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 MESSAGE("constructor de HOMARD_Gen_i");
100 _id = _poa->activate_object(_thisObj);
102 myHomard = new ::HOMARD_Gen;
103 _NS = SINGLETON_<SALOME_NamingService>::Instance();
104 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
115 //=================================
117 * standard destructor
119 //================================
120 HOMARD_Gen_i::~HOMARD_Gen_i()
123 //=============================================================================
124 //=============================================================================
125 // Utilitaires pour l'étude
126 //=============================================================================
127 //=============================================================================
128 void HOMARD_Gen_i::UpdateStudy()
130 ASSERT(!CORBA::is_nil(myStudy));
131 SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
133 // Create SComponent labelled 'homard' if it doesn't already exit
134 SALOMEDS::SComponent_var homardFather = myStudy->FindComponent(ComponentDataType());
135 if (CORBA::is_nil(homardFather))
137 myBuilder->NewCommand();
138 MESSAGE("Add Component HOMARD");
140 bool aLocked = myStudy->GetProperties()->IsLocked();
141 if (aLocked) myStudy->GetProperties()->SetLocked(false);
143 homardFather = myBuilder->NewComponent(ComponentDataType());
144 SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
145 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
146 CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
147 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
148 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
149 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
150 if (!Comp->_is_nil())
152 aName->SetValue(ComponentDataType());
155 anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributePixMap");
156 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
157 aPixmap->SetPixMap("HOMARD_2.png");
158 myBuilder->DefineComponentInstance(homardFather, HOMARD_Gen::_this());
160 if (aLocked) myStudy->GetProperties()->SetLocked(true);
161 myBuilder->CommitCommand();
165 //=============================================================================
166 //=============================================================================
167 // Utilitaires pour l'iteration
168 //=============================================================================
169 //=============================================================================
170 void HOMARD_Gen_i::SetEtatIter(const char* nomIter, const CORBA::Long Etat)
171 //=====================================================================================
173 MESSAGE( "SetEtatIter : affectation de l'etat " << Etat << " a l'iteration " << nomIter );
174 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
175 if (CORBA::is_nil(myIteration))
177 SALOME::ExceptionStruct es;
178 es.type = SALOME::BAD_PARAM;
179 es.text = "Invalid iteration";
180 throw SALOME::SALOME_Exception(es);
184 myIteration->SetState(Etat);
186 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
187 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
191 icone = "iter0.png" ;
192 else if ( Etat == 2 )
193 icone = "iter_calculee.png" ;
195 icone = "iter_non_calculee.png" ;
196 PublishInStudyAttr(aStudyBuilder, aIterSO, NULL , NULL, icone.c_str(), NULL) ;
198 aStudyBuilder->CommitCommand();
201 //=============================================================================
202 //=============================================================================
204 //=============================================================================
205 //=============================================================================
206 // Destruction des structures identifiees par leurs noms
207 //=============================================================================
208 //=============================================================================
209 CORBA::Long HOMARD_Gen_i::DeleteBoundary(const char* BoundaryName)
211 MESSAGE ( "DeleteBoundary : BoundaryName = " << BoundaryName );
212 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
213 if (CORBA::is_nil(myBoundary))
215 SALOME::ExceptionStruct es;
216 es.type = SALOME::BAD_PARAM;
217 es.text = "Invalid boundary";
218 throw SALOME::SALOME_Exception(es);
222 // On verifie que la frontiere n'est plus utilisee
223 HOMARD::listeCases* maListe = GetAllCasesName();
224 int numberOfCases = maListe->length();
225 MESSAGE ( ".. Nombre de cas = " << numberOfCases );
226 std::string CaseName ;
227 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType ;
229 HOMARD::HOMARD_Cas_var myCase ;
230 for (int NumeCas = 0; NumeCas< numberOfCases; NumeCas++)
232 CaseName = std::string((*maListe)[NumeCas]);
233 MESSAGE ( "... Examen du cas = " << CaseName.c_str() );
234 myCase = myStudyContext._mesCas[CaseName];
235 ASSERT(!CORBA::is_nil(myCase));
236 ListBoundaryGroupType = myCase->GetBoundaryGroup();
237 numberOfitems = ListBoundaryGroupType->length();
238 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
239 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
241 if ( std::string((*ListBoundaryGroupType)[NumBoundary]) == BoundaryName )
243 SALOME::ExceptionStruct es;
244 es.type = SALOME::BAD_PARAM;
245 es.text = "This boundary is used in a case and cannot be deleted.";
246 throw SALOME::SALOME_Exception(es);
252 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
253 myStudyContext._mesBoundarys.erase(BoundaryName);
254 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(BoundaryName, ComponentDataType());
255 SALOMEDS::SObject_var aSO =listSO[0];
256 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
257 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
261 //=============================================================================
262 CORBA::Long HOMARD_Gen_i::DeleteCase(const char* nomCas, CORBA::Long Option)
264 // Pour detruire un cas
265 MESSAGE ( "DeleteCase : nomCas = " << nomCas << ", avec option = " << Option );
266 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
267 if (CORBA::is_nil(myCase))
269 SALOME::ExceptionStruct es;
270 es.type = SALOME::BAD_PARAM;
271 es.text = "Invalid case context";
272 throw SALOME::SALOME_Exception(es);
275 // On commence par detruire toutes les iterations en partant de l'initiale et y compris elle
276 CORBA::String_var nomIter = myCase->GetIter0Name();
277 CORBA::Long Option1 = 0 ;
278 if ( DeleteIterationOption(nomIter, Option1, Option) != 0 )
283 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
284 myStudyContext._mesCas.erase(nomCas);
285 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomCas, ComponentDataType());
286 SALOMEDS::SObject_var aSO =listSO[0];
287 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
288 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
292 //=============================================================================
293 CORBA::Long HOMARD_Gen_i::DeleteHypo(const char* nomHypo)
295 MESSAGE ( "DeleteHypo : nomHypo = " << nomHypo );
296 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
297 if (CORBA::is_nil(myHypo))
299 SALOME::ExceptionStruct es;
300 es.type = SALOME::BAD_PARAM;
301 es.text = "Invalid hypothesis";
302 throw SALOME::SALOME_Exception(es);
306 // On verifie que l'hypothese n'est plus utilisee
307 HOMARD::listeIters* maListeIter = myHypo->GetIterations();
308 int numberOfIter = maListeIter->length();
309 if ( numberOfIter > 0 )
311 SALOME::ExceptionStruct es;
312 es.type = SALOME::BAD_PARAM;
313 es.text = "This hypothesis is used in an iteration and cannot be deleted.";
314 throw SALOME::SALOME_Exception(es);
318 // suppression du lien avec les zones eventuelles
319 HOMARD::listeZonesHypo* maListe = myHypo->GetZones();
320 int numberOfZones = maListe->length();
321 MESSAGE ( ".. Nombre de zones = " << numberOfZones );
322 for (int NumeZone = 0; NumeZone< numberOfZones; NumeZone++)
324 std::string ZoneName = std::string((*maListe)[NumeZone]);
325 MESSAGE ( ".. suppression du lien avec la zone = " << ZoneName.c_str() );
326 DissociateHypoZone(nomHypo, ZoneName.c_str()) ;
330 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
331 myStudyContext._mesHypotheses.erase(nomHypo);
332 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomHypo, ComponentDataType());
333 SALOMEDS::SObject_var aSO =listSO[0];
334 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
335 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
339 //=============================================================================
340 CORBA::Long HOMARD_Gen_i::DeleteIteration(const char* nomIter, CORBA::Long Option)
342 // Option = 0 : On ne supprime pas le fichier du maillage associe
343 // Option = 1 : On supprime le fichier du maillage associe
344 // Pour detruire une iteration courante
345 MESSAGE ( "DeleteIteration : nomIter = " << nomIter << ", avec option = " << Option );
346 CORBA::Long Option1 = 1 ;
347 return DeleteIterationOption(nomIter, Option1, Option);
349 //=============================================================================
350 CORBA::Long HOMARD_Gen_i::DeleteIterationOption(const char* nomIter, CORBA::Long Option1, CORBA::Long Option2)
352 // Option1 = 0 : On autorise la destruction de l'iteration 0
353 // Option1 = 1 : On interdit la destruction de l'iteration 0
355 // Option2 = 0 : On ne supprime pas le fichier du maillage associe
356 // Option2 = 1 : On supprime le fichier du maillage associe
357 MESSAGE ( "DeleteIterationOption : nomIter = " << nomIter << ", avec options = " << Option1<< ", " << Option2 );
358 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
359 if (CORBA::is_nil(myIteration))
361 SALOME::ExceptionStruct es;
362 es.type = SALOME::BAD_PARAM;
363 es.text = "Invalid iteration";
364 throw SALOME::SALOME_Exception(es);
368 int numero = myIteration->GetNumber();
369 MESSAGE ( "DeleteIterationOption : numero = " << numero );
370 if ( numero == 0 && Option1 == 1 )
372 SALOME::ExceptionStruct es;
373 es.type = SALOME::BAD_PARAM;
374 es.text = "This iteration cannot be deleted.";
375 throw SALOME::SALOME_Exception(es);
379 // On detruit recursivement toutes les filles
380 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
381 int numberOfIter = maListe->length();
382 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
384 std::string nomIterFille = std::string((*maListe)[NumeIter]);
385 MESSAGE ( ".. appel recursif de DeleteIterationOption pour nomIter = " << nomIterFille.c_str() );
386 DeleteIterationOption(nomIterFille.c_str(), Option1, Option2);
389 // On arrive ici pour une iteration sans fille
390 MESSAGE ( "Destruction effective de " << nomIter );
391 // On commence par invalider l'iteration pour faire le menage des dependances
392 // et eventuellement du maillage associe
394 if ( numero == 0 ) { option = 0 ; }
395 else { option = Option2 ; }
396 InvalideIterOption(nomIter, option) ;
398 // Retrait dans la descendance de l'iteration parent
401 std::string nomIterationParent = myIteration->GetIterParentName();
402 MESSAGE ( "Retrait dans la descendance de nomIterationParent " << nomIterationParent );
403 HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterationParent];
404 if (CORBA::is_nil(myIterationParent))
406 SALOME::ExceptionStruct es;
407 es.type = SALOME::BAD_PARAM;
408 es.text = "Invalid iteration";
409 throw SALOME::SALOME_Exception(es);
412 myIterationParent->UnLinkNextIteration(nomIter);
415 // suppression du lien avec l'hypothese
418 std::string nomHypo = myIteration->GetHypoName();
419 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
420 ASSERT(!CORBA::is_nil(myHypo));
421 myHypo->UnLinkIteration(nomIter);
424 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
425 myStudyContext._mesIterations.erase(nomIter);
426 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomIter, ComponentDataType());
427 SALOMEDS::SObject_var aSO =listSO[0];
428 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
429 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
430 // on peut aussi faire RemoveObject
431 // MESSAGE ( "Au final" );
432 // HOMARD::listeIterations* Liste = GetAllIterationsName() ;
433 // numberOfIter = Liste->length();
434 // for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
436 // std::string nomIterFille = std::string((*Liste)[NumeIter]);
437 // MESSAGE ( ".. nomIter = " << nomIterFille.c_str() );
442 //=============================================================================
443 CORBA::Long HOMARD_Gen_i::DeleteYACS(const char* nomYACS, CORBA::Long Option)
445 // Option = 0 : On ne supprime pas le fichier du schema associe
446 // Option = 1 : On supprime le fichier du schema associe
447 MESSAGE ( "DeleteYACS : nomYACS = " << nomYACS << ", avec option = " << Option );
448 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
449 if (CORBA::is_nil(myYACS))
451 SALOME::ExceptionStruct es;
452 es.type = SALOME::BAD_PARAM;
453 es.text = "Invalid schema YACS";
454 throw SALOME::SALOME_Exception(es);
457 // Suppression eventuelle du fichier XML
460 std::string nomFichier = myYACS->GetXMLFile();
461 std::string commande = "rm -rf " + nomFichier ;
462 MESSAGE ( "commande = " << commande );
463 if ((system(commande.c_str())) != 0)
465 SALOME::ExceptionStruct es;
466 es.type = SALOME::BAD_PARAM;
467 es.text = "The xml file for the schema YACS cannot be removed." ;
468 throw SALOME::SALOME_Exception(es);
472 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
473 myStudyContext._mesYACSs.erase(nomYACS);
474 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomYACS, ComponentDataType());
475 SALOMEDS::SObject_var aSO =listSO[0];
476 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
477 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
481 //=============================================================================
482 CORBA::Long HOMARD_Gen_i::DeleteZone(const char* nomZone)
484 MESSAGE ( "DeleteZone : nomZone = " << nomZone );
485 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[nomZone];
486 if (CORBA::is_nil(myZone))
488 SALOME::ExceptionStruct es;
489 es.type = SALOME::BAD_PARAM;
490 es.text = "Invalid zone";
491 throw SALOME::SALOME_Exception(es);
495 // On verifie que la zone n'est plus utilisee
496 HOMARD::listeHypo* maListe = myZone->GetHypo();
497 int numberOfHypo = maListe->length();
498 MESSAGE ( ".. Nombre d'hypotheses = " << numberOfHypo );
499 if ( numberOfHypo > 0 )
501 SALOME::ExceptionStruct es;
502 es.type = SALOME::BAD_PARAM;
503 es.text = "This zone is used in a hypothesis and cannot be deleted.";
504 throw SALOME::SALOME_Exception(es);
508 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
509 myStudyContext._mesZones.erase(nomZone);
510 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomZone, ComponentDataType());
511 SALOMEDS::SObject_var aSO =listSO[0];
512 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
513 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
517 //=============================================================================
518 //=============================================================================
520 //=============================================================================
521 //=============================================================================
522 // Invalidation des structures identifiees par leurs noms
523 //=============================================================================
524 //=============================================================================
525 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
527 MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName );
528 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
529 if (CORBA::is_nil(myBoundary))
531 SALOME::ExceptionStruct es;
532 es.type = SALOME::BAD_PARAM;
533 es.text = "Invalid boundary";
534 throw SALOME::SALOME_Exception(es);
539 SALOME::ExceptionStruct es;
540 es.type = SALOME::BAD_PARAM;
541 es.text = "No change is allowed in a boundary. Ask for evolution.";
542 throw SALOME::SALOME_Exception(es);
546 //=============================================================================
547 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
549 MESSAGE( "InvalideHypo : nomHypo = " << nomHypo );
550 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
551 if (CORBA::is_nil(myHypo))
553 SALOME::ExceptionStruct es;
554 es.type = SALOME::BAD_PARAM;
555 es.text = "Invalid hypothesis";
556 throw SALOME::SALOME_Exception(es);
560 HOMARD::listeIters* maListe = myHypo->GetIterations();
561 int numberOfIter = maListe->length();
562 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
564 std::string nomIter = std::string((*maListe)[NumeIter]);
565 MESSAGE( ".. nomIter = " << nomIter );
566 InvalideIter(nomIter.c_str());
569 //=============================================================================
570 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
572 MESSAGE("InvalideIter : nomIter = " << nomIter);
573 // Pour invalider totalement une iteration courante
574 CORBA::Long Option = 1 ;
575 return InvalideIterOption(nomIter, Option);
577 //=============================================================================
578 void HOMARD_Gen_i::InvalideIterOption(const char* nomIter, CORBA::Long Option)
580 // Option = 0 : On ne supprime pas le fichier du maillage associe
581 // Option = 1 : On supprime le fichier du maillage associe
582 MESSAGE ( "InvalideIterOption : nomIter = " << nomIter << ", avec option = " << Option );
583 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
584 if (CORBA::is_nil(myIteration))
586 SALOME::ExceptionStruct es;
587 es.type = SALOME::BAD_PARAM;
588 es.text = "Invalid iteration";
589 throw SALOME::SALOME_Exception(es);
593 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
594 int numberOfIter = maListe->length();
595 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
597 std::string nomIterFille = std::string((*maListe)[NumeIter]);
598 MESSAGE ( ".. appel recursif de InvalideIter pour nomIter = " << nomIterFille.c_str() );
599 InvalideIter(nomIterFille.c_str());
602 // On arrive ici pour une iteration sans fille
603 MESSAGE ( "Invalidation effective de " << nomIter );
604 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
605 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aIterSO);
606 for (; aIter->More(); aIter->Next())
608 SALOMEDS::SObject_var so = aIter->Value();
609 SALOMEDS::GenericAttribute_var anAttr;
610 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
611 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
612 std::string value (aCommentAttr->Value());
613 if(value == std::string("IterationHomard")) continue;
614 if(value == std::string("HypoHomard")) continue;
615 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
616 aStudyBuilder->RemoveObject(so);
619 int etat = myIteration->GetState();
622 SetEtatIter(nomIter,1);
623 const char * nomCas = myIteration->GetCaseName();
624 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
625 if (CORBA::is_nil(myCase))
627 SALOME::ExceptionStruct es;
628 es.type = SALOME::BAD_PARAM;
629 es.text = "Invalid case context";
630 throw SALOME::SALOME_Exception(es);
633 std::string nomDir = myIteration->GetDirName();
634 std::string nomFichier = myIteration->GetMeshFile();
635 std::string commande = "rm -rf " + std::string(nomDir);
636 if ( Option == 1 ) { commande = commande + ";rm -rf " + std::string(nomFichier) ; }
637 MESSAGE ( "commande = " << commande );
638 if ((system(commande.c_str())) != 0)
640 SALOME::ExceptionStruct es;
641 es.type = SALOME::BAD_PARAM;
642 es.text = "The directory for the calculation cannot be cleared." ;
643 throw SALOME::SALOME_Exception(es);
646 // Suppression du maillage publie dans SMESH
647 std::string MeshName = myIteration->GetMeshName() ;
648 DeleteResultInSmesh(nomFichier, MeshName) ;
652 //=============================================================================
653 void HOMARD_Gen_i::InvalideIterInfo(const char* nomIter)
655 MESSAGE("InvalideIterInfo : nomIter = " << nomIter);
656 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
657 if (CORBA::is_nil(myIteration))
659 SALOME::ExceptionStruct es;
660 es.type = SALOME::BAD_PARAM;
661 es.text = "Invalid iteration";
662 throw SALOME::SALOME_Exception(es);
666 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
667 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aIterSO);
668 for (; aIter->More(); aIter->Next())
670 SALOMEDS::SObject_var so = aIter->Value();
671 SALOMEDS::GenericAttribute_var anAttr;
672 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
673 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
674 std::string value (aCommentAttr->Value());
675 /* MESSAGE("... value = " << value);*/
676 if( (value == std::string("logInfo")) || ( value == std::string("SummaryInfo")) )
678 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
679 aStudyBuilder->RemoveObject(so);
683 const char * nomCas = myIteration->GetCaseName();
684 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
685 if (CORBA::is_nil(myCase))
687 SALOME::ExceptionStruct es;
688 es.type = SALOME::BAD_PARAM;
689 es.text = "Invalid case context";
690 throw SALOME::SALOME_Exception(es);
693 const char* nomDir = myIteration->GetDirName();
694 std::string commande = "rm -f " + std::string(nomDir) + "/info* " ;
695 commande += std::string(nomDir) + "/Liste.*info" ;
696 /* MESSAGE ( "commande = " << commande );*/
697 if ((system(commande.c_str())) != 0)
699 SALOME::ExceptionStruct es;
700 es.type = SALOME::BAD_PARAM;
701 es.text = "The directory for the calculation cannot be cleared." ;
702 throw SALOME::SALOME_Exception(es);
706 //=============================================================================
707 void HOMARD_Gen_i::InvalideYACS(const char* YACSName)
709 MESSAGE( "InvalideYACS : YACSName = " << YACSName );
710 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[YACSName];
711 if (CORBA::is_nil(myYACS))
713 SALOME::ExceptionStruct es;
714 es.type = SALOME::BAD_PARAM;
715 es.text = "Invalid schema YACS";
716 throw SALOME::SALOME_Exception(es);
720 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
721 SALOMEDS::ChildIterator_var aYACS = myStudy->NewChildIterator(aYACSSO);
722 for (; aYACS->More(); aYACS->Next())
724 SALOMEDS::SObject_var so = aYACS->Value();
725 SALOMEDS::GenericAttribute_var anAttr;
726 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
727 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
728 std::string value (aCommentAttr->Value());
729 if( value == std::string("xml") )
731 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
732 aStudyBuilder->RemoveObject(so);
735 std::string nomFichier = myYACS->GetXMLFile();
736 std::string commande = "rm -rf " + std::string(nomFichier) ;
737 MESSAGE ( "commande = " << commande );
738 if ((system(commande.c_str())) != 0)
740 SALOME::ExceptionStruct es;
741 es.type = SALOME::BAD_PARAM;
742 es.text = "The XML file for the schema YACS cannot be removed." ;
743 throw SALOME::SALOME_Exception(es);
747 //=============================================================================
748 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
750 MESSAGE( "InvalideZone : ZoneName = " << ZoneName );
751 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
752 if (CORBA::is_nil(myZone))
754 SALOME::ExceptionStruct es;
755 es.type = SALOME::BAD_PARAM;
756 es.text = "Invalid zone";
757 throw SALOME::SALOME_Exception(es);
760 HOMARD::listeHypo* maListe = myZone->GetHypo();
761 int numberOfHypo = maListe->length();
762 MESSAGE( ".. numberOfHypo = " << numberOfHypo );
763 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
765 std::string nomHypo = std::string((*maListe)[NumeHypo]);
766 MESSAGE( ".. nomHypo = " << nomHypo );
767 InvalideHypo(nomHypo.c_str());
770 //=============================================================================
771 //=============================================================================
773 //=============================================================================
774 //=============================================================================
775 // Association de lien entre des structures identifiees par leurs noms
776 //=============================================================================
777 //=============================================================================
778 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
780 MESSAGE( "AssociateCaseIter : " << nomCas << ", " << nomIter << ", " << labelIter );
782 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
783 if (CORBA::is_nil(myCase))
785 SALOME::ExceptionStruct es;
786 es.type = SALOME::BAD_PARAM;
787 es.text = "Invalid case";
788 throw SALOME::SALOME_Exception(es);
792 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
793 if (CORBA::is_nil(myIteration))
795 SALOME::ExceptionStruct es;
796 es.type = SALOME::BAD_PARAM;
797 es.text = "Invalid iteration";
798 throw SALOME::SALOME_Exception(es);
802 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
803 SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myCase)));
804 if (CORBA::is_nil(aCasSO))
806 SALOME::ExceptionStruct es;
807 es.type = SALOME::BAD_PARAM;
808 es.text = "Invalid case";
809 throw SALOME::SALOME_Exception(es);
813 aStudyBuilder->NewCommand();
814 SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
815 PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
816 "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
817 aStudyBuilder->CommitCommand();
819 myCase->AddIteration(nomIter);
820 myIteration->SetCaseName(nomCas);
822 //=====================================================================================
823 void HOMARD_Gen_i::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
825 MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
827 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypothesis];
828 ASSERT(!CORBA::is_nil(myHypo));
829 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
830 ASSERT(!CORBA::is_nil(aHypoSO));
832 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
833 ASSERT(!CORBA::is_nil(myZone));
834 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myZone)));
835 ASSERT(!CORBA::is_nil(aZoneSO));
837 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
839 aStudyBuilder->NewCommand();
841 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
842 aStudyBuilder->Addreference(aSubSO, aZoneSO);
844 aStudyBuilder->CommitCommand();
846 myZone->AddHypo(nomHypothesis);
847 myHypo->AddZone0(ZoneName, TypeUse);
849 //=============================================================================
850 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
852 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
854 // Verification de l'existence de l'hypothese
855 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
856 ASSERT(!CORBA::is_nil(myHypo));
857 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
858 ASSERT(!CORBA::is_nil(aHypoSO));
860 // Verification de l'existence de l'iteration
861 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
862 ASSERT(!CORBA::is_nil(myIteration));
863 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
864 ASSERT(!CORBA::is_nil(aIterSO));
866 // Gestion de l'arbre d'etudes
867 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
868 aStudyBuilder->NewCommand();
869 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
870 aStudyBuilder->Addreference(aSubSO, aHypoSO);
871 aStudyBuilder->CommitCommand();
874 myIteration->SetHypoName(nomHypo);
875 myHypo->LinkIteration(nomIter);
877 // On stocke les noms des champ a interpoler pour le futur controle de la donnée des pas de temps
878 myIteration->SupprFieldInterps() ;
879 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
880 int numberOfFieldsx2 = ListField->length();
881 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
883 std::string FieldName = std::string((*ListField)[iaux]) ;
884 myIteration->SetFieldInterp(FieldName.c_str()) ;
888 //=============================================================================
889 //=============================================================================
891 //=============================================================================
892 //=============================================================================
893 // Dissociation de lien entre des structures identifiees par leurs noms
894 //=============================================================================
895 //=============================================================================
896 void HOMARD_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
898 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
900 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypothesis];
901 ASSERT(!CORBA::is_nil(myHypo));
902 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
903 ASSERT(!CORBA::is_nil(aHypoSO));
905 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
906 ASSERT(!CORBA::is_nil(myZone));
907 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myZone)));
908 ASSERT(!CORBA::is_nil(aZoneSO));
910 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
912 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(aHypoSO);
913 for (; it->More(); it->Next())
915 SALOMEDS::SObject_var aHypObj = it->Value();
916 SALOMEDS::SObject_var ptrObj;
917 if (aHypObj->ReferencedObject(ptrObj))
919 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
921 aStudyBuilder->NewCommand();
922 aStudyBuilder->RemoveObject(aHypObj);
923 aStudyBuilder->CommitCommand();
929 myZone->SupprHypo(nomHypothesis);
930 myHypo->SupprZone(ZoneName);
932 //=============================================================================
933 //=============================================================================
936 //=============================================================================
937 //=============================================================================
938 // Recuperation des listes
939 //=============================================================================
940 //=============================================================================
941 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
943 MESSAGE("GetAllBoundarysName");
946 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
947 ret->length(myStudyContext._mesBoundarys.size());
948 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
950 for (it = myStudyContext._mesBoundarys.begin();
951 it != myStudyContext._mesBoundarys.end(); it++)
953 ret[i++] = CORBA::string_dup((*it).first.c_str());
958 //=============================================================================
959 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
961 MESSAGE("GetAllCasesName");
964 HOMARD::listeCases_var ret = new HOMARD::listeCases;
965 ret->length(myStudyContext._mesCas.size());
966 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
968 for (it = myStudyContext._mesCas.begin();
969 it != myStudyContext._mesCas.end(); it++)
971 ret[i++] = CORBA::string_dup((*it).first.c_str());
976 //=============================================================================
977 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
979 MESSAGE("GetAllHypothesesName");
982 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
983 ret->length(myStudyContext._mesHypotheses.size());
984 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
986 for (it = myStudyContext._mesHypotheses.begin();
987 it != myStudyContext._mesHypotheses.end(); it++)
989 ret[i++] = CORBA::string_dup((*it).first.c_str());
994 //=============================================================================
995 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
997 MESSAGE("GetAllIterationsName");
1000 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
1001 ret->length(myStudyContext._mesIterations.size());
1002 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
1004 for (it = myStudyContext._mesIterations.begin();
1005 it != myStudyContext._mesIterations.end(); it++)
1007 ret[i++] = CORBA::string_dup((*it).first.c_str());
1012 //=============================================================================
1013 HOMARD::listeYACSs* HOMARD_Gen_i::GetAllYACSsName()
1015 MESSAGE("GetAllYACSsName");
1018 HOMARD::listeYACSs_var ret = new HOMARD::listeYACSs;
1019 ret->length(myStudyContext._mesYACSs.size());
1020 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it;
1022 for (it = myStudyContext._mesYACSs.begin();
1023 it != myStudyContext._mesYACSs.end(); it++)
1025 ret[i++] = CORBA::string_dup((*it).first.c_str());
1030 //=============================================================================
1031 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
1033 MESSAGE("GetAllZonesName");
1036 HOMARD::listeZones_var ret = new HOMARD::listeZones;
1037 ret->length(myStudyContext._mesZones.size());
1038 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
1040 for (it = myStudyContext._mesZones.begin();
1041 it != myStudyContext._mesZones.end(); it++)
1043 ret[i++] = CORBA::string_dup((*it).first.c_str());
1048 //=============================================================================
1049 //=============================================================================
1051 //=============================================================================
1052 //=============================================================================
1053 // Recuperation des structures identifiees par leurs noms
1054 //=============================================================================
1055 //=============================================================================
1056 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
1058 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[nomBoundary];
1059 ASSERT(!CORBA::is_nil(myBoundary));
1060 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1062 //=============================================================================
1063 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
1065 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
1066 ASSERT(!CORBA::is_nil(myCase));
1067 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1069 //=============================================================================
1070 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
1072 HOMARD::HOMARD_Hypothesis_var myHypothesis = myStudyContext._mesHypotheses[nomHypothesis];
1073 ASSERT(!CORBA::is_nil(myHypothesis));
1074 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1076 //=============================================================================
1077 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* NomIterationation)
1079 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIterationation];
1080 ASSERT(!CORBA::is_nil(myIteration));
1081 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1083 //=============================================================================
1084 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::GetYACS(const char* nomYACS)
1086 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
1087 ASSERT(!CORBA::is_nil(myYACS));
1088 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
1090 //=============================================================================
1091 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
1093 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
1094 ASSERT(!CORBA::is_nil(myZone));
1095 return HOMARD::HOMARD_Zone::_duplicate(myZone);
1097 //=============================================================================
1098 //=============================================================================
1100 //=============================================================================
1101 //=============================================================================
1103 //=============================================================================
1104 //=============================================================================
1105 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)
1107 MESSAGE ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1108 MESSAGE ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte );
1113 if ( _PublisMeshIN != 0 ) option = 2 ;
1114 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, 0, option) ;
1115 myCase->SetDirName(DirName) ;
1117 myCase->MeshInfo(Qual, Diam, Conn, Tail, Inte) ;
1121 //=============================================================================
1122 //=============================================================================
1124 //=============================================================================
1125 //=============================================================================
1126 // Recuperation des structures par le contexte
1127 //=============================================================================
1128 //=============================================================================
1129 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::LastIteration(const char* nomCas)
1131 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
1132 ASSERT(!CORBA::is_nil(myCase));
1134 HOMARD::HOMARD_Iteration_var myIteration = myCase->LastIteration();
1135 ASSERT(!CORBA::is_nil(myIteration));
1137 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1139 //=============================================================================
1140 //=============================================================================
1142 //=============================================================================
1143 //=============================================================================
1144 // Nouvelles structures
1145 //=============================================================================
1146 //=============================================================================
1147 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1149 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1150 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
1151 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
1152 return aCase._retn();
1154 //=============================================================================
1155 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
1157 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1158 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
1159 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
1160 return aHypo._retn();
1162 //=============================================================================
1163 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
1165 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1166 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
1167 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
1168 return aIter._retn();
1170 //=============================================================================
1171 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1173 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1174 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
1175 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1176 return aBoundary._retn();
1178 //=============================================================================
1179 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
1181 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1182 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
1183 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
1184 return aZone._retn();
1186 //=============================================================================
1187 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::newYACS()
1189 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1190 HOMARD_YACS_i* aServant = new HOMARD_YACS_i(_orb, engine);
1191 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(aServant->_this());
1192 return aYACS._retn();
1194 //=============================================================================
1195 //=============================================================================
1197 //=============================================================================
1198 //=============================================================================
1199 // Creation des structures identifiees par leurs noms
1200 //=============================================================================
1201 //=============================================================================
1202 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
1204 // Creation d'un cas initial
1205 // nomCas : nom du cas a creer
1206 // MeshName, MeshFile : nom et fichier du maillage correspondant
1209 INFOS ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1212 if ( _PublisMeshIN != 0 ) option = 2 ;
1213 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 0, 0, option) ;
1215 // Valeurs par defaut des filtrages
1216 myCase->SetPyram(0);
1218 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1220 //=============================================================================
1221 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromIteration(const char* nomCas, const char* DirNameStart)
1223 // nomCas : nom du cas a creer
1224 // DirNameStart : nom du répertoire contenant l'iteration de reprise
1227 MESSAGE ( "CreateCaseFromIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1228 std::string nomDirWork = getenv("PWD") ;
1231 // A. Decodage du point de reprise
1232 // A.1. Controle du répertoire de depart de l'iteration
1233 codret = CHDIR(DirNameStart) ;
1236 SALOME::ExceptionStruct es;
1237 es.type = SALOME::BAD_PARAM;
1238 es.text = "The directory of the iteration does not exist.";
1239 throw SALOME::SALOME_Exception(es);
1242 // A.2. Reperage des fichiers du répertoire de reprise
1243 std::string file_configuration = "" ;
1244 std::string file_maillage_homard = "" ;
1248 struct dirent *dirp;
1249 dp = opendir(DirNameStart);
1250 while ( (dirp = readdir(dp)) != NULL )
1252 std::string file_name(dirp->d_name);
1253 // MESSAGE ( file_name );
1254 bilan = file_name.find("HOMARD.Configuration.") ;
1255 if ( bilan != string::npos ) { file_configuration = file_name ; }
1256 bilan = file_name.find("maill.") ;
1257 if ( bilan != string::npos )
1259 bilan = file_name.find(".hom.med") ;
1260 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1265 HANDLE hFind = INVALID_HANDLE_VALUE;
1266 WIN32_FIND_DATA ffd;
1267 hFind = FindFirstFile(DirNameStart, &ffd);
1268 if (INVALID_HANDLE_VALUE != hFind) {
1269 while (FindNextFile(hFind, &ffd) != 0) {
1270 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1271 std::string file_name(ffd.cFileName);
1272 bilan = file_name.find("HOMARD.Configuration.") ;
1273 if ( bilan != string::npos ) { file_configuration = file_name ; }
1274 bilan = file_name.find("maill.") ;
1275 if ( bilan != string::npos )
1277 bilan = file_name.find(".hom.med") ;
1278 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1284 MESSAGE ( "==> file_configuration : " << file_configuration ) ;
1285 MESSAGE ( "==> file_maillage_homard : " << file_maillage_homard ) ;
1287 if ( ( file_configuration == "" ) || ( file_maillage_homard == "" ) )
1289 SALOME::ExceptionStruct es;
1290 es.type = SALOME::BAD_PARAM;
1292 if ( file_configuration == "" ) { text = "The configuration file cannot be found." ; }
1293 else { text = "The HOMARD mesh file cannot be found." ; }
1294 es.text = CORBA::string_dup(text.c_str());
1295 throw SALOME::SALOME_Exception(es);
1298 // B. Lecture du fichier de configuration
1299 // ATTENTION : on doit veiller a la coherence entre HomardDriver et CreateCaseFromIteration
1306 // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1307 std::ifstream fichier( file_configuration.c_str() );
1308 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1310 std::string ligne; // variable contenant chaque ligne lue
1311 std::string mot_cle;
1312 std::string argument;
1314 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1315 while ( std::getline( fichier, ligne ) )
1317 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1318 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1319 ligne_bis >> mot_cle ;
1320 // B.2. Des valeurs entieres : le second bloc de la ligne
1321 if ( mot_cle == "NumeIter" )
1323 ligne_bis >> NumeIter ;
1326 // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1327 else if ( ( mot_cle == "TypeConf" ) || ( mot_cle == "TypeElem" ) )
1329 ligne_bis >> argument ;
1331 if ( mot_cle == "TypeConf" )
1333 if ( argument == "conforme" ) { TypeConf = 1 ; }
1334 else if ( argument == "non_conforme_1_noeud" ) { TypeConf = 2 ; }
1335 else if ( argument == "non_conforme_1_arete" ) { TypeConf = 3 ; }
1336 else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1338 else if ( mot_cle == "TypeElem" )
1340 if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1341 else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1344 // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1345 // il faut les supprimer
1346 else if ( ( mot_cle == "CCNoMNP1" ) || ( mot_cle == "CCMaiNP1" ) )
1348 ligne_bis >> argument ;
1349 if ( argument[0] == '"' ) { decalage = 1 ; }
1350 else { decalage = 0 ; }
1351 size_t size = argument.size() + 1 - 2*decalage ;
1353 if ( mot_cle == "CCNoMNP1" )
1355 MeshName = new char[ size ];
1356 strncpy( MeshName, argument.c_str()+decalage, size );
1357 MeshName[size-1] = '\0' ;
1359 else if ( mot_cle == "CCMaiNP1" )
1361 MeshFile = new char[ size ];
1362 strncpy( MeshFile, argument.c_str()+decalage, size );
1363 MeshFile[size-1] = '\0' ;
1367 MESSAGE ( "==> TypeConf : " << TypeConf ) ;
1368 MESSAGE ( "==> MeshName : " << MeshName ) ;
1369 MESSAGE ( "==> MeshFile : " << MeshFile ) ;
1370 MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1371 MESSAGE ( "==> Pyram : " << Pyram ) ;
1375 SALOME::ExceptionStruct es;
1376 es.type = SALOME::BAD_PARAM;
1377 std::string text = "The configuration file cannot be read." ;
1378 es.text = CORBA::string_dup(text.c_str());
1379 throw SALOME::SALOME_Exception(es);
1382 // C. Creation effective du cas
1385 if ( _PublisMeshIN != 0 ) option = 2 ;
1386 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, option) ;
1388 // D. Parametrages lus dans le fichier de configuration
1390 myCase->SetConfType (TypeConf) ;
1391 myCase->SetExtType (TypeExt) ;
1392 myCase->SetPyram (Pyram) ;
1394 // E. Copie du fichier de maillage homard
1395 // E.1. Répertoire associe au cas
1396 char* nomDirCase = myCase->GetDirName() ;
1397 // E.2. Répertoire associe a l'iteration de ce cas
1399 IterName = myCase->GetIter0Name() ;
1400 HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1401 char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1402 Iter->SetDirNameLoc(nomDirIter);
1403 std::string nomDirIterTotal ;
1404 nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1406 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1408 if (_mkdir(nomDirIterTotal.c_str()) != 0)
1411 MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1412 SALOME::ExceptionStruct es;
1413 es.type = SALOME::BAD_PARAM;
1414 std::string text = "The directory for the computation cannot be created." ;
1415 es.text = CORBA::string_dup(text.c_str());
1416 throw SALOME::SALOME_Exception(es);
1418 // E.3. Copie du maillage HOMARD au format MED
1419 codret = CHDIR(DirNameStart) ;
1420 std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1421 MESSAGE ( "commande : " << commande ) ;
1422 codret = system(commande.c_str()) ;
1423 MESSAGE ( "codret : " << codret ) ;
1426 SALOME::ExceptionStruct es;
1427 es.type = SALOME::BAD_PARAM;
1428 es.text = "The starting point for the case cannot be copied into the working directory.";
1429 throw SALOME::SALOME_Exception(es);
1438 CHDIR(nomDirWork.c_str());
1439 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1441 //=============================================================================
1442 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1444 // nomCas : nom du cas a creer
1445 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1448 MESSAGE ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1450 std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1452 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1453 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1455 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1457 //=============================================================================
1458 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1460 // nomCas : nom du cas a creer
1461 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1462 // Number : numero de l'iteration de depart
1465 MESSAGE ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1468 SALOME::ExceptionStruct es;
1469 es.type = SALOME::BAD_PARAM;
1470 es.text = "The number of iteration must be positive.";
1471 throw SALOME::SALOME_Exception(es);
1475 std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1477 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1478 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1480 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1482 //=============================================================================
1483 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1485 // Retourne le nom du répertoire ou se trouve l'iteration voulue.
1486 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1487 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1490 MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1491 std::string nomDirWork = getenv("PWD") ;
1492 std::string DirNameStartIter ;
1494 int NumeIterMax = -1 ;
1496 // A.1. Controle du répertoire de depart du cas
1497 codret = CHDIR(DirNameStart) ;
1500 SALOME::ExceptionStruct es;
1501 es.type = SALOME::BAD_PARAM;
1502 es.text = "The directory of the case for the pursuit does not exist.";
1503 throw SALOME::SALOME_Exception(es);
1506 // A.2. Reperage des sous-répertoire du répertoire de reprise
1507 bool existe = false ;
1510 struct dirent *dirp;
1511 dp = opendir(DirNameStart);
1512 while ( (dirp = readdir(dp)) != NULL ) {
1513 std::string DirName_1(dirp->d_name);
1515 HANDLE hFind = INVALID_HANDLE_VALUE;
1516 WIN32_FIND_DATA ffd;
1517 hFind = FindFirstFile(DirNameStart, &ffd);
1518 if (INVALID_HANDLE_VALUE != hFind) {
1519 while (FindNextFile(hFind, &ffd) != 0) {
1520 std::string DirName_1 = "";
1521 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1522 DirName_1 = std::string(ffd.cFileName);
1525 if ( ( DirName_1 != "." ) && ( DirName_1 != ".." ) )
1527 if ( CHDIR(DirName_1.c_str()) == 0 )
1529 // On cherche le fichier de configuration dans ce sous-répertoire
1530 codret = CHDIR(DirNameStart);
1533 struct dirent *dirp_1;
1534 dp_1 = opendir(DirName_1.c_str()) ;
1535 while ( (dirp_1 = readdir(dp_1)) != NULL )
1537 std::string file_name_1(dirp_1->d_name);
1539 HANDLE hFind1 = INVALID_HANDLE_VALUE;
1540 WIN32_FIND_DATA ffd1;
1541 hFind1 = FindFirstFile(DirName_1.c_str(), &ffd1);
1542 while (FindNextFile(hFind1, &ffd1) != 0)
1544 if (ffd1.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1545 std::string file_name_1(ffd1.cFileName);
1547 int bilan = file_name_1.find("HOMARD.Configuration.") ;
1548 if ( bilan != string::npos )
1550 // Decodage du fichier pour trouver le numero d'iteration
1551 CHDIR(DirName_1.c_str()) ;
1553 std::ifstream fichier( file_name_1.c_str() );
1554 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1557 std::string ligne; // variable contenant chaque ligne lue
1558 std::string mot_cle;
1559 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1560 while ( std::getline( fichier, ligne ) )
1562 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1563 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1564 ligne_bis >> mot_cle ;
1565 if ( mot_cle == "NumeIter" )
1567 ligne_bis >> NumeIter ;
1569 // MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1570 if ( Number == - 1 )
1572 if ( NumeIter >= NumeIterMax )
1574 NumeIterMax = NumeIter ;
1575 DirNameStartIter = DirName_1 ;
1580 if ( NumeIter == Number )
1582 DirNameStartIter = DirName_1 ;
1592 SALOME::ExceptionStruct es;
1593 es.type = SALOME::BAD_PARAM;
1594 std::string text = "The configuration file cannot be read." ;
1595 es.text = CORBA::string_dup(text.c_str());
1596 throw SALOME::SALOME_Exception(es);
1598 CHDIR(DirNameStart) ;
1600 if ( existe ) { break ; }
1607 if ( existe ) { break ; }
1616 CHDIR(nomDirWork.c_str());
1618 if ( ( Number >= 0 && ( !existe ) ) || ( Number < 0 && ( NumeIterMax == -1 ) ) )
1620 SALOME::ExceptionStruct es;
1621 es.type = SALOME::BAD_PARAM;
1622 es.text = "The directory of the iteration does not exist.";
1623 throw SALOME::SALOME_Exception(es);
1627 return DirNameStartIter ;
1629 //=============================================================================
1630 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)
1632 // nomCas : nom du cas a creer
1633 // MeshName, MeshFile : nom et fichier du maillage correspondant
1634 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1635 // 1 : le maillage fourni peut ne pas exister ==> on continue si absent
1636 // -1 : le maillage n'est pas fourni
1637 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1638 // Option : multiple de nombres premiers
1639 // 1 : aucune option
1640 // x2 : publication du maillage dans SMESH
1642 MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1643 MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1644 MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1650 // A.2. Controle du nom :
1651 if ((myStudyContext._mesCas).find(nomCas)!=(myStudyContext._mesCas).end())
1653 SALOME::ExceptionStruct es;
1654 es.type = SALOME::BAD_PARAM;
1655 es.text = "This case has already been defined.";
1656 throw SALOME::SALOME_Exception(es);
1660 // A.3. Controle du fichier du maillage
1661 int existeMeshFile ;
1662 if ( MeshOption >= 0 )
1664 existeMeshFile = MEDFileExist ( MeshFile ) ;
1665 MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1666 if ( ( existeMeshFile == 0 ) && ( MeshOption == 0 ) )
1668 SALOME::ExceptionStruct es;
1669 es.type = SALOME::BAD_PARAM;
1670 es.text = "The mesh file does not exist.";
1671 throw SALOME::SALOME_Exception(es);
1675 else { existeMeshFile = 0 ; }
1677 // B. Creation de l'objet cas et publication
1678 // MESSAGE ( "CreateCase0 : Creation de l'objet" );
1679 HOMARD::HOMARD_Cas_var myCase = newCase();
1680 myCase->SetName(nomCas);
1681 SALOMEDS::SObject_var aSO;
1682 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myCase, nomCas);
1683 myStudyContext._mesCas[nomCas] = myCase;
1685 // C. Caracteristiques du maillage
1686 if ( existeMeshFile != 0 )
1688 // Les valeurs extremes des coordonnées
1689 // MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnées" );
1690 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1691 HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1692 if (LesExtremes.size()!=10) { return 0; }
1694 for (int i =0 ; i< LesExtremes.size() ; i++)
1695 aSeq[i]=LesExtremes[i] ;
1696 myCase->SetBoundingBox(aSeq) ;
1698 // MESSAGE ( "CreateCase0 : Les groupes" );
1699 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile) ;
1700 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1701 aSeqGroupe->length(LesGroupes.size());
1702 std::set<std::string>::const_iterator it ;
1704 for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1705 aSeqGroupe[i++]=(*it).c_str() ;
1706 myCase->SetGroups(aSeqGroupe) ;
1709 // D. L'iteration initiale du cas
1710 MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1711 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1712 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1714 std::string NomIteration = std::string(MeshName) ;
1715 while ( (myStudyContext._mesIterations).find(NomIteration) != (myStudyContext._mesIterations.end()) )
1717 std::ostringstream nom;
1718 nom << MeshName << monNum;
1719 NomIteration = nom.str();
1722 MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1724 // D.2. Creation de l'iteration
1725 HOMARD::HOMARD_Iteration_var anIter = newIteration();
1726 myStudyContext._mesIterations[NomIteration] = anIter;
1727 anIter->SetName(NomIteration.c_str());
1728 AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1730 // D.4. Maillage correspondant
1731 if ( existeMeshFile != 0 )
1733 anIter->SetMeshFile(MeshFile);
1734 if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1736 anIter->SetMeshName(MeshName);
1738 // D.5. Numero d'iteration
1739 anIter->SetNumber(NumeIter);
1742 SetEtatIter(NomIteration.c_str(), -NumeIter);
1745 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1747 //=============================================================================
1748 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1750 MESSAGE ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1753 // A. Controle du nom :
1754 if ((myStudyContext._mesHypotheses).find(nomHypothesis) != (myStudyContext._mesHypotheses).end())
1756 SALOME::ExceptionStruct es;
1757 es.type = SALOME::BAD_PARAM;
1758 es.text = "This hypothesis has already been defined.";
1759 throw SALOME::SALOME_Exception(es);
1763 // B. Creation de l'objet
1764 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1765 if (CORBA::is_nil(myHypothesis))
1767 SALOME::ExceptionStruct es;
1768 es.type = SALOME::BAD_PARAM;
1769 es.text = "Unable to create the hypothesis";
1770 throw SALOME::SALOME_Exception(es);
1773 myHypothesis->SetName(nomHypothesis);
1775 // C. Enregistrement
1776 myStudyContext._mesHypotheses[nomHypothesis] = myHypothesis;
1778 SALOMEDS::SObject_var aSO;
1779 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myHypothesis, nomHypothesis);
1781 // D. Valeurs par defaut des options avancees
1782 myHypothesis->SetNivMax(-1);
1783 myHypothesis->SetDiamMin(-1.0);
1784 myHypothesis->SetAdapInit(0);
1785 myHypothesis->SetExtraOutput(1);
1787 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1790 //=============================================================================
1791 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1792 //=============================================================================
1794 MESSAGE ("CreateIteration : NomIteration = " << NomIteration << ", nomIterParent = " << nomIterParent);
1797 HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterParent];
1798 if (CORBA::is_nil(myIterationParent))
1800 SALOME::ExceptionStruct es;
1801 es.type = SALOME::BAD_PARAM;
1802 es.text = "The parent iteration is not defined.";
1803 throw SALOME::SALOME_Exception(es);
1807 const char* nomCas = myIterationParent->GetCaseName();
1808 MESSAGE ("CreateIteration : nomCas = " << nomCas);
1809 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
1810 if (CORBA::is_nil(myCase))
1812 SALOME::ExceptionStruct es;
1813 es.type = SALOME::BAD_PARAM;
1814 es.text = "Invalid case context";
1815 throw SALOME::SALOME_Exception(es);
1818 const char* nomDirCase = myCase->GetDirName();
1820 // Controle du nom :
1821 if ((myStudyContext._mesIterations).find(NomIteration)!=(myStudyContext._mesIterations).end())
1823 SALOME::ExceptionStruct es;
1824 es.type = SALOME::BAD_PARAM;
1825 es.text = "This iteration has already been defined.";
1826 throw SALOME::SALOME_Exception(es);
1830 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1831 if (CORBA::is_nil(myIteration))
1833 SALOME::ExceptionStruct es;
1834 es.type = SALOME::BAD_PARAM;
1835 es.text = "Unable to create the iteration";
1836 throw SALOME::SALOME_Exception(es);
1839 myStudyContext._mesIterations[std::string(NomIteration)] = myIteration;
1840 // Nom de l'iteration et du maillage
1841 myIteration->SetName(NomIteration);
1842 myIteration->SetMeshName(NomIteration);
1843 myIteration->SetState(1);
1845 int numero = myIterationParent->GetNumber() + 1;
1846 myIteration->SetNumber(numero);
1848 // Nombre d'iterations deja connues pour le cas, permettant
1849 // la creation d'un sous-répertoire unique
1850 int nbitercase = myCase->GetNumberofIter();
1851 char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1852 myIteration->SetDirNameLoc(nomDirIter);
1854 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1855 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1856 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1857 // situation la plus frequente.
1858 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1859 // le nombre d'iterations du cas permet d'eviter les collisions.
1861 if ( nbitercase < 100 ) { jaux = 2 ; }
1862 else if ( nbitercase < 1000 ) { jaux = 3 ; }
1863 else if ( nbitercase < 10000 ) { jaux = 4 ; }
1864 else if ( nbitercase < 100000 ) { jaux = 5 ; }
1866 std::ostringstream iaux ;
1867 iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1868 std::stringstream MeshFile;
1869 MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1870 myIteration->SetMeshFile(MeshFile.str().c_str());
1872 // Association avec le cas
1873 std::string label = "IterationHomard_" + std::string(nomIterParent);
1874 AssociateCaseIter(nomCas, NomIteration, label.c_str());
1875 // Lien avec l'iteration precedente
1876 myIterationParent->LinkNextIteration(NomIteration);
1877 myIteration->SetIterParentName(nomIterParent);
1878 // Gestion de l'arbre d'etudes
1879 SALOMEDS::SObject_var aIterSOParent = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIterationParent)));
1880 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
1881 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
1882 aStudyBuilder->NewCommand();
1883 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
1884 aStudyBuilder->Addreference(aSubSO, aIterSOParent);
1885 aStudyBuilder->CommitCommand();
1887 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1889 //=============================================================================
1890 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1892 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1895 // Controle du nom :
1896 if ((myStudyContext._mesBoundarys).find(BoundaryName)!=(myStudyContext._mesBoundarys).end())
1898 MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1899 SALOME::ExceptionStruct es;
1900 es.type = SALOME::BAD_PARAM;
1901 es.text = "This boundary has already been defined";
1902 throw SALOME::SALOME_Exception(es);
1906 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1907 myBoundary->SetName(BoundaryName);
1908 myBoundary->SetType(BoundaryType);
1910 myStudyContext._mesBoundarys[BoundaryName] = myBoundary;
1912 SALOMEDS::SObject_var aSO;
1913 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myBoundary, BoundaryName);
1915 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1917 //=============================================================================
1918 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCAO(const char* BoundaryName, const char* CAOFile)
1920 MESSAGE ("CreateBoundaryCAO : BoundaryName = " << BoundaryName << ", CAOFile = " << CAOFile );
1921 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, -1);
1922 myBoundary->SetDataFile( CAOFile ) ;
1924 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1926 //=============================================================================
1927 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1929 MESSAGE ("CreateBoundaryDi : BoundaryName = " << BoundaryName << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1930 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1931 myBoundary->SetDataFile( MeshFile ) ;
1932 myBoundary->SetMeshName( MeshName ) ;
1934 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1936 //=============================================================================
1937 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1938 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1939 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1940 CORBA::Double Rayon)
1942 MESSAGE ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
1944 SALOME::ExceptionStruct es;
1947 { es.text = "The radius must be positive." ;
1949 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1950 if ( daux < 0.0000001 )
1951 { es.text = "The axis must be a non 0 vector." ;
1955 es.type = SALOME::BAD_PARAM;
1956 throw SALOME::SALOME_Exception(es);
1960 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1961 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1963 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1965 //=============================================================================
1966 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1967 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1968 CORBA::Double Rayon)
1970 MESSAGE ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
1972 SALOME::ExceptionStruct es;
1975 { es.text = "The radius must be positive." ;
1979 es.type = SALOME::BAD_PARAM;
1980 throw SALOME::SALOME_Exception(es);
1984 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1985 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1987 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1989 //=============================================================================
1990 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
1991 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
1992 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
1994 MESSAGE ("CreateBoundaryConeA : BoundaryName = " << BoundaryName ) ;
1996 SALOME::ExceptionStruct es;
1998 if ( Angle <= 0.0 || Angle >= 90.0 )
1999 { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
2001 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2002 if ( daux < 0.0000001 )
2003 { es.text = "The axis must be a non 0 vector." ;
2007 es.type = SALOME::BAD_PARAM;
2008 throw SALOME::SALOME_Exception(es);
2012 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
2013 myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
2015 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2017 //=============================================================================
2018 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
2019 CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
2020 CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
2022 MESSAGE ("CreateBoundaryConeR : BoundaryName = " << BoundaryName ) ;
2024 SALOME::ExceptionStruct es;
2026 if ( Rayon1 < 0.0 || Rayon2 < 0.0 )
2027 { es.text = "The radius must be positive." ;
2029 double daux = fabs(Rayon2-Rayon1) ;
2030 if ( daux < 0.0000001 )
2031 { es.text = "The radius must be different." ;
2033 daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
2034 if ( daux < 0.0000001 )
2035 { es.text = "The centers must be different." ;
2039 es.type = SALOME::BAD_PARAM;
2040 throw SALOME::SALOME_Exception(es);
2044 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
2045 myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
2047 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2049 //=============================================================================
2050 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryTorus(const char* BoundaryName,
2051 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2052 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2053 CORBA::Double RayonRev, CORBA::Double RayonPri)
2055 MESSAGE ("CreateBoundaryTorus : BoundaryName = " << BoundaryName ) ;
2057 SALOME::ExceptionStruct es;
2059 if ( ( RayonRev <= 0.0 ) || ( RayonPri <= 0.0 ) )
2060 { es.text = "The radius must be positive." ;
2062 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2063 if ( daux < 0.0000001 )
2064 { es.text = "The axis must be a non 0 vector." ;
2068 es.type = SALOME::BAD_PARAM;
2069 throw SALOME::SALOME_Exception(es);
2073 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 5) ;
2074 myBoundary->SetTorus( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, RayonRev, RayonPri ) ;
2076 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2078 //=============================================================================
2079 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
2081 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
2084 // Controle du nom :
2085 if ((myStudyContext._mesZones).find(ZoneName)!=(myStudyContext._mesZones).end())
2087 SALOME::ExceptionStruct es;
2088 es.type = SALOME::BAD_PARAM;
2089 es.text = "This zone has already been defined";
2090 throw SALOME::SALOME_Exception(es);
2094 HOMARD::HOMARD_Zone_var myZone = newZone();
2095 myZone->SetName(ZoneName);
2096 myZone->SetType(ZoneType);
2098 myStudyContext._mesZones[ZoneName] = myZone;
2100 SALOMEDS::SObject_var aSO;
2101 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myZone, ZoneName);
2103 return HOMARD::HOMARD_Zone::_duplicate(myZone);
2105 //=============================================================================
2106 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
2107 CORBA::Double Xmini, CORBA::Double Xmaxi,
2108 CORBA::Double Ymini, CORBA::Double Ymaxi,
2109 CORBA::Double Zmini, CORBA::Double Zmaxi)
2111 MESSAGE ("CreateZoneBox : ZoneName = " << ZoneName ) ;
2113 SALOME::ExceptionStruct es;
2115 if ( Xmini > Xmaxi )
2116 { es.text = "The X coordinates are not coherent." ;
2118 if ( Ymini > Ymaxi )
2119 { es.text = "The Y coordinates are not coherent." ;
2121 if ( Zmini > Zmaxi )
2122 { es.text = "The Z coordinates are not coherent." ;
2126 es.type = SALOME::BAD_PARAM;
2127 throw SALOME::SALOME_Exception(es);
2131 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
2132 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2134 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2136 //=============================================================================
2137 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
2138 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
2140 MESSAGE ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
2142 SALOME::ExceptionStruct es;
2145 { es.text = "The radius must be positive." ;
2149 es.type = SALOME::BAD_PARAM;
2150 throw SALOME::SALOME_Exception(es);
2154 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
2155 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2157 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2159 //=============================================================================
2160 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
2161 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2162 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2163 CORBA::Double Rayon, CORBA::Double Haut)
2165 MESSAGE ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
2167 SALOME::ExceptionStruct es;
2170 { es.text = "The radius must be positive." ;
2172 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2173 if ( daux < 0.0000001 )
2174 { es.text = "The axis must be a non 0 vector." ;
2177 { es.text = "The height must be positive." ;
2181 es.type = SALOME::BAD_PARAM;
2182 throw SALOME::SALOME_Exception(es);
2186 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
2187 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
2189 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2191 //=============================================================================
2192 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
2193 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2194 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2195 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
2197 MESSAGE ("CreateZonePipe : ZoneName = " << ZoneName ) ;
2199 SALOME::ExceptionStruct es;
2201 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2202 { es.text = "The radius must be positive." ;
2204 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2205 if ( daux < 0.0000001 )
2206 { es.text = "The axis must be a non 0 vector." ;
2209 { es.text = "The height must be positive." ;
2211 if ( Rayon <= Rayonint )
2212 { es.text = "The external radius must be higher than the internal radius." ;
2216 es.type = SALOME::BAD_PARAM;
2217 throw SALOME::SALOME_Exception(es);
2221 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
2222 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
2224 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2226 //=============================================================================
2227 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
2228 CORBA::Double Umini, CORBA::Double Umaxi,
2229 CORBA::Double Vmini, CORBA::Double Vmaxi,
2232 MESSAGE ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
2233 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
2234 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
2235 // MESSAGE ("Orient = " << Orient ) ;
2237 SALOME::ExceptionStruct es;
2239 if ( Umini > Umaxi )
2240 { es.text = "The first coordinates are not coherent." ;
2242 if ( Vmini > Vmaxi )
2243 { es.text = "The second coordinates are not coherent." ;
2245 if ( Orient < 1 || Orient > 3 )
2246 { es.text = "The orientation must be 1, 2 or 3." ;
2250 es.type = SALOME::BAD_PARAM;
2251 throw SALOME::SALOME_Exception(es);
2255 double Xmini, Xmaxi ;
2256 double Ymini, Ymaxi ;
2257 double Zmini, Zmaxi ;
2265 else if ( Orient == 2 )
2272 else if ( Orient == 3 )
2279 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2281 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2282 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2284 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2286 //=============================================================================
2287 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2288 CORBA::Double Ucentre, CORBA::Double Vcentre,
2289 CORBA::Double Rayon,
2292 MESSAGE ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
2294 SALOME::ExceptionStruct es;
2297 { es.text = "The radius must be positive." ;
2299 if ( Orient < 1 || Orient > 3 )
2300 { es.text = "The orientation must be 1, 2 or 3." ;
2304 es.type = SALOME::BAD_PARAM;
2305 throw SALOME::SALOME_Exception(es);
2313 { Xcentre = Ucentre ;
2316 else if ( Orient == 2 )
2319 Zcentre = Vcentre ; }
2320 else if ( Orient == 3 )
2321 { Xcentre = Vcentre ;
2323 Zcentre = Ucentre ; }
2324 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2326 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2327 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2329 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2331 //=============================================================================
2332 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2333 CORBA::Double Ucentre, CORBA::Double Vcentre,
2334 CORBA::Double Rayon, CORBA::Double Rayonint,
2337 MESSAGE ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
2339 SALOME::ExceptionStruct es;
2341 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2342 { es.text = "The radius must be positive." ;
2344 if ( Orient < 1 || Orient > 3 )
2345 { es.text = "The orientation must be 1, 2 or 3." ;
2347 if ( Rayon <= Rayonint )
2348 { es.text = "The external radius must be higher than the internal radius." ;
2352 es.type = SALOME::BAD_PARAM;
2353 throw SALOME::SALOME_Exception(es);
2361 { Xcentre = Ucentre ;
2364 else if ( Orient == 2 )
2367 Zcentre = Vcentre ; }
2368 else if ( Orient == 3 )
2369 { Xcentre = Vcentre ;
2371 Zcentre = Ucentre ; }
2372 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2374 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2375 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2377 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2379 //=============================================================================
2380 //=============================================================================
2385 //=============================================================================
2386 //=============================================================================
2387 // Traitement d'une iteration
2388 // etatMenage = 1 : destruction du répertoire d'execution
2389 // modeHOMARD = 1 : adaptation
2390 // != 1 : information avec les options modeHOMARD
2391 // Option1 >0 : appel depuis python
2392 // <0 : appel depuis GUI
2393 // Option2 : multiple de nombres premiers
2394 // 1 : aucune option
2395 // x2 : publication du maillage dans SMESH
2396 //=============================================================================
2397 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2399 INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2404 // A.1. L'objet iteration
2405 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIteration];
2406 ASSERT(!CORBA::is_nil(myIteration));
2408 // A.2. Controle de la possibilite d'agir
2409 // A.2.1. Etat de l'iteration
2410 int etat = myIteration->GetState();
2411 MESSAGE ( "etat = "<<etat );
2412 // A.2.2. On ne calcule pas l'iteration initiale, ni une iteration deja calculee
2413 if ( modeHOMARD == 1 )
2417 SALOME::ExceptionStruct es;
2418 es.type = SALOME::BAD_PARAM;
2419 es.text = "This iteration is the first of the case and cannot be computed.";
2420 throw SALOME::SALOME_Exception(es);
2423 else if ( ( etat == 2 ) & ( modeHOMARD == 1 ) )
2425 SALOME::ExceptionStruct es;
2426 es.type = SALOME::BAD_PARAM;
2427 es.text = "This iteration is already computed.";
2428 throw SALOME::SALOME_Exception(es);
2432 // A.2.3. On n'analyse pas une iteration non calculee
2437 SALOME::ExceptionStruct es;
2438 es.type = SALOME::BAD_PARAM;
2439 es.text = "This iteration is not computed.";
2440 throw SALOME::SALOME_Exception(es);
2445 // A.3. Numero de l'iteration
2446 // siterp1 : numero de l'iteration a traiter
2448 // siter : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2449 // Ou si information :
2451 int NumeIter = myIteration->GetNumber();
2452 std::string siterp1 ;
2453 std::stringstream saux1 ;
2455 siterp1 = saux1.str() ;
2456 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2459 if ( modeHOMARD==1 )
2461 std::stringstream saux0 ;
2462 int iaux = max(0, NumeIter-1) ;
2464 siter = saux0.str() ;
2465 if (NumeIter < 11) { siter = "0" + siter ; }
2468 { siter = siterp1 ; }
2471 const char* nomCas = myIteration->GetCaseName();
2472 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
2473 ASSERT(!CORBA::is_nil(myCase));
2475 // B. Les répertoires
2476 // B.1. Le répertoire courant
2477 std::string nomDirWork = getenv("PWD") ;
2478 // B.2. Le sous-répertoire de l'iteration a traiter
2479 char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2480 MESSAGE( ". DirCompute = " << DirCompute );
2482 // C. Le fichier des messages
2483 // C.1. Le deroulement de l'execution de HOMARD
2484 std::string LogFile = DirCompute ;
2485 LogFile += "/Liste" ;
2486 if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2488 MESSAGE (". LogFile = " << LogFile);
2489 if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2490 // C.2. Le bilan de l'analyse du maillage
2491 std::string FileInfo = DirCompute ;
2493 if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2495 { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2496 else { FileInfo += "info_ap" ; }
2498 FileInfo += "." + siterp1 + ".bilan" ;
2499 myIteration->SetFileInfo(FileInfo.c_str());
2501 // D. On passe dans le répertoire de l'iteration a calculer
2502 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2505 // E. Les données de l'exécution HOMARD
2506 // E.1. L'objet du texte du fichier de configuration
2507 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2508 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2510 // E.2. Le maillage associe a l'iteration
2511 const char* NomMesh = myIteration->GetMeshName();
2512 MESSAGE ( ". NomMesh = " << NomMesh );
2513 const char* MeshFile = myIteration->GetMeshFile();
2514 MESSAGE ( ". MeshFile = " << MeshFile );
2516 // E.3. Les données du traitement HOMARD
2518 if ( modeHOMARD == 1 )
2521 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2522 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2523 codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2527 InvalideIterInfo(NomIteration);
2528 myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2530 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2531 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2532 myDriver->CreeFichierDonn();
2535 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2536 int BoundaryOption = DriverTexteBoundary(myCase, myDriver) ;
2538 // E.5. Ecriture du texte dans le fichier
2539 MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2541 { myDriver->CreeFichier(); }
2545 int codretexec = 1789 ;
2548 codretexec = myDriver->ExecuteHomard(Option1);
2550 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2551 // En mode adaptation, on ajuste l'etat de l'iteration
2552 if ( modeHOMARD == 1 )
2554 if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2555 else { SetEtatIter(NomIteration,1); }
2556 // GERALD -- QMESSAGE BOX
2560 // H. Gestion des resultats
2563 std::string Commentaire ;
2564 // H.1. Le fichier des messages, dans tous les cas
2565 Commentaire = "log" ;
2566 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2567 else { Commentaire += "Info" ; }
2568 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2570 // H.2. Si tout s'est bien passe :
2571 if (codretexec == 0)
2573 // H.2.1. Le fichier de bilan
2574 Commentaire = "Summary" ;
2575 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2576 else { Commentaire += "Info" ; }
2577 PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2578 // H.2.2. Le fichier de maillage obtenu
2579 if ( modeHOMARD == 1 )
2581 std::stringstream saux0 ;
2582 Commentaire = "Mesh" ;
2583 Commentaire += " " + siterp1 ;
2584 PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2585 if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2588 // H.3 Message d'erreur
2589 if (codretexec != 0)
2591 std::string text = "" ;
2592 // Message d'erreur en cas de probleme en adaptation
2593 if ( modeHOMARD == 1 )
2595 text = "Error during the adaptation.\n" ;
2596 bool stopvu = false ;
2597 std::ifstream fichier( LogFile.c_str() );
2598 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
2600 std::string ligne; // variable contenant chaque ligne lue
2601 while ( std::getline( fichier, ligne ) )
2605 { text += ligne+ "\n"; }
2608 int position = ligne.find( "===== HOMARD ===== STOP =====" ) ;
2609 if ( position > 0 ) { stopvu = true ; }
2614 text += "\n\nSee the file " + LogFile + "\n" ;
2616 SALOME::ExceptionStruct es;
2617 es.type = SALOME::BAD_PARAM;
2618 es.text = CORBA::string_dup(text.c_str());
2619 throw SALOME::SALOME_Exception(es);
2621 // En mode information, on force le succes pour pouvoir consulter le fichier log
2622 if ( modeHOMARD != 1 ) { codretexec = 0 ; }
2626 // I. Menage et retour dans le répertoire du cas
2630 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2632 CHDIR(nomDirWork.c_str());
2635 // J. Suivi de la frontière CAO
2636 // std::cout << "- codret : " << codret << std::endl;
2637 // std::cout << "- modeHOMARD : " << modeHOMARD << std::endl;
2638 // std::cout << "- BoundaryOption : " << BoundaryOption << std::endl;
2639 // std::cout << "- codretexec : " << codretexec << std::endl;
2642 if ( ( modeHOMARD == 1 ) && ( BoundaryOption % 5 == 0 ) && (codretexec == 0) )
2644 MESSAGE ( "Suivi de frontière CAO" );
2645 codret = ComputeCAO(myCase, myIteration, Option1, Option2) ;
2651 //=============================================================================
2652 // Calcul d'une iteration : partie spécifique à l'adaptation
2653 //=============================================================================
2654 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)
2656 MESSAGE ( "ComputeAdap avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2661 // Numero de l'iteration
2662 int NumeIter = myIteration->GetNumber();
2663 std::stringstream saux0 ;
2664 saux0 << NumeIter-1 ;
2665 std::string siter = saux0.str() ;
2666 if (NumeIter < 11) { siter = "0" + siter ; }
2668 // A.2. On verifie qu il y a une hypothese (erreur improbable);
2669 const char* nomHypo = myIteration->GetHypoName();
2670 if (std::string(nomHypo) == std::string(""))
2672 SALOME::ExceptionStruct es;
2673 es.type = SALOME::BAD_PARAM;
2674 es.text = "This iteration does not have any associated hypothesis.";
2675 throw SALOME::SALOME_Exception(es);
2678 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
2679 ASSERT(!CORBA::is_nil(myHypo));
2681 // B. L'iteration parent
2682 const char* nomIterationParent = myIteration->GetIterParentName();
2683 HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterationParent];
2684 ASSERT(!CORBA::is_nil(myIterationParent));
2685 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2686 if ( myIterationParent->GetState() == 1 )
2689 int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2692 // GERALD -- QMESSAGE BOX
2693 VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2697 // C. Le sous-répertoire de l'iteration precedente
2698 char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2699 MESSAGE( ". DirComputePa = " << DirComputePa );
2701 // D. Les données de l'adaptation HOMARD
2702 // D.1. Le type de conformite
2703 int ConfType = myCase->GetConfType();
2704 MESSAGE ( ". ConfType = " << ConfType );
2706 // D.1. Le type externe
2707 int ExtType = myCase->GetExtType();
2708 MESSAGE ( ". ExtType = " << ExtType );
2710 // D.3. Le maillage de depart
2711 const char* NomMeshParent = myIterationParent->GetMeshName();
2712 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2713 const char* MeshFileParent = myIterationParent->GetMeshFile();
2714 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2716 // D.4. Le maillage associe a l'iteration
2717 const char* MeshFile = myIteration->GetMeshFile();
2718 MESSAGE ( ". MeshFile = " << MeshFile );
2719 FILE *file = fopen(MeshFile,"r");
2723 if (etatMenage == 0)
2725 SALOME::ExceptionStruct es;
2726 es.type = SALOME::BAD_PARAM;
2727 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2728 es.text = CORBA::string_dup(text.c_str());
2729 throw SALOME::SALOME_Exception(es);
2734 std::string commande = "rm -f " + std::string(MeshFile);
2735 codret = system(commande.c_str());
2738 SALOME::ExceptionStruct es;
2739 es.type = SALOME::BAD_PARAM;
2740 es.text = "The mesh file cannot be deleted.";
2741 throw SALOME::SALOME_Exception(es);
2747 // D.5. Les types de raffinement et de deraffinement
2748 // Les appels corba sont lourds, il vaut mieux les grouper
2749 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2750 ASSERT(ListTypes->length() == 3);
2751 int TypeAdap = (*ListTypes)[0];
2752 int TypeRaff = (*ListTypes)[1];
2753 int TypeDera = (*ListTypes)[2];
2754 // MESSAGE ( ". TypeAdap = " << TypeAdap << ", TypeRaff = " << TypeRaff << ", TypeDera = " << TypeDera );
2756 // E. Texte du fichier de configuration
2757 // E.1. Incontournables du texte
2758 myDriver->TexteAdap(ExtType);
2760 myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2761 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2762 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2764 // E.2. Ajout des informations liees aux zones eventuelles
2765 if ( TypeAdap == 0 )
2766 { DriverTexteZone(myHypo, myDriver) ; }
2768 // E.3. Ajout des informations liees aux champs eventuels
2769 if ( TypeAdap == 1 )
2770 { DriverTexteField(myIteration, myHypo, myDriver) ; }
2772 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2773 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2774 int numberOfGroups = listeGroupes->length();
2775 MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2776 if (numberOfGroups > 0)
2778 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2780 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2781 MESSAGE( "... GroupName = " << GroupName );
2782 myDriver->TexteGroup(GroupName);
2786 // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2787 DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2789 // E.6. Ajout des options avancees
2790 int Pyram = myCase->GetPyram();
2791 MESSAGE ( ". Pyram = " << Pyram );
2792 int NivMax = myHypo->GetNivMax();
2793 MESSAGE ( ". NivMax = " << NivMax );
2794 double DiamMin = myHypo->GetDiamMin() ;
2795 MESSAGE ( ". DiamMin = " << DiamMin );
2796 int AdapInit = myHypo->GetAdapInit();
2797 MESSAGE ( ". AdapInit = " << AdapInit );
2798 int ExtraOutput = myHypo->GetExtraOutput();
2799 MESSAGE ( ". ExtraOutput = " << ExtraOutput );
2800 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, ExtraOutput);
2802 // E.7. Ajout des informations sur le deroulement de l'execution
2803 int MessInfo = myIteration->GetInfoCompute();
2804 MESSAGE ( ". MessInfo = " << MessInfo );
2805 myDriver->TexteInfoCompute(MessInfo);
2809 //=============================================================================
2810 // Calcul d'une iteration : partie spécifique au suivi de frontière CAO
2811 //=============================================================================
2812 CORBA::Long HOMARD_Gen_i::ComputeCAO(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long Option1, CORBA::Long Option2)
2814 MESSAGE ( "ComputeCAO avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2819 // A.2. Le sous-répertoire de l'iteration en cours de traitement
2820 char* DirCompute = myIteration->GetDirName();
2821 // A.3. Le maillage résultat de l'iteration en cours de traitement
2822 char* MeshFile = myIteration->GetMeshFile();
2824 // B. Les données pour FrontTrack
2825 // B.1. Le maillage à modifier
2826 const std::string theInputMedFile = MeshFile;
2827 MESSAGE ( ". theInputMedFile = " << theInputMedFile );
2829 // B.2. Le maillage après modification : fichier identique
2830 const std::string theOutputMedFile = MeshFile ;
2831 MESSAGE ( ". theOutputMedFile = " << theInputMedFile );
2833 // B.3. La liste des fichiers contenant les numéros des noeuds à bouger
2834 std::vector< std::string > theInputNodeFiles ;
2835 MESSAGE ( ". DirCompute = " << DirCompute );
2840 struct dirent *dirp;
2841 dp = opendir(DirCompute);
2842 while ( (dirp = readdir(dp)) != NULL )
2844 std::string file_name(dirp->d_name);
2845 bilan = file_name.find("fr") ;
2846 if ( bilan != string::npos )
2848 std::stringstream filename_total ;
2849 filename_total << DirCompute << "/" << file_name ;
2850 theInputNodeFiles.push_back(filename_total.str()) ;
2855 HANDLE hFind = INVALID_HANDLE_VALUE;
2856 WIN32_FIND_DATA ffd;
2857 hFind = FindFirstFile(DirNameStart, &ffd);
2858 if (INVALID_HANDLE_VALUE != hFind) {
2859 while (FindNextFile(hFind, &ffd) != 0) {
2860 std::string file_name(ffd.cFileName);
2861 bilan = file_name.find("fr") ;
2862 if ( bilan != string::npos )
2864 std::stringstream filename_total ;
2865 filename_total << DirCompute << "/" << file_name ;
2866 theInputNodeFiles.push_back(filename_total.str()) ;
2873 for ( int i = 0; i < icpt; i++ )
2874 { MESSAGE ( ". theInputNodeFiles["<< i << "] = " << theInputNodeFiles[i] ); }
2876 // B.4. Le fichier de la CAO
2877 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2878 std::string BoundaryName = std::string((*ListBoundaryGroupType)[0]);
2879 MESSAGE ( ". BoundaryName = " << BoundaryName );
2880 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
2881 const std::string theXaoFileName = myBoundary->GetDataFile();
2882 MESSAGE ( ". theXaoFileName = " << theXaoFileName );
2884 // B.5. Parallélisme
2885 bool theIsParallel = false;
2887 // C. Lancement des projections
2888 MESSAGE ( ". Lancement des projections" );
2889 FrontTrack* myFrontTrack = new FrontTrack();
2890 myFrontTrack->track(theInputMedFile, theOutputMedFile, theInputNodeFiles, theXaoFileName, theIsParallel);
2892 // D. Transfert des coordonnées modifiées dans le fichier historique de HOMARD
2893 // On lance une exécution spéciale de HOMARD en attendant de savoir le faire avec MEDCoupling
2894 MESSAGE ( ". Transfert des coordonnées" );
2895 codret = ComputeCAObis(myIteration, Option1, Option2) ;
2899 //=============================================================================
2900 //=============================================================================
2901 // Transfert des coordonnées en suivi de frontière CAO
2902 // Option1 >0 : appel depuis python
2903 // <0 : appel depuis GUI
2904 // Option2 : multiple de nombres premiers
2905 // 1 : aucune option
2906 // x2 : publication du maillage dans SMESH
2907 //=============================================================================
2908 CORBA::Long HOMARD_Gen_i::ComputeCAObis(HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long Option1, CORBA::Long Option2)
2910 MESSAGE ( "ComputeCAObis, avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2915 // A.1. Controle de la possibilite d'agir
2916 // A.1.1. Etat de l'iteration
2917 int etat = myIteration->GetState();
2918 MESSAGE ( "etat = "<<etat );
2919 // A.1.2. L'iteration doit être calculee
2922 SALOME::ExceptionStruct es;
2923 es.type = SALOME::BAD_PARAM;
2924 es.text = "This iteration is not computed.";
2925 throw SALOME::SALOME_Exception(es);
2928 // A.2. Numero de l'iteration
2929 // siterp1 : numero de l'iteration a traiter
2930 int NumeIter = myIteration->GetNumber();
2931 std::string siterp1 ;
2932 std::stringstream saux1 ;
2934 siterp1 = saux1.str() ;
2935 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2936 MESSAGE ( "siterp1 = "<<siterp1 );
2939 const char* CaseName = myIteration->GetCaseName();
2940 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[CaseName];
2941 ASSERT(!CORBA::is_nil(myCase));
2943 // A.4. Le sous-répertoire de l'iteration a traiter
2944 char* DirCompute = myIteration->GetDirName();
2945 MESSAGE( ". DirCompute = " << DirCompute );
2947 // C. Le fichier des messages
2948 std::string LogFile = DirCompute ;
2949 LogFile += "/Liste." + siterp1 + ".maj_coords.log" ;
2950 MESSAGE (". LogFile = " << LogFile);
2951 myIteration->SetFileInfo(LogFile.c_str());
2953 // D. On passe dans le répertoire de l'iteration a calculer
2954 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2957 // E. Les données de l'exécution HOMARD
2958 // E.1. L'objet du texte du fichier de configuration
2959 HomardDriver* myDriver = new HomardDriver("", siterp1);
2960 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2962 // E.2. Le maillage associe a l'iteration
2963 const char* NomMesh = myIteration->GetMeshName();
2964 MESSAGE ( ". NomMesh = " << NomMesh );
2965 const char* MeshFile = myIteration->GetMeshFile();
2966 MESSAGE ( ". MeshFile = " << MeshFile );
2968 // E.3. Les données du traitement HOMARD
2970 myDriver->TexteMajCoords( NumeIter ) ;
2972 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2973 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2975 // E.4. Ecriture du texte dans le fichier
2976 MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2978 { myDriver->CreeFichier(); }
2982 int codretexec = 1789 ;
2985 codretexec = myDriver->ExecuteHomard(Option1);
2986 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2989 // G. Gestion des resultats
2992 // G.1. Le fichier des messages, dans tous les cas
2993 const char* NomIteration = myIteration->GetName();
2994 std::string Commentaire = "logmaj_coords" ;
2995 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2996 // G.2 Message d'erreur
2997 if (codretexec != 0)
2999 std::string text = "\n\nSee the file " + LogFile + "\n" ;
3001 SALOME::ExceptionStruct es;
3002 es.type = SALOME::BAD_PARAM;
3003 es.text = CORBA::string_dup(text.c_str());
3004 throw SALOME::SALOME_Exception(es);
3006 // On force le succes pour pouvoir consulter le fichier log
3011 // H. Menage et retour dans le répertoire du cas
3012 if (codret == 0) { delete myDriver; }
3016 //=============================================================================
3017 // Creation d'un nom de sous-répertoire pour l'iteration au sein d'un répertoire parent
3018 // nomrep : nom du répertoire parent
3019 // num : le nom du sous-répertoire est sous la forme 'In', n est >= num
3020 //=============================================================================
3021 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
3023 MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
3024 // On verifie que le répertoire parent existe
3025 int codret = CHDIR(nomrep) ;
3028 SALOME::ExceptionStruct es;
3029 es.type = SALOME::BAD_PARAM;
3030 es.text = "The directory of the case does not exist.";
3031 throw SALOME::SALOME_Exception(es);
3034 std::string nomDirActuel = getenv("PWD") ;
3035 std::string DirName ;
3036 // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un répertoire inconnu
3037 bool a_chercher = true ;
3038 while ( a_chercher )
3040 // On passe dans le répertoire parent
3043 // On recherche un nom sous la forme Iabc, avec abc representant le numero
3045 if ( num < 100 ) { jaux = 2 ; }
3046 else if ( num < 1000 ) { jaux = 3 ; }
3047 else if ( num < 10000 ) { jaux = 4 ; }
3048 else if ( num < 100000 ) { jaux = 5 ; }
3050 std::ostringstream iaux ;
3051 iaux << std::setw(jaux) << std::setfill('0') << num ;
3052 std::ostringstream DirNameA ;
3053 DirNameA << "I" << iaux.str();
3054 // Si on ne pas peut entrer dans le répertoire, on doit verifier
3055 // que c'est bien un probleme d'absence
3056 if ( CHDIR(DirNameA.str().c_str()) != 0 )
3058 bool existe = false ;
3061 struct dirent *dirp;
3062 dp = opendir(nomrep);
3063 while ( (dirp = readdir(dp)) != NULL )
3065 std::string file_name(dirp->d_name);
3067 HANDLE hFind = INVALID_HANDLE_VALUE;
3068 WIN32_FIND_DATA ffd;
3069 hFind = FindFirstFile(nomrep, &ffd);
3070 if (INVALID_HANDLE_VALUE != hFind) {
3071 while (FindNextFile(hFind, &ffd) != 0) {
3072 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
3073 std::string file_name(ffd.cFileName);
3075 if ( file_name == DirNameA.str() ) { existe = true ; }
3084 DirName = DirNameA.str() ;
3085 a_chercher = false ;
3092 MESSAGE ( "==> DirName = " << DirName);
3093 MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
3094 CHDIR(nomDirActuel.c_str());
3095 return CORBA::string_dup( DirName.c_str() );
3097 //=============================================================================
3098 // Calcul d'une iteration : gestion du répertoire de calcul
3099 // Si le sous-répertoire existe :
3100 // etatMenage = 0 : on sort en erreur si le répertoire n'est pas vide
3101 // etatMenage = 1 : on fait le menage du répertoire
3102 // etatMenage = -1 : on ne fait rien
3103 //=============================================================================
3104 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
3106 MESSAGE ( "ComputeDirManagement : répertoires pour le calcul" );
3107 // B.2. Le répertoire du cas
3108 const char* nomDirCase = myCase->GetDirName();
3109 MESSAGE ( ". nomDirCase = " << nomDirCase );
3111 // B.3. Le sous-répertoire de l'iteration a calculer, puis le répertoire complet a creer
3112 // B.3.1. Le nom du sous-répertoire
3113 const char* nomDirIt = myIteration->GetDirNameLoc();
3115 // B.3.2. Le nom complet du sous-répertoire
3116 std::stringstream DirCompute ;
3117 DirCompute << nomDirCase << "/" << nomDirIt;
3118 MESSAGE (". DirCompute = " << DirCompute.str() );
3120 // B.3.3. Si le sous-répertoire n'existe pas, on le cree
3121 if (CHDIR(DirCompute.str().c_str()) != 0)
3124 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
3126 if (_mkdir(DirCompute.str().c_str()) != 0)
3129 // GERALD -- QMESSAGE BOX
3130 std::cerr << "Pb Creation du répertoire DirCompute = " << DirCompute.str() << std::endl;
3131 VERIFICATION("Pb a la creation du répertoire" == 0);
3136 // Le répertoire existe
3137 // On demande de faire le menage de son contenu :
3138 if (etatMenage == 1)
3140 MESSAGE (". Menage du répertoire DirCompute = " << DirCompute.str());
3141 std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
3142 int codret = system(commande.c_str());
3145 // GERALD -- QMESSAGE BOX
3146 std::cerr << ". Menage du répertoire de calcul" << DirCompute.str() << std::endl;
3147 VERIFICATION("Pb au menage du répertoire de calcul" == 0);
3150 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
3153 if (etatMenage == 0)
3157 struct dirent *dirp;
3158 dp = opendir(DirCompute.str().c_str());
3160 while ((dirp = readdir(dp)) != NULL && result )
3162 std::string file_name(dirp->d_name);
3163 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3167 HANDLE hFind = INVALID_HANDLE_VALUE;
3168 WIN32_FIND_DATA ffd;
3169 hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
3171 if (INVALID_HANDLE_VALUE != hFind) {
3172 while (FindNextFile(hFind, &ffd) != 0) {
3173 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
3174 std::string file_name(ffd.cFileName);
3175 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3180 if ( result == false)
3182 SALOME::ExceptionStruct es;
3183 es.type = SALOME::BAD_PARAM;
3184 std::string text = "Directory : " + DirCompute.str() + " is not empty";
3185 es.text = CORBA::string_dup(text.c_str());
3186 throw SALOME::SALOME_Exception(es);
3187 VERIFICATION("Directory is not empty" == 0);
3193 return CORBA::string_dup( DirCompute.str().c_str() );
3195 //=============================================================================
3196 // Calcul d'une iteration : gestion du répertoire de calcul de l'iteration parent
3197 //=============================================================================
3198 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
3200 MESSAGE ( "ComputeDirPaManagement : répertoires pour le calcul" );
3201 // Le répertoire du cas
3202 const char* nomDirCase = myCase->GetDirName();
3203 MESSAGE ( ". nomDirCase = " << nomDirCase );
3205 // Le sous-répertoire de l'iteration precedente
3207 const char* nomIterationParent = myIteration->GetIterParentName();
3208 HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterationParent];
3209 const char* nomDirItPa = myIterationParent->GetDirNameLoc();
3210 std::stringstream DirComputePa ;
3211 DirComputePa << nomDirCase << "/" << nomDirItPa;
3212 MESSAGE( ". nomDirItPa = " << nomDirItPa);
3213 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
3215 return CORBA::string_dup( DirComputePa.str().c_str() );
3217 //=============================================================================
3218 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
3219 //=============================================================================
3220 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3222 MESSAGE ( "... DriverTexteZone" );
3223 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3224 int numberOfZonesx2 = ListZone->length();
3227 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3229 std::string ZoneName = std::string((*ListZone)[iaux]);
3230 MESSAGE ( "... ZoneName = " << ZoneName);
3231 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
3232 ASSERT(!CORBA::is_nil(myZone));
3234 int ZoneType = myZone->GetType();
3235 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
3236 int TypeUse = atoi( TypeUsestr.c_str() );
3237 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
3238 NumZone = iaux/2 + 1 ;
3239 HOMARD::double_array* zone = myZone->GetCoords();
3240 if ( ZoneType == 2 || ( ZoneType>=11 && ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
3241 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
3242 else if ( ZoneType == 4 ) // Cas d une sphere
3243 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
3244 else if ( ZoneType == 5 || ( ZoneType>=31 && ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
3245 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
3246 else if ( ZoneType == 7 || ( ZoneType>=61 && ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
3247 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
3248 else { VERIFICATION("ZoneType est incorrect." == 0) ; }
3253 //=============================================================================
3254 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
3255 //=============================================================================
3256 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3258 MESSAGE ( "... DriverTexteField" );
3259 // Le fichier du champ
3260 char* FieldFile = myIteration->GetFieldFile();
3261 MESSAGE ( ". FieldFile = " << FieldFile );
3262 if (strlen(FieldFile) == 0)
3264 // GERALD -- QMESSAGE BOX
3265 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
3266 VERIFICATION("The file for the field is not given." == 0);
3268 // Les caracteristiques d'instants du champ de pilotage
3269 int TimeStep = myIteration->GetTimeStep();
3270 MESSAGE( ". TimeStep = " << TimeStep );
3271 int Rank = myIteration->GetRank();
3272 MESSAGE( ". Rank = " << Rank );
3273 // Les informations sur les champs
3274 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
3276 const char* FieldName = aInfosHypo->FieldName;
3278 int TypeThR = aInfosHypo->TypeThR;
3279 double ThreshR = aInfosHypo->ThreshR;
3280 int TypeThC = aInfosHypo->TypeThC;
3281 double ThreshC = aInfosHypo->ThreshC;
3282 // Saut entre mailles ou non ?
3283 int UsField = aInfosHypo->UsField;
3284 MESSAGE( ". UsField = " << UsField );
3285 // L'usage des composantes
3286 int UsCmpI = aInfosHypo->UsCmpI;
3287 MESSAGE( ". UsCmpI = " << UsCmpI );
3289 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
3292 HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
3293 int numberOfCompos = mescompo->length();
3294 MESSAGE( ". numberOfCompos = " << numberOfCompos );
3295 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
3297 std::string nomCompo = std::string((*mescompo)[NumeComp]);
3298 MESSAGE( "... nomCompo = " << nomCompo );
3299 myDriver->TexteCompo(NumeComp, nomCompo);
3303 //=============================================================================
3304 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
3305 // On ecrit dans l'ordre :
3306 // 1. la definition des frontieres
3307 // 2. les liens avec les groupes
3308 // 3. un entier resumant le type de comportement pour les frontieres
3309 //=============================================================================
3310 int HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
3312 MESSAGE ( "... DriverTexteBoundary" );
3313 // 1. Recuperation des frontieres
3314 std::list<std::string> ListeBoundaryTraitees ;
3315 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3316 int numberOfitems = ListBoundaryGroupType->length();
3317 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
3318 int BoundaryOption = 1 ;
3319 // 2. Parcours des frontieres pour ecrire leur description
3320 int NumBoundaryAnalytical = 0 ;
3321 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3323 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3324 MESSAGE ( "... BoundaryName = " << BoundaryName);
3325 // 2.1. La frontiere a-t-elle deja ete ecrite ?
3326 // Cela arrive quand elle est liee a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
3328 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3329 while (it != ListeBoundaryTraitees.end())
3331 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3332 if ( BoundaryName == *it ) { A_faire = 0 ; }
3335 // 2.2. Ecriture de la frontiere
3338 // 2.2.1. Caracteristiques de la frontiere
3339 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
3340 ASSERT(!CORBA::is_nil(myBoundary));
3341 int BoundaryType = myBoundary->GetType();
3342 MESSAGE ( "... BoundaryType = " << BoundaryType );
3343 // 2.2.2. Ecriture selon le type
3344 // 2.2.2.1. Cas d une frontiere CAO
3345 if (BoundaryType == -1)
3347 // const char* CAOFile = myBoundary->GetDataFile() ;
3348 // MESSAGE ( ". CAOFile = " << CAOFile );
3349 if ( BoundaryOption % 5 != 0 ) { BoundaryOption = BoundaryOption*5 ; }
3351 // 2.2.2.2. Cas d une frontiere discrete
3352 else if (BoundaryType == 0)
3354 const char* MeshName = myBoundary->GetMeshName() ;
3355 MESSAGE ( ". MeshName = " << MeshName );
3356 const char* MeshFile = myBoundary->GetDataFile() ;
3357 MESSAGE ( ". MeshFile = " << MeshFile );
3358 myDriver->TexteBoundaryDi( MeshName, MeshFile);
3359 if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
3361 // 2.2.2.3. Cas d une frontiere analytique
3364 NumBoundaryAnalytical++ ;
3365 HOMARD::double_array* coor = myBoundary->GetCoords();
3366 if (BoundaryType == 1) // Cas d un cylindre
3368 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3369 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3371 else if (BoundaryType == 2) // Cas d une sphere
3373 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
3374 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3376 else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
3378 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3379 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3381 else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
3383 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3384 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3386 else if (BoundaryType == 5) // Cas d un tore
3388 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3389 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3392 // 2.2.3. Memorisation du traitement
3393 ListeBoundaryTraitees.push_back( BoundaryName );
3396 // 3. Parcours des frontieres pour ecrire les liens avec les groupes
3397 NumBoundaryAnalytical = 0 ;
3398 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3400 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3401 MESSAGE ( "... BoundaryName = " << BoundaryName);
3402 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
3403 ASSERT(!CORBA::is_nil(myBoundary));
3404 int BoundaryType = myBoundary->GetType();
3405 MESSAGE ( "... BoundaryType = " << BoundaryType );
3406 // 3.1. Recuperation du nom du groupe
3407 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
3408 MESSAGE ( "... GroupName = " << GroupName);
3409 // 3.2. Cas d une frontiere CAO
3410 if ( BoundaryType == -1 )
3412 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryCAOGr ( GroupName ) ; }
3414 // 3.3. Cas d une frontiere discrete
3415 else if ( BoundaryType == 0 )
3417 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
3419 // 3.4. Cas d une frontiere analytique
3422 NumBoundaryAnalytical++ ;
3423 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
3426 // 4. Ecriture de l'option finale
3427 myDriver->TexteBoundaryOption(BoundaryOption);
3429 return BoundaryOption ;
3431 //=============================================================================
3432 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3433 //=============================================================================
3434 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3436 MESSAGE ( "... DriverTexteFieldInterp" );
3437 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3438 MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3439 if (TypeFieldInterp != 0)
3441 // Le fichier des champs
3442 char* FieldFile = myIteration->GetFieldFile();
3443 MESSAGE ( ". FieldFile = " << FieldFile );
3444 if (strlen(FieldFile) == 0)
3446 // GERALD -- QMESSAGE BOX
3447 VERIFICATION("The file for the field is not given." == 0);
3450 const char* MeshFile = myIteration->GetMeshFile();
3451 myDriver->TexteFieldInterp(FieldFile, MeshFile);
3454 // Interpolation de tous les champs
3455 if ( TypeFieldInterp == 1 )
3457 myDriver->TexteFieldInterpAll();
3459 // Interpolation de certains champs
3460 else if (TypeFieldInterp == 2)
3462 // Les champs et leurs instants pour l'iteration
3463 HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3464 int numberOfFieldsx3 = ListFieldTSR->length();
3465 MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3466 // Les champs pour l'hypothese
3467 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3468 int numberOfFieldsx2 = ListField->length();
3469 MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3470 // On parcourt tous les champs de l'hypothese
3472 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3475 std::string FieldName = std::string((*ListField)[iaux]) ;
3476 // Le type d'interpolation
3477 std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3478 MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3479 // On cherche ?? savoir si des instants ont ??t?? pr??cis??s pour cette it??ration
3481 for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3484 std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3485 MESSAGE( "..... FieldName2 = " << FieldName2 );
3486 // Quand c'est le bon champ, on ecrit le pas de temps
3487 if ( FieldName == FieldName2 )
3491 std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3492 // Le numero d'ordre
3493 std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3494 MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3496 int TimeStep = atoi( TimeStepstr.c_str() );
3497 int Rank = atoi( Rankstr.c_str() );
3498 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3502 // Si aucun instant n'a été défini
3506 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3514 //===========================================================================
3515 //===========================================================================
3518 //===========================================================================
3519 //===========================================================================
3521 //===========================================================================
3522 //===========================================================================
3523 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::SObject_ptr theSObject,
3524 CORBA::Object_ptr theObject,
3525 const char* theName)
3527 MESSAGE("PublishInStudy pour " << theName);
3528 SALOMEDS::SObject_var aResultSO;
3529 if (CORBA::is_nil(myStudy))
3531 SALOME::ExceptionStruct es;
3532 es.type = SALOME::BAD_PARAM;
3533 es.text = "Invalid study context";
3534 throw SALOME::SALOME_Exception(es);
3538 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3539 // Rq : Iteration est publiee ailleurs
3540 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3541 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
3542 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3543 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3544 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3548 // Controle de la non publication d'un objet de meme nom
3549 if ( (!aBoundary->_is_nil()) || (!aHypo->_is_nil()) || (!aYACS->_is_nil()) || (!aZone->_is_nil()) )
3551 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(theName, ComponentDataType());
3552 if (listSO->length() >= 1)
3554 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3555 aResultSO = listSO[0];
3556 return aResultSO._retn();
3560 // Caracteristiques de l'etude
3561 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
3562 aStudyBuilder->NewCommand();
3563 if(!aBoundary->_is_nil())
3564 aResultSO = PublishBoundaryInStudy(aStudyBuilder, aBoundary, theName);
3565 else if(!aCase->_is_nil())
3566 aResultSO = PublishCaseInStudy(aStudyBuilder, aCase, theName);
3567 else if(!aHypo->_is_nil())
3568 aResultSO = PublishHypotheseInStudy(aStudyBuilder, aHypo, theName);
3569 else if(!aYACS->_is_nil())
3570 aResultSO = PublishYACSInStudy(aStudyBuilder, aYACS, theName);
3571 else if(!aZone->_is_nil())
3572 aResultSO = PublishZoneInStudy(aStudyBuilder, aZone, theName);
3574 aStudyBuilder->CommitCommand();
3576 return aResultSO._retn();
3578 //=============================================================================
3579 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy( SALOMEDS::StudyBuilder_var aStudyBuilder,
3580 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3582 MESSAGE("PublishBoundaryStudy pour "<<theName);
3583 SALOMEDS::SObject_var aResultSO;
3585 // Caracteristique de la Boundary
3586 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[theName];
3588 // On recupere le module pere dans l etude
3589 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3590 if (theFatherHomard->_is_nil())
3592 MESSAGE("theFatherHomard->_is_nil()");
3593 return aResultSO._retn();
3596 // On ajoute la categorie des boundarys dans l etude si necessaire
3597 if ( _tag_boun == 0 )
3600 _tag_boun = _tag_gene ;
3602 MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3603 SALOMEDS::SObject_var aSObject;
3604 if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3606 MESSAGE("Ajout de la categorie des boundarys");
3607 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3608 PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3610 else { MESSAGE("La categorie des boundarys existe deja."); }
3612 CORBA::Long BoundaryType = myBoundary->GetType();
3613 // MESSAGE("BoundaryType : "<<BoundaryType);
3616 switch (BoundaryType)
3619 { value = "BoundaryCAOHomard" ;
3620 icone = "geometry.png" ;
3624 { value = "BoundaryDiHomard" ;
3625 icone = "mesh_tree_mesh.png" ;
3629 { value = "BoundaryAnHomard" ;
3630 icone = "cylinderpointvector_2.png" ;
3634 { value = "BoundaryAnHomard" ;
3635 icone = "spherepoint_2.png" ;
3639 { value = "BoundaryAnHomard" ;
3640 icone = "conepointvector.png" ;
3644 { value = "BoundaryAnHomard" ;
3645 icone = "conedxyz.png" ;
3649 { value = "BoundaryAnHomard" ;
3650 icone = "toruspointvector.png" ;
3654 aResultSO = aStudyBuilder->NewObject(aSObject);
3655 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3656 return aResultSO._retn();
3658 //=============================================================================
3659 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3660 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3662 MESSAGE("PublishCaseInStudy pour "<<theName);
3663 SALOMEDS::SObject_var aResultSO;
3665 if (CORBA::is_nil(theObject)) {
3666 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3667 return aResultSO._retn();
3669 if (myStudy->_is_nil()) {
3670 MESSAGE("HOMARD_Gen_i::myStudy->_is_nil()");
3671 return aResultSO._retn();
3674 // On recupere le module pere dans l etude
3675 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3676 if (theFatherHomard->_is_nil())
3678 MESSAGE("theFatherHomard->_is_nil()");
3679 return aResultSO._retn();
3683 MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3684 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3685 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3686 _orb->object_to_string(theObject) ) ;
3688 return aResultSO._retn();
3690 //=============================================================================
3691 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3692 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3694 MESSAGE("PublishHypotheseInStudy pour "<<theName);
3695 SALOMEDS::SObject_var aResultSO;
3697 // On recupere le module pere dans l etude
3698 // On ajoute la categorie des hypotheses dans l etude si necessaire
3699 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3700 if (theFatherHomard->_is_nil())
3702 MESSAGE("theFatherHomard->_is_nil()");
3703 return aResultSO._retn();
3706 // On ajoute la categorie des hypotheses dans l etude si necessaire
3707 SALOMEDS::SObject_var aSObject;
3708 if ( _tag_hypo == 0 )
3711 _tag_hypo = _tag_gene ;
3713 MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3714 if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3716 MESSAGE("Ajout de la categorie des hypotheses");
3717 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3718 PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3720 else { MESSAGE("La categorie des hypotheses existe deja."); }
3722 // Creation du resultat dans l'etude
3723 aResultSO = aStudyBuilder->NewObject(aSObject);
3724 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3726 return aResultSO._retn();
3728 //=============================================================================
3729 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3730 HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3732 MESSAGE("PublishYACSInStudy pour "<<theName);
3733 SALOMEDS::SObject_var aResultSO;
3735 // On recupere le module pere dans l etude
3736 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3737 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3738 if (theFatherHomard->_is_nil())
3740 MESSAGE("theFatherHomard->_is_nil()");
3741 return aResultSO._retn();
3743 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3744 if ( _tag_yacs == 0 )
3747 _tag_yacs = _tag_gene ;
3749 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3750 SALOMEDS::SObject_var aSObject;
3751 if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3753 MESSAGE("Ajout de la categorie des schemas YACS");
3754 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3755 PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3757 else { MESSAGE("La categorie des schemas YACS existe deja."); }
3759 // Creation du resultat dans l'etude
3760 aResultSO = aStudyBuilder->NewObject(aSObject);
3761 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3763 return aResultSO._retn();
3766 //=============================================================================
3767 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3768 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3770 MESSAGE("PublishZoneStudy pour "<<theName);
3771 SALOMEDS::SObject_var aResultSO;
3772 if (CORBA::is_nil(theObject))
3774 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3775 return aResultSO._retn();
3777 if (myStudy->_is_nil())
3779 MESSAGE("PublishZoneInStudy : myStudy->_is_nil()");
3780 return aResultSO._retn();
3782 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3783 if (theFatherHomard->_is_nil())
3785 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3786 return aResultSO._retn();
3789 // Caracteristique de la zone
3790 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[theName];
3791 CORBA::Long ZoneType = myZone->GetType();
3793 // On ajoute la categorie des zones dans l etude si necessaire
3794 if ( _tag_zone == 0 )
3797 _tag_zone = _tag_gene ;
3799 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3800 SALOMEDS::SObject_var aSObject;
3801 if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3803 MESSAGE("Ajout de la categorie des zones");
3804 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3805 PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3807 else { MESSAGE("La categorie des zones existe deja."); }
3809 aResultSO = aStudyBuilder->NewObject(aSObject);
3818 { icone = "boxdxy_2.png" ;
3822 { icone = "boxdxyz_2.png" ;
3830 { icone = "disk_2.png" ;
3834 { icone = "spherepoint_2.png" ;
3838 { icone = "cylinderpointvector_2.png" ;
3846 { icone = "diskwithhole_2.png" ;
3850 { icone = "pipe_2.png" ;
3854 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3856 return aResultSO._retn();
3858 //===========================================================================
3859 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3860 SALOMEDS::SObject_var aResultSO,
3861 const char* name, const char* comment, const char* icone, const char* ior)
3863 MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3864 // MESSAGE("icone = "<<icone);
3865 // MESSAGE("ior = "<<ior);
3866 SALOMEDS::GenericAttribute_var anAttr ;
3870 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3871 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3872 aNameAttrib->SetValue(name);
3875 // Ajout du commentaire
3876 if ( comment != NULL )
3878 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3879 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3880 aCommentAttrib->SetValue(comment);
3884 if ( icone != NULL )
3886 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3887 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3888 aPixmap->SetPixMap(icone);
3894 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3895 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3896 anIOR->SetValue(ior);
3900 //=====================================================================================
3901 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3903 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3905 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[CaseName];
3906 ASSERT(!CORBA::is_nil(myCase));
3907 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3908 ASSERT(!CORBA::is_nil(aCaseSO));
3910 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
3911 ASSERT(!CORBA::is_nil(myBoundary));
3912 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3913 ASSERT(!CORBA::is_nil(aBoundarySO));
3915 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
3917 aStudyBuilder->NewCommand();
3919 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3920 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3921 // aStudyBuilder->RemoveReference(aSubSO);
3923 aStudyBuilder->CommitCommand();
3926 //=====================================================================================
3927 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3929 MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3931 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
3932 ASSERT(!CORBA::is_nil(myYACS));
3933 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3934 ASSERT(!CORBA::is_nil(aYACSSO));
3936 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[CaseName];
3937 ASSERT(!CORBA::is_nil(myCase));
3938 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3939 ASSERT(!CORBA::is_nil(aCaseSO));
3941 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
3943 aStudyBuilder->NewCommand();
3945 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3946 aStudyBuilder->Addreference(aSubSO, aCaseSO);
3948 aStudyBuilder->CommitCommand();
3951 //=============================================================================
3952 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3953 // Option = 0 : fichier issu d'une importation
3954 // Option = 1 : fichier issu d'une execution HOMARD
3956 MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3957 if (CORBA::is_nil(myStudy))
3959 SALOME::ExceptionStruct es;
3960 es.type = SALOME::BAD_PARAM;
3961 es.text = "Invalid study context";
3962 throw SALOME::SALOME_Exception(es);
3966 // Le module SMESH est-il actif ?
3967 SALOMEDS::SObject_var aSmeshSO = myStudy->FindComponent("SMESH");
3969 if (!CORBA::is_nil(aSmeshSO))
3971 // On verifie que le fichier n est pas deja publie
3972 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aSmeshSO);
3973 for (; aIter->More(); aIter->Next())
3975 SALOMEDS::SObject_var aSO = aIter->Value();
3976 SALOMEDS::GenericAttribute_var aGAttr;
3977 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3979 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3980 CORBA::String_var value=anAttr->Value();
3981 if (strcmp((const char*)value,NomFich) == 0)
3983 MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3984 // Pour un fichier importe, on ne republie pas
3985 if ( Option == 0 ) { return; }
3986 // Pour un fichier calcule, on commence par faire la depublication
3989 MESSAGE ( "PublishResultInSmesh : depublication" );
3990 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3991 CORBA::String_var value2=anAttr2->Value();
3992 std::string MeshName = string(value2) ;
3993 MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3994 DeleteResultInSmesh(NomFich, MeshName) ;
4001 // On enregistre le fichier
4002 MESSAGE( "Enregistrement du fichier");
4003 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
4004 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
4005 ASSERT(!CORBA::is_nil(aSmeshEngine));
4006 aSmeshEngine->UpdateStudy();
4007 SMESH::DriverMED_ReadStatus theStatus;
4008 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
4010 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
4011 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
4012 for (int i = 0; i < mesMaillages->length(); i++)
4014 MESSAGE( ". Mise a jour des attributs du maillage");
4015 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
4016 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
4017 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4018 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
4019 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
4020 anAttr->SetValue(NomFich);
4021 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
4022 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
4024 if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
4025 else { icone = "mesh_tree_mesh.png" ; }
4026 anAttr2->SetPixMap( icone );
4030 //=============================================================================
4031 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
4033 MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
4034 if (CORBA::is_nil(myStudy))
4036 SALOME::ExceptionStruct es;
4037 es.type = SALOME::BAD_PARAM;
4038 es.text = "Invalid study context";
4039 throw SALOME::SALOME_Exception(es);
4043 // Le module SMESH est-il actif ?
4044 SALOMEDS::SObject_var aSmeshSO = myStudy->FindComponent("SMESH");
4046 if (CORBA::is_nil(aSmeshSO))
4050 // On verifie que le fichier est deja publie
4051 SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
4052 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aSmeshSO);
4053 for (; aIter->More(); aIter->Next())
4055 SALOMEDS::SObject_var aSO = aIter->Value();
4056 SALOMEDS::GenericAttribute_var aGAttr;
4057 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
4059 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
4060 CORBA::String_var value=anAttr->Value();
4061 if (strcmp((const char*)value,NomFich.c_str()) == 0)
4063 if (aSO->FindAttribute(aGAttr,"AttributeName"))
4065 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
4066 CORBA::String_var value2=anAttr2->Value();
4067 if (strcmp((const char*)value2,MeshName.c_str()) == 0)
4069 myBuilder->RemoveObjectWithChildren( aSO ) ;
4077 //=============================================================================
4078 void HOMARD_Gen_i::PublishMeshIterInSmesh(const char* NomIter)
4080 MESSAGE( "PublishMeshIterInSmesh " << NomIter);
4081 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIter];
4083 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
4084 if (CORBA::is_nil(myIteration))
4086 SALOME::ExceptionStruct es;
4087 es.type = SALOME::BAD_PARAM;
4088 es.text = "Invalid iterationStudy Object";
4089 throw SALOME::SALOME_Exception(es);
4092 const char* MeshFile = myIteration->GetMeshFile() ;
4093 const char* MeshName = myIteration->GetMeshName() ;
4094 CORBA::Long Option = -1 ;
4095 int etat = myIteration->GetState();
4096 // Iteration initiale
4097 if ( etat <= 0 ) { Option = 0 ; }
4098 // ou iteration calculee
4099 else if ( etat == 2 ) { Option = 1 ; }
4100 // Publication effective apres menage eventuel
4103 DeleteResultInSmesh(MeshFile, MeshName) ;
4104 PublishResultInSmesh(MeshFile, Option) ;
4108 //=============================================================================
4109 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
4111 // MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
4112 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIter];
4114 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
4115 if (CORBA::is_nil(myIteration))
4117 SALOME::ExceptionStruct es;
4118 es.type = SALOME::BAD_PARAM;
4119 es.text = "Invalid iterationStudy Object";
4120 throw SALOME::SALOME_Exception(es);
4124 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4126 aStudyBuilder->NewCommand();
4128 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
4129 // Pour les fichiers med, on affiche une icone de maillage
4130 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
4131 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
4133 std::string ior = " " ;
4134 if ( Commentaire[0] == 'M' )
4135 { icone = "med.png" ; }
4137 { icone = "texte_2.png" ; }
4138 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
4140 aStudyBuilder->CommitCommand();
4143 //=============================================================================
4144 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
4146 // MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
4147 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
4149 SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
4150 if (CORBA::is_nil(myYACS))
4152 SALOME::ExceptionStruct es;
4153 es.type = SALOME::BAD_PARAM;
4154 es.text = "Invalid YACSStudy Object";
4155 throw SALOME::SALOME_Exception(es);
4159 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4161 aStudyBuilder->NewCommand();
4163 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
4164 std::string icone = "texte_2.png" ;
4165 std::string ior = " " ;
4166 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
4168 aStudyBuilder->CommitCommand();
4171 //=============================================================================
4172 //=============================================================================
4174 //=============================================================================
4175 //=============================================================================
4176 //=============================================================================
4177 // Creation d'un schema YACS
4178 // nomCas : nom du cas a traiter
4179 // FileName : nom du fichier contenant le script de lancement du calcul
4180 // DirName : le répertoire de lancement des calculs du schéma
4181 //=============================================================================
4182 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
4184 MESSAGE ( "CreateYACSSchema : Schema YACS " << nomYACS );
4185 MESSAGE ( ". nomCas : " << nomCas);
4186 MESSAGE ( ". ScriptFile : " << ScriptFile);
4187 MESSAGE ( ". DirName : " << DirName);
4188 MESSAGE ( ". MeshFile : " << MeshFile);
4190 // A. Controle du nom :
4191 if ((myStudyContext._mesYACSs).find(nomYACS) != (myStudyContext._mesYACSs).end())
4193 SALOME::ExceptionStruct es;
4194 es.type = SALOME::BAD_PARAM;
4195 es.text = "This schema YACS has already been defined.";
4196 throw SALOME::SALOME_Exception(es);
4200 // B. Creation de l'objet
4201 HOMARD::HOMARD_YACS_var myYACS = newYACS();
4202 if (CORBA::is_nil(myYACS))
4204 SALOME::ExceptionStruct es;
4205 es.type = SALOME::BAD_PARAM;
4206 es.text = "Unable to create the schema YACS";
4207 throw SALOME::SALOME_Exception(es);
4210 myYACS->SetName( nomYACS ) ;
4212 // C. Enregistrement
4213 myStudyContext._mesYACSs[nomYACS] = myYACS;
4215 SALOMEDS::SObject_var aSO;
4216 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myYACS, nomYACS);
4218 PublishCaseUnderYACS(nomYACS, nomCas);
4220 // D. Caracterisation
4222 myYACS->SetDirName( DirName ) ;
4223 myYACS->SetMeshFile( MeshFile ) ;
4224 myYACS->SetScriptFile( ScriptFile ) ;
4225 myYACS->SetCaseName( nomCas ) ;
4228 // D.2.1. Type constant
4229 myYACS->SetType( 1 ) ;
4230 // D.2.2. Convergence
4231 defaut_i = GetYACSMaxIter() ;
4232 myYACS->SetMaxIter( defaut_i ) ;
4233 defaut_i = GetYACSMaxNode() ;
4234 myYACS->SetMaxNode( defaut_i ) ;
4235 defaut_i = GetYACSMaxElem() ;
4236 myYACS->SetMaxElem( defaut_i ) ;
4237 // D.3. Fichier de sauvegarde dans le répertoire du cas
4238 HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
4239 std::string dirnamecase = caseyacs->GetDirName() ;
4240 std::string XMLFile ;
4241 XMLFile = dirnamecase + "/schema.xml" ;
4242 myYACS->SetXMLFile( XMLFile.c_str() ) ;
4244 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
4246 //=============================================================================
4247 // Ecriture d'un schema YACS
4248 //=============================================================================
4249 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
4251 MESSAGE ( "YACSWrite : Ecriture de " << nomYACS );
4252 // Le répertoire du cas
4253 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
4254 ASSERT(!CORBA::is_nil(myYACS));
4255 // Le nom du fichier du schema
4256 std::string XMLFile ;
4257 XMLFile = myYACS->GetXMLFile() ;
4259 int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
4263 //=============================================================================
4264 // Ecriture d'un schema YACS sur un fichier donne
4265 //=============================================================================
4266 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
4268 MESSAGE ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
4275 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
4276 ASSERT(!CORBA::is_nil(myYACS));
4277 // B.2. Les caracteristiques
4278 std::string DirName = myYACS->GetDirName() ;
4279 std::string MeshFile = myYACS->GetMeshFile() ;
4280 std::string ScriptFile = myYACS->GetScriptFile() ;
4281 // B.3. Les caracteristiques de convergence
4282 int MaxIter = myYACS->GetMaxIter() ;
4283 int MaxNode = myYACS->GetMaxNode() ;
4284 int MaxElem = myYACS->GetMaxElem() ;
4288 const char* nomCas = myYACS->GetCaseName();
4289 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
4290 ASSERT(!CORBA::is_nil(myCase));
4291 // C.2. Les instructions python associees au cas
4292 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4293 std::string pythonCas = dumpCorbaCase.in();
4294 MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
4296 // D. Les iterations
4297 // D.1. L'iteration initiale
4298 HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
4299 std::string Iter0Name = myCase->GetIter0Name() ;
4300 MESSAGE (". Iter0Name = " << Iter0Name);
4301 std::string MeshName = Iter0->GetMeshName();
4302 MESSAGE (". MeshName = " << MeshName);
4303 // D.2. L'iteration numero 1
4304 HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
4305 int numberOfIter = maListe->length();
4306 if ( numberOfIter > 1 )
4308 MESSAGE (". numberOfIter = " << numberOfIter);
4309 SALOME::ExceptionStruct es ;
4310 es.type = SALOME::BAD_PARAM;
4311 std::string text = "Une seule iteration est permise." ;
4312 es.text = CORBA::string_dup(text.c_str());
4313 throw SALOME::SALOME_Exception(es);
4316 std::string Iter1Name = std::string((*maListe)[0]);
4317 MESSAGE ("... Iter1Name = " << Iter1Name);
4318 HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
4319 // D.3. Les instructions python associees a l'iteration
4320 CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
4321 std::string pythonIter = dumpCorbaIter.in();
4322 MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
4324 // E. L'hypothese pour passer de l'iteration initiale a la suivante
4325 // E.1. La structure
4326 std::string nomHypo = Iter1->GetHypoName();
4327 MESSAGE (". nomHypo = " << nomHypo);
4328 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
4329 ASSERT(!CORBA::is_nil(myHypo));
4330 // E.2. Les caracteristiques de l'adaptation
4331 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
4332 ASSERT(ListTypes->length() == 3);
4333 int TypeAdap = (*ListTypes)[0];
4334 // int TypeRaff = (*ListTypes)[1];
4335 // int TypeDera = (*ListTypes)[2];
4336 // E.3. Les instructions python associees a l'hypothese
4337 CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
4338 std::string pythonHypo = dumpCorbaHypo.in();
4339 MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
4341 // F. Le fichier du schema de reference
4342 // HOMARD_ROOT_DIR : répertoire ou se trouve le module HOMARD
4343 std::string XMLFile_base ;
4344 if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
4347 SALOME::ExceptionStruct es ;
4348 es.type = SALOME::BAD_PARAM;
4349 std::string text = "HOMARD_ROOT_DIR est inconnu." ;
4350 es.text = CORBA::string_dup(text.c_str());
4351 throw SALOME::SALOME_Exception(es);
4354 XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
4356 MESSAGE("XMLFile_base ="<<XMLFile_base);
4358 // G. Lecture du schema de reference et insertion des données propres au fil de la rencontre des mots-cles
4359 YACSDriver* myDriver = new YACSDriver(XMLFile, DirName, _LangueShort);
4360 std::ifstream fichier( XMLFile_base.c_str() );
4361 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
4363 // G.1. Lecture du schema de reference et insertion des données propres au fil de la rencontre des mots-cles
4364 std::string ligne; // variable contenant chaque ligne lue
4365 std::string mot_cle;
4366 while ( std::getline( fichier, ligne ) )
4368 // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
4369 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
4370 ligne_bis >> mot_cle ;
4371 // G.1.2. Le maillage initial
4372 if ( mot_cle == "DataInit_MeshFile" )
4373 { myDriver->Texte_DataInit_MeshFile(MeshFile); }
4374 // G.1.3. Le script de lancement
4375 else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
4376 { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
4377 // G.1.4. Les options du cas
4378 else if ( mot_cle == "Iter_1_Case_Options" )
4379 { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
4380 // G.1.5. Execution de HOMARD : le répertoire du cas
4381 else if ( mot_cle == "HOMARD_Exec_DirName" )
4382 { myDriver->Texte_HOMARD_Exec_DirName(); }
4383 // G.1.6. Execution de HOMARD : le nom du maillage
4384 else if ( mot_cle == "HOMARD_Exec_MeshName" )
4386 myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
4388 if ( _LangueShort == "fr" ) { node = "Boucle_de_convergence.Alternance_Calcul_HOMARD" ; }
4389 else { node = "Convergence_Loop.Alternation_Computation_HOMARD" ; }
4390 node += ".Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
4391 myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
4393 // G.1.7. Execution de HOMARD : les options de l'hypothese
4394 else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
4395 { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ; }
4396 // G.1.8. Execution de HOMARD : les options de l'iteration
4397 else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
4398 { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ; }
4399 // G.1.9. a. Creation eventuelles des zones et frontieres
4401 else if ( mot_cle == "Iter_1" )
4403 std::string texte_control = "" ;
4404 if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
4405 texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
4406 texte_control += myDriver->Texte_Iter_1_control() ;
4407 myDriver->TexteAdd(texte_control);
4409 // G.1.10. Les tests de convergence
4410 else if ( mot_cle == "Analyse_Test_Convergence" )
4411 { myDriver->TexteAnalyse_Test_Convergence(MaxIter, MaxNode, MaxElem); }
4412 // G.1.11. Les parametres
4413 else if ( mot_cle == "PARAMETRES" )
4414 { myDriver->TexteAddParametres(); }
4415 // G.1.n. La ligne est recopiee telle quelle
4416 else { myDriver->TexteAdd(ligne); }
4418 // G.2. Ecriture du texte dans le fichier
4420 { myDriver->CreeFichier(); }
4424 SALOME::ExceptionStruct es;
4425 es.type = SALOME::BAD_PARAM;
4426 std::string text = "The reference file for the YACS schema cannot be read." ;
4427 es.text = CORBA::string_dup(text.c_str());
4428 throw SALOME::SALOME_Exception(es);
4433 // H. Publication du fichier dans l'arbre
4435 std::string Commentaire = "xml" ;
4436 PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
4440 //=============================================================================
4441 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
4442 //=============================================================================
4443 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
4445 MESSAGE ( "YACSDriverTexteZone" );
4446 // A. Les zones associees a cette hypothese
4447 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
4448 int numberOfZonesx2 = ListZone->length();
4450 // B. Parcours des zones
4451 std::string texte_control ;
4452 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
4454 // 1. Reperage de la zone
4455 std::string ZoneName = std::string((*ListZone)[iaux]);
4456 MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
4457 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
4458 ASSERT(!CORBA::is_nil(myZone));
4459 // 2. Les instructions python associees a la zone
4460 // La premiere ligne est un commentaire a eliminer
4461 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4462 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4463 std::string pythonStructure_0 = dumpCorbaZone.in();
4464 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4465 std::istringstream tout (pythonStructure_0) ;
4467 std::string pythonStructure ;
4468 while ( std::getline( tout, ligne ) )
4469 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4470 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4471 // 3. Decodage du nom du service
4472 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4473 MESSAGE ( "... methode = " << methode);
4474 // 4. Mise en place des instructions
4475 int ZoneType = myZone->GetType();
4476 MESSAGE ( "... ZoneType = " << ZoneType);
4477 std::string texte_control_0 ;
4478 texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
4479 texte_control += texte_control_0 ;
4484 return texte_control ;
4486 //=============================================================================
4487 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4488 //=============================================================================
4489 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4491 MESSAGE ( "YACSDriverTexteBoundary" );
4492 // A. Les frontieres associees au cas
4493 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4494 int numberOfitems = ListBoundaryGroupType->length();
4496 // B. Parcours des frontieres
4497 std::string texte_control ;
4498 std::list<std::string> ListeBoundaryTraitees ;
4499 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4501 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4502 MESSAGE ( "... BoundaryName = " << BoundaryName);
4503 // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4504 // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4506 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4507 while (it != ListeBoundaryTraitees.end())
4509 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4510 if ( BoundaryName == *it ) { A_faire = 0 ; }
4515 // 1. Caracteristiques de la frontiere
4516 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
4517 ASSERT(!CORBA::is_nil(myBoundary));
4518 // 2. Les instructions python associees a la frontiere
4519 // La premiere ligne est un commentaire a eliminer
4520 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4521 CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4522 std::string pythonStructure_0 = dumpCorbaBoundary.in();
4523 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4524 std::istringstream tout (pythonStructure_0) ;
4526 std::string pythonStructure ;
4527 while ( std::getline( tout, ligne ) )
4528 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4529 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4530 // 3. Decodage du nom du service
4531 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4532 MESSAGE ( "... methode = " << methode);
4533 // 4. Mise en place des instructions
4534 int BoundaryType = myBoundary->GetType();
4535 MESSAGE ( "... BoundaryType = " << BoundaryType);
4536 const char* MeshName ;
4537 const char* DataFile ;
4538 if (BoundaryType == -1)
4540 DataFile = myBoundary->GetDataFile() ;
4541 MESSAGE ( ". CAOFile = " << DataFile );
4543 else if (BoundaryType == 0)
4545 MeshName = myBoundary->GetMeshName() ;
4546 MESSAGE ( ". MeshName = " << MeshName );
4547 DataFile = myBoundary->GetDataFile() ;
4548 MESSAGE ( ". MeshFile = " << DataFile );
4550 std::string texte_control_0 ;
4551 texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName, MeshName, DataFile );
4552 texte_control += texte_control_0 ;
4553 // 5. Memorisation du traitement
4554 ListeBoundaryTraitees.push_back( BoundaryName );
4558 return texte_control ;
4561 //=============================================================================
4562 //=============================================================================
4563 // Next functions are inherited from SALOMEDS::Driver interface
4564 //=============================================================================
4565 //=============================================================================
4566 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4568 CORBA::Boolean isMultiFile)
4570 MESSAGE ("Save for theURL = "<< theURL);
4571 SALOMEDS::TMPFile_var aStreamFile;
4573 // get temporary directory name
4574 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4576 StudyContext& context = myStudyContext;
4578 // HOMARD data file name
4579 std::string aFileName = "";
4581 aFileName = SALOMEDS_Tool::GetNameFromPath(Kernel_Utils::encode(myStudy->URL()));
4582 aFileName += "_HOMARD.dat";
4584 // initialize sequence of file names
4585 SALOMEDS_Tool::ListOfFiles aFileSeq;
4586 aFileSeq.reserve(1);
4587 aFileSeq.push_back(CORBA::string_dup(aFileName.c_str())) ;
4589 // get full path to the data file
4590 aFileName = tmpDir + aFileName;
4594 std::ofstream f(aFileName.c_str());
4596 // clear temporary id map
4597 context._idmap.clear();
4602 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4603 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4604 HOMARD::HOMARD_Cas_var aCas = it_case->second;
4605 PortableServer::ServantBase_var aServant = GetServant(aCas);
4606 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4608 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4609 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4613 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4614 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4615 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4616 PortableServer::ServantBase_var aServant = GetServant(aZone);
4617 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4619 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4620 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4623 // -> save hypotheses
4624 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4625 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4626 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4627 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4628 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4630 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4631 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4634 // -> save iterations
4635 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4636 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4637 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4638 PortableServer::ServantBase_var aServant = GetServant(aIter);
4639 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4641 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4642 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4645 // -> save boundaries
4646 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4647 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4648 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4649 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4650 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4651 if (aBoundaryServant) {
4652 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4653 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4657 MESSAGE ("close file");
4660 // put temporary files to the stream
4661 MESSAGE ("put temporary files to the stream");
4662 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq, isMultiFile);
4664 // remove temporary files
4665 MESSAGE ("remove temporary files");
4666 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq, true);
4668 // return data stream
4669 MESSAGE ("return data stream");
4670 return aStreamFile._retn();
4673 //===========================================================================
4674 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4676 CORBA::Boolean isMultiFile)
4678 // No specific ASCII persistence
4679 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4680 return aStreamFile._retn();
4683 //===========================================================================
4684 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4685 const SALOMEDS::TMPFile& theStream,
4687 CORBA::Boolean isMultiFile)
4689 MESSAGE ("Load pour theURL = "<< theURL);
4691 // set current study
4692 if (myStudy->_is_nil())
4695 // get temporary directory name
4696 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4698 // Convert the stream into sequence of files to process
4699 SALOMEDS_Tool::ListOfFiles aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4702 // HOMARD data file name
4703 std::string aFileName = "";
4705 aFileName = SALOMEDS_Tool::GetNameFromPath(Kernel_Utils::encode(myStudy->URL()));
4706 aFileName = tmpDir + aFileName + "_HOMARD.dat";
4708 StudyContext& context = myStudyContext;
4712 std::ifstream f(aFileName.c_str());
4715 context._mesCas.clear();
4716 context._mesHypotheses.clear();
4717 context._mesIterations.clear();
4718 context._mesZones.clear();
4719 context._mesBoundarys.clear();
4720 context._idmap.clear();
4726 std::getline(f, line);
4727 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4728 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4729 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4730 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4731 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4732 std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4733 if (line.substr(0, bounSignature.size()) == bounSignature) {
4734 // re-create boundary
4735 MESSAGE ("Recreation de la frontiere" );
4736 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4737 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4738 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4739 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4740 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4741 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4744 else if (line.substr(0, caseSignature.size()) == caseSignature) {
4746 MESSAGE ("Recreation du cas" );
4747 HOMARD::HOMARD_Cas_var aCase = newCase();
4748 PortableServer::ServantBase_var aServant = GetServant(aCase);
4749 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4750 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4751 context._mesCas[aCase->GetName()] = aCase;
4752 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4755 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4756 // re-create hypothesis
4757 MESSAGE ("Recreation de l hypothese" );
4758 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4759 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4760 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4761 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4762 context._mesHypotheses[aHypo->GetName()] = aHypo;
4763 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4766 else if (line.substr(0, iterSignature.size()) == iterSignature) {
4767 // re-create iteration
4768 MESSAGE ("Recreation de l'iteration" );
4769 HOMARD::HOMARD_Iteration_var aIter = newIteration();
4770 PortableServer::ServantBase_var aServant = GetServant(aIter);
4771 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4772 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4773 context._mesIterations[aIter->GetName()] = aIter;
4774 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4777 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4778 MESSAGE ("Recreation de la zone" );
4780 HOMARD::HOMARD_Zone_var aZone = newZone();
4781 PortableServer::ServantBase_var aServant = GetServant(aZone);
4782 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4783 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4784 context._mesZones[aZone->GetName()] = aZone;
4785 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4788 else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4789 MESSAGE ("Recreation du schema YACS" );
4791 HOMARD::HOMARD_YACS_var aYACS = newYACS();
4792 PortableServer::ServantBase_var aServant = GetServant(aYACS);
4793 HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4794 if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4795 context._mesYACSs[aYACS->GetName()] = aYACS;
4796 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4805 // Remove temporary files created from the stream
4807 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq, true);
4812 //===========================================================================
4813 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4814 const SALOMEDS::TMPFile& theStream,
4816 CORBA::Boolean isMultiFile)
4818 // No specific ASCII persistence
4819 return Load(theComponent, theStream, theURL, isMultiFile);
4822 //===========================================================================
4823 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4827 //===========================================================================
4828 char* HOMARD_Gen_i::ComponentDataType()
4830 return CORBA::string_dup("HOMARD");
4833 //===========================================================================
4834 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4835 const char* IORString,
4836 CORBA::Boolean isMultiFile,
4837 CORBA::Boolean isASCII)
4839 CORBA::String_var aString("");
4840 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4841 StudyContext context = myStudyContext;
4842 CORBA::Object_var anObj = _orb->string_to_object(IORString);
4843 if (!CORBA::is_nil(anObj)) {
4844 PortableServer::ServantBase_var aServant = GetServant(anObj);
4845 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4847 std::map<int, PortableServer::ServantBase*>::const_iterator it;
4848 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4849 if (it->second == aStorable) {
4850 std::stringstream os;
4852 aString = CORBA::string_dup(os.str().c_str());
4858 return aString._retn();
4861 //===========================================================================
4862 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4863 const char* aLocalPersistentID,
4864 CORBA::Boolean isMultiFile,
4865 CORBA::Boolean isASCII)
4867 CORBA::String_var aString("");
4868 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4869 StudyContext context = myStudyContext;
4870 int id = atoi(aLocalPersistentID);
4871 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4872 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4873 if (!CORBA::is_nil(object)) {
4874 aString = _orb->object_to_string(object);
4878 return aString._retn();
4881 //===========================================================================
4882 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4884 if(CORBA::is_nil(myStudy))
4887 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4888 if(!aCas->_is_nil())
4891 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4892 if(!aHypo->_is_nil())
4895 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4896 if(!aZone->_is_nil())
4899 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4900 if(!aBoundary->_is_nil())
4903 /* Iteration is not published directly
4904 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4905 if(!aIter->_is_nil())
4911 //===========================================================================
4912 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4914 // No Copy/Paste support
4918 //===========================================================================
4919 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4920 CORBA::Long& theObjectID)
4922 // No Copy/Paste support
4923 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4924 return aStreamFile._retn();
4927 //===========================================================================
4928 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
4929 CORBA::Long theObjectID)
4931 // No Copy/Paste support
4935 //===========================================================================
4936 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4937 CORBA::Long theObjectID,
4938 SALOMEDS::SObject_ptr theSObject)
4940 // No Copy/Paste support
4941 SALOMEDS::SObject_var aResultSO;
4942 return aResultSO._retn();
4945 //===========================================================================
4946 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4948 PortableServer::Servant aServant = 0;
4949 if (!CORBA::is_nil(theObject)) {
4951 aServant = _poa->reference_to_servant(theObject);
4959 //==========================================================================
4960 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Boolean isPublished,
4961 CORBA::Boolean isMultiFile,
4962 CORBA::Boolean& isValidScript)
4964 MESSAGE ("Entree dans DumpPython");
4967 SALOMEDS::SObject_var aSO = myStudy->FindComponent("HOMARD");
4968 if(CORBA::is_nil(aSO))
4969 return new Engines::TMPFile(0);
4971 std::string aScript = "\"\"\"\n";
4972 aScript += "Python script for HOMARD\n";
4973 aScript += "Copyright 1996, 2011, 2015 EDF\n";
4974 aScript += "\"\"\"\n";
4975 aScript += "__revision__ = \"V1.2\"\n";
4976 aScript += "import HOMARD\n";
4978 aScript += "import salome\n";
4979 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4980 aScript += "\thomard.UpdateStudy()\n";
4981 MESSAGE (". Au depart \n"<<aScript);
4984 if (myStudyContext._mesBoundarys.size() > 0)
4986 MESSAGE (". Ecritures des frontieres");
4987 aScript += "#\n# Creation of the boundaries";
4988 aScript += "\n# ==========================";
4990 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4991 for (it_boundary = myStudyContext._mesBoundarys.begin();
4992 it_boundary != myStudyContext._mesBoundarys.end(); ++it_boundary)
4994 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4995 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4996 std::string dumpBoundary = dumpCorbaBoundary.in();
4997 MESSAGE (dumpBoundary<<"\n");
4998 aScript += dumpBoundary;
5002 if (myStudyContext._mesZones.size() > 0)
5004 MESSAGE (". Ecritures des zones");
5005 aScript += "#\n# Creation of the zones";
5006 aScript += "\n# =====================";
5008 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
5009 for ( it_zone = myStudyContext._mesZones.begin();
5010 it_zone != myStudyContext._mesZones.end(); ++it_zone)
5012 HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
5013 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
5014 std::string dumpZone = dumpCorbaZone.in();
5015 MESSAGE (dumpZone<<"\n");
5016 aScript += dumpZone;
5020 if (myStudyContext._mesHypotheses.size() > 0)
5022 MESSAGE (". Ecritures des hypotheses");
5023 aScript += "#\n# Creation of the hypotheses";
5024 aScript += "\n# ==========================";
5026 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
5027 for ( it_hypo = myStudyContext._mesHypotheses.begin();
5028 it_hypo != myStudyContext._mesHypotheses.end(); it_hypo++)
5030 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
5031 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
5032 std::string dumpHypo = dumpCorbaHypo.in();
5033 MESSAGE (dumpHypo<<"\n");
5034 aScript += dumpHypo;
5038 if (myStudyContext._mesCas.size() > 0)
5040 MESSAGE (". Ecritures des cas");
5041 aScript += "#\n# Creation of the cases";
5042 aScript += "\n# =====================";
5044 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
5045 for (it_cas = myStudyContext._mesCas.begin();
5046 it_cas != myStudyContext._mesCas.end(); it_cas++)
5048 std::string nomCas = (*it_cas).first;
5049 std::string dumpCas = std::string("\n# Creation of the case ") ;
5050 dumpCas += nomCas + std::string("\n");
5051 dumpCas += std::string("\t") + nomCas;
5052 dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
5054 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
5055 CORBA::String_var cIter0= myCase->GetIter0Name();
5056 std::string iter0 = cIter0.in();
5058 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[iter0];
5059 CORBA::String_var cMesh0= myIteration->GetMeshFile();
5060 std::string mesh0 = cMesh0.in();
5061 CORBA::String_var cMeshName0= myIteration->GetMeshName();
5062 std::string meshName0 = cMeshName0.in();
5063 dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
5064 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
5065 std::string dumpCas2= dumpCorbaCase.in();
5067 MESSAGE (dumpCas<<dumpCas2<<"\n");
5068 aScript += dumpCas + dumpCas2;
5072 if (myStudyContext._mesIterations.size() > 0)
5074 MESSAGE (". Ecritures des iterations");
5075 aScript += "#\n# Creation of the iterations" ;
5076 aScript += "\n# ==========================";
5078 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
5079 for (it_iter = myStudyContext._mesIterations.begin();
5080 it_iter != myStudyContext._mesIterations.end(); ++it_iter)
5082 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
5083 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
5084 std::string dumpIter = dumpCorbaIter.in();
5085 MESSAGE (dumpIter<<"\n");
5086 aScript += dumpIter;
5090 if (myStudyContext._mesYACSs.size() > 0)
5092 MESSAGE (". Ecritures des schemas YACS");
5093 aScript += "#\n# Creation of the schemas YACS";
5094 aScript += "\n# ============================";
5096 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
5097 for ( it_yacs = myStudyContext._mesYACSs.begin();
5098 it_yacs != myStudyContext._mesYACSs.end(); ++it_yacs)
5100 HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
5101 CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
5102 std::string dumpYACS = dumpCorbaYACS.in();
5103 MESSAGE (dumpYACS<<"\n");
5104 aScript += dumpYACS;
5107 MESSAGE (". Ecritures finales");
5109 aScript += "\n\tpass";
5112 if( !isMultiFile ) // remove unnecessary tabulation
5113 aScript = RemoveTabulation( aScript );
5115 // MESSAGE ("A ecrire \n"<<aScript);
5116 const size_t aLen = strlen(aScript.c_str());
5117 char* aBuffer = new char[aLen+1];
5118 strcpy(aBuffer, aScript.c_str());
5120 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
5121 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
5123 MESSAGE ("Sortie de DumpPython");
5124 return aStreamFile._retn();
5128 //=============================================================================
5129 //=============================================================================
5131 //=============================================================================
5132 //=============================================================================
5133 void HOMARD_Gen_i::IsValidStudy( )
5135 // MESSAGE( "IsValidStudy" );
5136 if (CORBA::is_nil(myStudy))
5138 SALOME::ExceptionStruct es;
5139 es.type = SALOME::BAD_PARAM;
5140 es.text = "Invalid study context";
5141 throw SALOME::SALOME_Exception(es);
5146 //=============================================================================
5147 char* HOMARD_Gen_i::VerifieDir(const char* nomDir)
5149 std::string casename = std::string("") ;
5150 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
5151 for (it = myStudyContext._mesCas.begin();
5152 it != myStudyContext._mesCas.end(); it++)
5154 if (std::string(nomDir) == std::string(it->second->GetDirName()))
5156 casename = std::string(it->second->GetName()) ;
5160 return CORBA::string_dup( casename.c_str() );
5162 /*//=============================================================================
5163 void SALOMEException( std::string message )
5165 SALOME::ExceptionStruct es;
5166 es.type = SALOME::BAD_PARAM;
5168 throw SALOME::SALOME_Exception(es);
5171 //=============================================================================
5172 char* HOMARD_Gen_i::getVersion()
5174 #if HOMARD_DEVELOPMENT
5175 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
5177 return CORBA::string_dup(HOMARD_VERSION_STR);
5180 //===============================================================================
5181 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un caractere
5182 // ligne : la ligne a manipuler
5183 // caractere : le caractere a reperer
5184 // option : 0 : la chaine avant la premiere apparition du caractere
5185 // 1 : la chaine apres la premiere apparition du caractere
5186 // 2 : la chaine avant la derniere apparition du caractere
5187 // 3 : la chaine apres la derniere apparition du caractere
5188 // Si le caractere est absent, on retourne la chaine totale
5189 //===============================================================================
5190 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string caractere, int option )
5192 // MESSAGE("GetStringInTexte, recherche de '"<<caractere<<"' dans '"<<ligne<<"'"<<", option = "<<option);
5194 std::string chaine = ligne ;
5196 if ( option < 2 ) { position = ligne.find_first_of( caractere ) ; }
5197 else { position = ligne.find_last_of( caractere ) ; }
5198 // MESSAGE("position = "<<position);
5199 // MESSAGE("a = "<<ligne.substr( 0, position ).c_str());
5200 // MESSAGE("b = "<<ligne.substr( position+1 ).c_str());
5202 if ( position != std::string::npos )
5204 if ( ( option == 0 ) || ( option == 2 ) ) { chaine = ligne.substr( 0, position ) ; }
5205 else { chaine = ligne.substr( position+1 ) ; }
5210 //=============================================================================
5211 //=============================================================================
5212 // Gestion des preferences
5213 //=============================================================================
5214 //=============================================================================
5215 // Decodage du fichier d'arcihvage des preferences
5217 void HOMARD_Gen_i::SetPreferences( )
5219 MESSAGE ( "SetPreferences" );
5221 std::string ligne, mot_cle, salome_version ;
5224 // A. Les valeurs par defaut ; elles doivent etre coherentes
5225 std::string LanguageShort = "en" ;
5226 int PublisMeshIN = 0 ;
5227 int PublisMeshOUT = 0 ;
5228 int YACSMaxIter = 0 ;
5229 int YACSMaxNode = 0 ;
5230 int YACSMaxElem = 0 ;
5231 std::string YACSTypeTestchaine = "None" ;
5233 // B. La version de salome
5234 // Cela se presente sous la forme :
5235 // [SALOME KERNEL] : 7.3.0
5237 File = getenv("KERNEL_ROOT_DIR") ;
5238 File += "/bin/salome/VERSION" ;
5239 MESSAGE ( "File = "<<File ) ;
5240 std::ifstream fichier0( File.c_str() ) ;
5241 if ( fichier0 ) // ce test échoue si le fichier n'est pas ouvert
5243 std::string ligne; // variable contenant chaque ligne lue
5244 while ( std::getline( fichier0, ligne ) )
5246 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5247 ligne_bis >> mot_cle ;
5248 if ( mot_cle == "[SALOME" )
5250 salome_version = GetStringInTexte ( ligne, " ", 3 ) ;
5251 // MESSAGE ( "salome_version = "<<salome_version<<"|||");
5256 else { ok = false ; }
5258 // B. Decodage du fichier de preferences
5261 std::string PrefFile ;
5262 PrefFile = Kernel_Utils::HomePath() ;
5263 PrefFile += "/.config/salome/SalomeApprc." + salome_version ;
5264 MESSAGE ( "PrefFile = "<<PrefFile ) ;
5266 std::ifstream fichier( PrefFile.c_str() );
5267 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
5269 bool section_langue = false ;
5270 bool section_homard = false ;
5271 while ( std::getline( fichier, ligne ) )
5273 std::string chaine ;
5274 // 1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
5275 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5276 ligne_bis >> mot_cle ;
5279 // 2.1. Debut d'une section
5280 // MESSAGE(mot_cle);
5281 if ( mot_cle == "<section" )
5282 { /*MESSAGE ( "Debut de la section : "<< ligne);*/
5283 ligne_bis >> mot_cle ;
5284 chaine = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5285 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5286 if ( chaine == "language" ) { section_langue = true ; }
5287 if ( chaine == "HOMARD" ) { section_homard = true ; }
5288 // MESSAGE ( "section_langue = "<<section_langue<<", section_homard = "<<section_homard);
5290 // 2.2. Fin d'une section
5291 else if ( mot_cle == "</section>" )
5292 { /*MESSAGE ( "Fin de la section : "<< ligne<<", section_langue = "<<section_langue<<", section_homard = "<<section_homard);*/
5293 section_langue = false ;
5294 section_homard = false ; }
5298 else if ( section_langue || section_homard )
5299 { MESSAGE ( "a decoder : "<< ligne);
5300 // La valeur : entre les deux premieres quotes
5301 chaine = GetStringInTexte ( ligne, "\"", 1 ) ;
5302 // MESSAGE("chaine 1 = |"<<chaine<<"|");
5303 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5304 // MESSAGE("chaine = |"<<chaine<<"|");
5305 // Le mot_cle : entre les deux dernieres quotes
5306 std::string chaine2 = GetStringInTexte ( ligne, "\"", 2 ) ;
5307 // MESSAGE("chaine2 1 = |"<<chaine2<<"|");
5308 chaine2 = GetStringInTexte ( chaine2, "\"", 3 ) ;
5309 // MESSAGE("chaine2 = |"<<chaine2<<"|");
5311 if ( section_langue )
5312 { if ( chaine2 == "language" ) { LanguageShort = chaine ; } }
5314 if ( section_homard )
5316 std::istringstream chainebis( chaine ) ;
5317 // 3.2.1. Les publications
5318 if ( chaine2 == "publish_mesh_in" ) { chainebis >> PublisMeshIN ; }
5319 if ( chaine2 == "publish_mesh_out" ) { chainebis >> PublisMeshOUT ; }
5320 // 3.2.2. Les maximum pour YACS
5321 if ( chaine2 == "yacs_max_iter" ) { chainebis >> YACSMaxIter ; }
5322 if ( chaine2 == "yacs_max_node" ) { chainebis >> YACSMaxNode ; }
5323 if ( chaine2 == "yacs_max_elem" ) { chainebis >> YACSMaxElem ; }
5324 if ( chaine2 == "yacs_type_test" ) { YACSTypeTestchaine = chaine ; }
5331 // C. Enregistrements
5332 MESSAGE ("Enregistrement de LanguageShort = " << LanguageShort );
5333 SetLanguageShort( LanguageShort.c_str() ) ;
5335 MESSAGE ("Enregistrement de PublisMeshIN = " << PublisMeshIN<<", PublisMeshOUT = "<< PublisMeshOUT);
5336 SetPublisMesh(PublisMeshIN, PublisMeshOUT) ;
5338 MESSAGE ("Enregistrement de YACSMaxIter = " << YACSMaxIter<<", YACSMaxNode = "<< YACSMaxNode<<", YACSMaxElem = "<< YACSMaxElem);
5339 SetYACSMaximum(YACSMaxIter, YACSMaxNode, YACSMaxElem) ;
5341 MESSAGE ("Enregistrement de TypeTest = " << YACSTypeTestchaine.c_str() );
5343 if ( ( YACSTypeTestchaine == "VTest > VRef" ) || ( YACSTypeTestchaine == "VTest > VRef" ) ) { YACSTypeTest = 1 ; }
5344 else if ( ( YACSTypeTestchaine == "VTest < VRef" ) || ( YACSTypeTestchaine == "VTest < VRef" ) ) { YACSTypeTest = 2 ; }
5345 else { YACSTypeTest = 0 ; }
5346 MESSAGE ("==> TypeTest = " << YACSTypeTest );
5347 SetYACSConvergenceType( YACSTypeTest ) ;
5351 //===============================================================================
5353 //===============================================================================
5354 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
5356 // MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
5357 _LangueShort = LanguageShort ;
5358 if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
5359 else { _Langue = "English" ; }
5362 char* HOMARD_Gen_i::GetLanguageShort()
5364 // MESSAGE ("GetLanguageShort");
5365 return CORBA::string_dup( _LangueShort.c_str() );
5367 //===============================================================================
5368 // Options de publications
5369 //===============================================================================
5370 void HOMARD_Gen_i::SetPublisMesh(CORBA::Long PublisMeshIN, CORBA::Long PublisMeshOUT)
5372 _PublisMeshIN = PublisMeshIN ;
5373 _PublisMeshOUT = PublisMeshOUT ;
5376 CORBA::Long HOMARD_Gen_i::GetPublisMeshIN()
5378 return _PublisMeshIN ;
5380 CORBA::Long HOMARD_Gen_i::GetPublisMeshOUT()
5382 return _PublisMeshOUT ;
5384 //===============================================================================
5385 // YACS - test de convergence
5386 //===============================================================================
5387 void HOMARD_Gen_i::SetYACSMaximum(CORBA::Long YACSMaxIter, CORBA::Long YACSMaxNode, CORBA::Long YACSMaxElem)
5389 _YACSMaxIter = YACSMaxIter ;
5390 _YACSMaxNode = YACSMaxNode ;
5391 _YACSMaxElem = YACSMaxElem ;
5394 CORBA::Long HOMARD_Gen_i::GetYACSMaxIter()
5396 return _YACSMaxIter ;
5398 CORBA::Long HOMARD_Gen_i::GetYACSMaxNode()
5400 return _YACSMaxNode ;
5402 CORBA::Long HOMARD_Gen_i::GetYACSMaxElem()
5404 return _YACSMaxElem ;
5406 void HOMARD_Gen_i::SetYACSConvergenceType(CORBA::Long YACSTypeTest)
5408 _YACSTypeTest = YACSTypeTest ;
5411 CORBA::Long HOMARD_Gen_i::GetYACSConvergenceType()
5413 return _YACSTypeTest ;