1 // Copyright (C) 2011-2022 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>
68 //=============================================================================
70 //=============================================================================
71 std::string RemoveTabulation( std::string theScript )
73 std::string::size_type aPos = 0;
74 while( aPos < theScript.length() )
76 aPos = theScript.find( "\n\t", aPos );
77 if( aPos == std::string::npos )
79 theScript.replace( aPos, 2, "\n" );
84 //=============================================================================
86 * standard constructor
88 //=============================================================================
89 HOMARD_Gen_i::HOMARD_Gen_i( CORBA::ORB_ptr orb,
90 PortableServer::POA_ptr poa,
91 PortableServer::ObjectId * contId,
92 const char *instanceName,
93 const char *interfaceName,
95 Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, checkNS)
97 MESSAGE("constructor de HOMARD_Gen_i");
99 _id = _poa->activate_object(_thisObj);
101 myHomard = new ::HOMARD_Gen;
111 //=================================
113 * standard destructor
115 //================================
116 HOMARD_Gen_i::~HOMARD_Gen_i()
119 //=============================================================================
120 //=============================================================================
121 // Utilitaires pour l'étude
122 //=============================================================================
123 //=============================================================================
124 void HOMARD_Gen_i::UpdateStudy()
126 ASSERT(!CORBA::is_nil(myStudy));
127 SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
129 // Create SComponent labelled 'homard' if it doesn't already exit
130 SALOMEDS::SComponent_var homardFather = myStudy->FindComponent(ComponentDataType());
131 if (CORBA::is_nil(homardFather))
133 myBuilder->NewCommand();
134 MESSAGE("Add Component HOMARD");
136 bool aLocked = myStudy->GetProperties()->IsLocked();
137 if (aLocked) myStudy->GetProperties()->SetLocked(false);
139 homardFather = myBuilder->NewComponent(ComponentDataType());
140 SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
141 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
142 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = this->getModuleCatalog();
143 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
144 if (!Comp->_is_nil())
146 aName->SetValue(ComponentDataType());
149 anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributePixMap");
150 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
151 aPixmap->SetPixMap("HOMARD_2.png");
152 myBuilder->DefineComponentInstance(homardFather, HOMARD_Gen::_this());
154 if (aLocked) myStudy->GetProperties()->SetLocked(true);
155 myBuilder->CommitCommand();
159 //=============================================================================
160 //=============================================================================
161 // Utilitaires pour l'iteration
162 //=============================================================================
163 //=============================================================================
164 void HOMARD_Gen_i::SetEtatIter(const char* nomIter, const CORBA::Long Etat)
165 //=====================================================================================
167 MESSAGE( "SetEtatIter : affectation de l'etat " << Etat << " a l'iteration " << nomIter );
168 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
169 if (CORBA::is_nil(myIteration))
171 SALOME::ExceptionStruct es;
172 es.type = SALOME::BAD_PARAM;
173 es.text = "Invalid iteration";
174 throw SALOME::SALOME_Exception(es);
178 myIteration->SetState(Etat);
180 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
181 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
185 icone = "iter0.png" ;
186 else if ( Etat == 2 )
187 icone = "iter_calculee.png" ;
189 icone = "iter_non_calculee.png" ;
190 PublishInStudyAttr(aStudyBuilder, aIterSO, NULL , NULL, icone.c_str(), NULL) ;
192 aStudyBuilder->CommitCommand();
195 //=============================================================================
196 //=============================================================================
198 //=============================================================================
199 //=============================================================================
200 // Destruction des structures identifiees par leurs noms
201 //=============================================================================
202 //=============================================================================
203 CORBA::Long HOMARD_Gen_i::DeleteBoundary(const char* BoundaryName)
205 MESSAGE ( "DeleteBoundary : BoundaryName = " << BoundaryName );
206 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
207 if (CORBA::is_nil(myBoundary))
209 SALOME::ExceptionStruct es;
210 es.type = SALOME::BAD_PARAM;
211 es.text = "Invalid boundary";
212 throw SALOME::SALOME_Exception(es);
216 // On verifie que la frontiere n'est plus utilisee
217 HOMARD::listeCases* maListe = GetAllCasesName();
218 int numberOfCases = maListe->length();
219 MESSAGE ( ".. Nombre de cas = " << numberOfCases );
220 std::string CaseName ;
221 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType ;
223 HOMARD::HOMARD_Cas_var myCase ;
224 for (int NumeCas = 0; NumeCas< numberOfCases; NumeCas++)
226 CaseName = std::string((*maListe)[NumeCas]);
227 MESSAGE ( "... Examen du cas = " << CaseName.c_str() );
228 myCase = myStudyContext._mesCas[CaseName];
229 ASSERT(!CORBA::is_nil(myCase));
230 ListBoundaryGroupType = myCase->GetBoundaryGroup();
231 numberOfitems = ListBoundaryGroupType->length();
232 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
233 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
235 if ( std::string((*ListBoundaryGroupType)[NumBoundary]) == BoundaryName )
237 SALOME::ExceptionStruct es;
238 es.type = SALOME::BAD_PARAM;
239 es.text = "This boundary is used in a case and cannot be deleted.";
240 throw SALOME::SALOME_Exception(es);
246 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
247 myStudyContext._mesBoundarys.erase(BoundaryName);
248 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(BoundaryName, ComponentDataType());
249 SALOMEDS::SObject_var aSO =listSO[0];
250 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
251 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
255 //=============================================================================
256 CORBA::Long HOMARD_Gen_i::DeleteCase(const char* nomCas, CORBA::Long Option)
258 // Pour detruire un cas
259 MESSAGE ( "DeleteCase : nomCas = " << nomCas << ", avec option = " << Option );
260 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
261 if (CORBA::is_nil(myCase))
263 SALOME::ExceptionStruct es;
264 es.type = SALOME::BAD_PARAM;
265 es.text = "Invalid case context";
266 throw SALOME::SALOME_Exception(es);
269 // On commence par detruire toutes les iterations en partant de l'initiale et y compris elle
270 CORBA::String_var nomIter = myCase->GetIter0Name();
271 CORBA::Long Option1 = 0 ;
272 if ( DeleteIterationOption(nomIter, Option1, Option) != 0 )
277 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
278 myStudyContext._mesCas.erase(nomCas);
279 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomCas, ComponentDataType());
280 SALOMEDS::SObject_var aSO =listSO[0];
281 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
282 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
286 //=============================================================================
287 CORBA::Long HOMARD_Gen_i::DeleteHypo(const char* nomHypo)
289 MESSAGE ( "DeleteHypo : nomHypo = " << nomHypo );
290 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
291 if (CORBA::is_nil(myHypo))
293 SALOME::ExceptionStruct es;
294 es.type = SALOME::BAD_PARAM;
295 es.text = "Invalid hypothesis";
296 throw SALOME::SALOME_Exception(es);
300 // On verifie que l'hypothese n'est plus utilisee
301 HOMARD::listeIters* maListeIter = myHypo->GetIterations();
302 int numberOfIter = maListeIter->length();
303 if ( numberOfIter > 0 )
305 SALOME::ExceptionStruct es;
306 es.type = SALOME::BAD_PARAM;
307 es.text = "This hypothesis is used in an iteration and cannot be deleted.";
308 throw SALOME::SALOME_Exception(es);
312 // suppression du lien avec les zones eventuelles
313 HOMARD::listeZonesHypo* maListe = myHypo->GetZones();
314 int numberOfZones = maListe->length();
315 MESSAGE ( ".. Nombre de zones = " << numberOfZones );
316 for (int NumeZone = 0; NumeZone< numberOfZones; NumeZone++)
318 std::string ZoneName = std::string((*maListe)[NumeZone]);
319 MESSAGE ( ".. suppression du lien avec la zone = " << ZoneName.c_str() );
320 DissociateHypoZone(nomHypo, ZoneName.c_str()) ;
324 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
325 myStudyContext._mesHypotheses.erase(nomHypo);
326 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomHypo, ComponentDataType());
327 SALOMEDS::SObject_var aSO =listSO[0];
328 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
329 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
333 //=============================================================================
334 CORBA::Long HOMARD_Gen_i::DeleteIteration(const char* nomIter, CORBA::Long Option)
336 // Option = 0 : On ne supprime pas le fichier du maillage associe
337 // Option = 1 : On supprime le fichier du maillage associe
338 // Pour detruire une iteration courante
339 MESSAGE ( "DeleteIteration : nomIter = " << nomIter << ", avec option = " << Option );
340 CORBA::Long Option1 = 1 ;
341 return DeleteIterationOption(nomIter, Option1, Option);
343 //=============================================================================
344 CORBA::Long HOMARD_Gen_i::DeleteIterationOption(const char* nomIter, CORBA::Long Option1, CORBA::Long Option2)
346 // Option1 = 0 : On autorise la destruction de l'iteration 0
347 // Option1 = 1 : On interdit la destruction de l'iteration 0
349 // Option2 = 0 : On ne supprime pas le fichier du maillage associe
350 // Option2 = 1 : On supprime le fichier du maillage associe
351 MESSAGE ( "DeleteIterationOption : nomIter = " << nomIter << ", avec options = " << Option1<< ", " << Option2 );
352 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
353 if (CORBA::is_nil(myIteration))
355 SALOME::ExceptionStruct es;
356 es.type = SALOME::BAD_PARAM;
357 es.text = "Invalid iteration";
358 throw SALOME::SALOME_Exception(es);
362 int numero = myIteration->GetNumber();
363 MESSAGE ( "DeleteIterationOption : numero = " << numero );
364 if ( numero == 0 && Option1 == 1 )
366 SALOME::ExceptionStruct es;
367 es.type = SALOME::BAD_PARAM;
368 es.text = "This iteration cannot be deleted.";
369 throw SALOME::SALOME_Exception(es);
373 // On detruit recursivement toutes les filles
374 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
375 int numberOfIter = maListe->length();
376 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
378 std::string nomIterFille = std::string((*maListe)[NumeIter]);
379 MESSAGE ( ".. appel recursif de DeleteIterationOption pour nomIter = " << nomIterFille.c_str() );
380 DeleteIterationOption(nomIterFille.c_str(), Option1, Option2);
383 // On arrive ici pour une iteration sans fille
384 MESSAGE ( "Destruction effective de " << nomIter );
385 // On commence par invalider l'iteration pour faire le menage des dependances
386 // et eventuellement du maillage associe
388 if ( numero == 0 ) { option = 0 ; }
389 else { option = Option2 ; }
390 InvalideIterOption(nomIter, option) ;
392 // Retrait dans la descendance de l'iteration parent
395 std::string nomIterationParent = myIteration->GetIterParentName();
396 MESSAGE ( "Retrait dans la descendance de nomIterationParent " << nomIterationParent );
397 HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterationParent];
398 if (CORBA::is_nil(myIterationParent))
400 SALOME::ExceptionStruct es;
401 es.type = SALOME::BAD_PARAM;
402 es.text = "Invalid iteration";
403 throw SALOME::SALOME_Exception(es);
406 myIterationParent->UnLinkNextIteration(nomIter);
409 // suppression du lien avec l'hypothese
412 std::string nomHypo = myIteration->GetHypoName();
413 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
414 ASSERT(!CORBA::is_nil(myHypo));
415 myHypo->UnLinkIteration(nomIter);
418 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
419 myStudyContext._mesIterations.erase(nomIter);
420 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomIter, ComponentDataType());
421 SALOMEDS::SObject_var aSO =listSO[0];
422 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
423 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
424 // on peut aussi faire RemoveObject
425 // MESSAGE ( "Au final" );
426 // HOMARD::listeIterations* Liste = GetAllIterationsName() ;
427 // numberOfIter = Liste->length();
428 // for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
430 // std::string nomIterFille = std::string((*Liste)[NumeIter]);
431 // MESSAGE ( ".. nomIter = " << nomIterFille.c_str() );
436 //=============================================================================
437 CORBA::Long HOMARD_Gen_i::DeleteYACS(const char* nomYACS, CORBA::Long Option)
439 // Option = 0 : On ne supprime pas le fichier du schema associe
440 // Option = 1 : On supprime le fichier du schema associe
441 MESSAGE ( "DeleteYACS : nomYACS = " << nomYACS << ", avec option = " << Option );
442 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
443 if (CORBA::is_nil(myYACS))
445 SALOME::ExceptionStruct es;
446 es.type = SALOME::BAD_PARAM;
447 es.text = "Invalid schema YACS";
448 throw SALOME::SALOME_Exception(es);
451 // Suppression eventuelle du fichier XML
454 std::string nomFichier = myYACS->GetXMLFile();
455 std::string commande = "rm -rf " + nomFichier ;
456 MESSAGE ( "commande = " << commande );
457 if ((system(commande.c_str())) != 0)
459 SALOME::ExceptionStruct es;
460 es.type = SALOME::BAD_PARAM;
461 es.text = "The xml file for the schema YACS cannot be removed." ;
462 throw SALOME::SALOME_Exception(es);
466 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
467 myStudyContext._mesYACSs.erase(nomYACS);
468 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomYACS, ComponentDataType());
469 SALOMEDS::SObject_var aSO =listSO[0];
470 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
471 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
475 //=============================================================================
476 CORBA::Long HOMARD_Gen_i::DeleteZone(const char* nomZone)
478 MESSAGE ( "DeleteZone : nomZone = " << nomZone );
479 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[nomZone];
480 if (CORBA::is_nil(myZone))
482 SALOME::ExceptionStruct es;
483 es.type = SALOME::BAD_PARAM;
484 es.text = "Invalid zone";
485 throw SALOME::SALOME_Exception(es);
489 // On verifie que la zone n'est plus utilisee
490 HOMARD::listeHypo* maListe = myZone->GetHypo();
491 int numberOfHypo = maListe->length();
492 MESSAGE ( ".. Nombre d'hypotheses = " << numberOfHypo );
493 if ( numberOfHypo > 0 )
495 SALOME::ExceptionStruct es;
496 es.type = SALOME::BAD_PARAM;
497 es.text = "This zone is used in a hypothesis and cannot be deleted.";
498 throw SALOME::SALOME_Exception(es);
502 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
503 myStudyContext._mesZones.erase(nomZone);
504 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomZone, ComponentDataType());
505 SALOMEDS::SObject_var aSO =listSO[0];
506 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
507 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
511 //=============================================================================
512 //=============================================================================
514 //=============================================================================
515 //=============================================================================
516 // Invalidation des structures identifiees par leurs noms
517 //=============================================================================
518 //=============================================================================
519 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
521 MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName );
522 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
523 if (CORBA::is_nil(myBoundary))
525 SALOME::ExceptionStruct es;
526 es.type = SALOME::BAD_PARAM;
527 es.text = "Invalid boundary";
528 throw SALOME::SALOME_Exception(es);
533 SALOME::ExceptionStruct es;
534 es.type = SALOME::BAD_PARAM;
535 es.text = "No change is allowed in a boundary. Ask for evolution.";
536 throw SALOME::SALOME_Exception(es);
540 //=============================================================================
541 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
543 MESSAGE( "InvalideHypo : nomHypo = " << nomHypo );
544 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
545 if (CORBA::is_nil(myHypo))
547 SALOME::ExceptionStruct es;
548 es.type = SALOME::BAD_PARAM;
549 es.text = "Invalid hypothesis";
550 throw SALOME::SALOME_Exception(es);
554 HOMARD::listeIters* maListe = myHypo->GetIterations();
555 int numberOfIter = maListe->length();
556 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
558 std::string nomIter = std::string((*maListe)[NumeIter]);
559 MESSAGE( ".. nomIter = " << nomIter );
560 InvalideIter(nomIter.c_str());
563 //=============================================================================
564 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
566 MESSAGE("InvalideIter : nomIter = " << nomIter);
567 // Pour invalider totalement une iteration courante
568 CORBA::Long Option = 1 ;
569 return InvalideIterOption(nomIter, Option);
571 //=============================================================================
572 void HOMARD_Gen_i::InvalideIterOption(const char* nomIter, CORBA::Long Option)
574 // Option = 0 : On ne supprime pas le fichier du maillage associe
575 // Option = 1 : On supprime le fichier du maillage associe
576 MESSAGE ( "InvalideIterOption : nomIter = " << nomIter << ", avec option = " << Option );
577 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
578 if (CORBA::is_nil(myIteration))
580 SALOME::ExceptionStruct es;
581 es.type = SALOME::BAD_PARAM;
582 es.text = "Invalid iteration";
583 throw SALOME::SALOME_Exception(es);
587 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
588 int numberOfIter = maListe->length();
589 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
591 std::string nomIterFille = std::string((*maListe)[NumeIter]);
592 MESSAGE ( ".. appel recursif de InvalideIter pour nomIter = " << nomIterFille.c_str() );
593 InvalideIter(nomIterFille.c_str());
596 // On arrive ici pour une iteration sans fille
597 MESSAGE ( "Invalidation effective de " << nomIter );
598 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
599 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aIterSO);
600 for (; aIter->More(); aIter->Next())
602 SALOMEDS::SObject_var so = aIter->Value();
603 SALOMEDS::GenericAttribute_var anAttr;
604 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
605 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
606 std::string value (aCommentAttr->Value());
607 if(value == std::string("IterationHomard")) continue;
608 if(value == std::string("HypoHomard")) continue;
609 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
610 aStudyBuilder->RemoveObject(so);
613 int etat = myIteration->GetState();
616 SetEtatIter(nomIter,1);
617 const char * nomCas = myIteration->GetCaseName();
618 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
619 if (CORBA::is_nil(myCase))
621 SALOME::ExceptionStruct es;
622 es.type = SALOME::BAD_PARAM;
623 es.text = "Invalid case context";
624 throw SALOME::SALOME_Exception(es);
627 std::string nomDir = myIteration->GetDirName();
628 std::string nomFichier = myIteration->GetMeshFile();
629 std::string commande = "rm -rf " + std::string(nomDir);
630 if ( Option == 1 ) { commande = commande + ";rm -rf " + std::string(nomFichier) ; }
631 MESSAGE ( "commande = " << commande );
632 if ((system(commande.c_str())) != 0)
634 SALOME::ExceptionStruct es;
635 es.type = SALOME::BAD_PARAM;
636 es.text = "The directory for the calculation cannot be cleared." ;
637 throw SALOME::SALOME_Exception(es);
640 // Suppression du maillage publie dans SMESH
641 std::string MeshName = myIteration->GetMeshName() ;
642 DeleteResultInSmesh(nomFichier, MeshName) ;
646 //=============================================================================
647 void HOMARD_Gen_i::InvalideIterInfo(const char* nomIter)
649 MESSAGE("InvalideIterInfo : nomIter = " << nomIter);
650 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
651 if (CORBA::is_nil(myIteration))
653 SALOME::ExceptionStruct es;
654 es.type = SALOME::BAD_PARAM;
655 es.text = "Invalid iteration";
656 throw SALOME::SALOME_Exception(es);
660 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
661 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aIterSO);
662 for (; aIter->More(); aIter->Next())
664 SALOMEDS::SObject_var so = aIter->Value();
665 SALOMEDS::GenericAttribute_var anAttr;
666 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
667 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
668 std::string value (aCommentAttr->Value());
669 /* MESSAGE("... value = " << value);*/
670 if( (value == std::string("logInfo")) || ( value == std::string("SummaryInfo")) )
672 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
673 aStudyBuilder->RemoveObject(so);
677 const char * nomCas = myIteration->GetCaseName();
678 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
679 if (CORBA::is_nil(myCase))
681 SALOME::ExceptionStruct es;
682 es.type = SALOME::BAD_PARAM;
683 es.text = "Invalid case context";
684 throw SALOME::SALOME_Exception(es);
687 const char* nomDir = myIteration->GetDirName();
688 std::string commande = "rm -f " + std::string(nomDir) + "/info* " ;
689 commande += std::string(nomDir) + "/Liste.*info" ;
690 /* MESSAGE ( "commande = " << commande );*/
691 if ((system(commande.c_str())) != 0)
693 SALOME::ExceptionStruct es;
694 es.type = SALOME::BAD_PARAM;
695 es.text = "The directory for the calculation cannot be cleared." ;
696 throw SALOME::SALOME_Exception(es);
700 //=============================================================================
701 void HOMARD_Gen_i::InvalideYACS(const char* YACSName)
703 MESSAGE( "InvalideYACS : YACSName = " << YACSName );
704 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[YACSName];
705 if (CORBA::is_nil(myYACS))
707 SALOME::ExceptionStruct es;
708 es.type = SALOME::BAD_PARAM;
709 es.text = "Invalid schema YACS";
710 throw SALOME::SALOME_Exception(es);
714 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
715 SALOMEDS::ChildIterator_var aYACS = myStudy->NewChildIterator(aYACSSO);
716 for (; aYACS->More(); aYACS->Next())
718 SALOMEDS::SObject_var so = aYACS->Value();
719 SALOMEDS::GenericAttribute_var anAttr;
720 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
721 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
722 std::string value (aCommentAttr->Value());
723 if( value == std::string("xml") )
725 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
726 aStudyBuilder->RemoveObject(so);
729 std::string nomFichier = myYACS->GetXMLFile();
730 std::string commande = "rm -rf " + std::string(nomFichier) ;
731 MESSAGE ( "commande = " << commande );
732 if ((system(commande.c_str())) != 0)
734 SALOME::ExceptionStruct es;
735 es.type = SALOME::BAD_PARAM;
736 es.text = "The XML file for the schema YACS cannot be removed." ;
737 throw SALOME::SALOME_Exception(es);
741 //=============================================================================
742 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
744 MESSAGE( "InvalideZone : ZoneName = " << ZoneName );
745 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
746 if (CORBA::is_nil(myZone))
748 SALOME::ExceptionStruct es;
749 es.type = SALOME::BAD_PARAM;
750 es.text = "Invalid zone";
751 throw SALOME::SALOME_Exception(es);
754 HOMARD::listeHypo* maListe = myZone->GetHypo();
755 int numberOfHypo = maListe->length();
756 MESSAGE( ".. numberOfHypo = " << numberOfHypo );
757 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
759 std::string nomHypo = std::string((*maListe)[NumeHypo]);
760 MESSAGE( ".. nomHypo = " << nomHypo );
761 InvalideHypo(nomHypo.c_str());
764 //=============================================================================
765 //=============================================================================
767 //=============================================================================
768 //=============================================================================
769 // Association de lien entre des structures identifiees par leurs noms
770 //=============================================================================
771 //=============================================================================
772 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
774 MESSAGE( "AssociateCaseIter : " << nomCas << ", " << nomIter << ", " << labelIter );
776 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
777 if (CORBA::is_nil(myCase))
779 SALOME::ExceptionStruct es;
780 es.type = SALOME::BAD_PARAM;
781 es.text = "Invalid case";
782 throw SALOME::SALOME_Exception(es);
786 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
787 if (CORBA::is_nil(myIteration))
789 SALOME::ExceptionStruct es;
790 es.type = SALOME::BAD_PARAM;
791 es.text = "Invalid iteration";
792 throw SALOME::SALOME_Exception(es);
796 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
797 SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myCase)));
798 if (CORBA::is_nil(aCasSO))
800 SALOME::ExceptionStruct es;
801 es.type = SALOME::BAD_PARAM;
802 es.text = "Invalid case";
803 throw SALOME::SALOME_Exception(es);
807 aStudyBuilder->NewCommand();
808 SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
809 PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
810 "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
811 aStudyBuilder->CommitCommand();
813 myCase->AddIteration(nomIter);
814 myIteration->SetCaseName(nomCas);
816 //=====================================================================================
817 void HOMARD_Gen_i::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
819 MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
821 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypothesis];
822 ASSERT(!CORBA::is_nil(myHypo));
823 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
824 ASSERT(!CORBA::is_nil(aHypoSO));
826 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
827 ASSERT(!CORBA::is_nil(myZone));
828 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myZone)));
829 ASSERT(!CORBA::is_nil(aZoneSO));
831 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
833 aStudyBuilder->NewCommand();
835 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
836 aStudyBuilder->Addreference(aSubSO, aZoneSO);
838 aStudyBuilder->CommitCommand();
840 myZone->AddHypo(nomHypothesis);
841 myHypo->AddZone0(ZoneName, TypeUse);
843 //=============================================================================
844 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
846 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
848 // Verification de l'existence de l'hypothese
849 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
850 ASSERT(!CORBA::is_nil(myHypo));
851 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
852 ASSERT(!CORBA::is_nil(aHypoSO));
854 // Verification de l'existence de l'iteration
855 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
856 ASSERT(!CORBA::is_nil(myIteration));
857 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
858 ASSERT(!CORBA::is_nil(aIterSO));
860 // Gestion de l'arbre d'etudes
861 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
862 aStudyBuilder->NewCommand();
863 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
864 aStudyBuilder->Addreference(aSubSO, aHypoSO);
865 aStudyBuilder->CommitCommand();
868 myIteration->SetHypoName(nomHypo);
869 myHypo->LinkIteration(nomIter);
871 // On stocke les noms des champ a interpoler pour le futur controle de la donnée des pas de temps
872 myIteration->SupprFieldInterps() ;
873 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
874 int numberOfFieldsx2 = ListField->length();
875 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
877 std::string FieldName = std::string((*ListField)[iaux]) ;
878 myIteration->SetFieldInterp(FieldName.c_str()) ;
882 //=============================================================================
883 //=============================================================================
885 //=============================================================================
886 //=============================================================================
887 // Dissociation de lien entre des structures identifiees par leurs noms
888 //=============================================================================
889 //=============================================================================
890 void HOMARD_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
892 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
894 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypothesis];
895 ASSERT(!CORBA::is_nil(myHypo));
896 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
897 ASSERT(!CORBA::is_nil(aHypoSO));
899 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
900 ASSERT(!CORBA::is_nil(myZone));
901 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myZone)));
902 ASSERT(!CORBA::is_nil(aZoneSO));
904 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
906 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(aHypoSO);
907 for (; it->More(); it->Next())
909 SALOMEDS::SObject_var aHypObj = it->Value();
910 SALOMEDS::SObject_var ptrObj;
911 if (aHypObj->ReferencedObject(ptrObj))
913 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
915 aStudyBuilder->NewCommand();
916 aStudyBuilder->RemoveObject(aHypObj);
917 aStudyBuilder->CommitCommand();
923 myZone->SupprHypo(nomHypothesis);
924 myHypo->SupprZone(ZoneName);
926 //=============================================================================
927 //=============================================================================
930 //=============================================================================
931 //=============================================================================
932 // Recuperation des listes
933 //=============================================================================
934 //=============================================================================
935 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
937 MESSAGE("GetAllBoundarysName");
940 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
941 ret->length(myStudyContext._mesBoundarys.size());
942 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
944 for (it = myStudyContext._mesBoundarys.begin();
945 it != myStudyContext._mesBoundarys.end(); it++)
947 ret[i++] = CORBA::string_dup((*it).first.c_str());
952 //=============================================================================
953 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
955 MESSAGE("GetAllCasesName");
958 HOMARD::listeCases_var ret = new HOMARD::listeCases;
959 ret->length(myStudyContext._mesCas.size());
960 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
962 for (it = myStudyContext._mesCas.begin();
963 it != myStudyContext._mesCas.end(); it++)
965 ret[i++] = CORBA::string_dup((*it).first.c_str());
970 //=============================================================================
971 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
973 MESSAGE("GetAllHypothesesName");
976 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
977 ret->length(myStudyContext._mesHypotheses.size());
978 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
980 for (it = myStudyContext._mesHypotheses.begin();
981 it != myStudyContext._mesHypotheses.end(); it++)
983 ret[i++] = CORBA::string_dup((*it).first.c_str());
988 //=============================================================================
989 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
991 MESSAGE("GetAllIterationsName");
994 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
995 ret->length(myStudyContext._mesIterations.size());
996 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
998 for (it = myStudyContext._mesIterations.begin();
999 it != myStudyContext._mesIterations.end(); it++)
1001 ret[i++] = CORBA::string_dup((*it).first.c_str());
1006 //=============================================================================
1007 HOMARD::listeYACSs* HOMARD_Gen_i::GetAllYACSsName()
1009 MESSAGE("GetAllYACSsName");
1012 HOMARD::listeYACSs_var ret = new HOMARD::listeYACSs;
1013 ret->length(myStudyContext._mesYACSs.size());
1014 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it;
1016 for (it = myStudyContext._mesYACSs.begin();
1017 it != myStudyContext._mesYACSs.end(); it++)
1019 ret[i++] = CORBA::string_dup((*it).first.c_str());
1024 //=============================================================================
1025 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
1027 MESSAGE("GetAllZonesName");
1030 HOMARD::listeZones_var ret = new HOMARD::listeZones;
1031 ret->length(myStudyContext._mesZones.size());
1032 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
1034 for (it = myStudyContext._mesZones.begin();
1035 it != myStudyContext._mesZones.end(); it++)
1037 ret[i++] = CORBA::string_dup((*it).first.c_str());
1042 //=============================================================================
1043 //=============================================================================
1045 //=============================================================================
1046 //=============================================================================
1047 // Recuperation des structures identifiees par leurs noms
1048 //=============================================================================
1049 //=============================================================================
1050 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
1052 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[nomBoundary];
1053 ASSERT(!CORBA::is_nil(myBoundary));
1054 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1056 //=============================================================================
1057 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
1059 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
1060 ASSERT(!CORBA::is_nil(myCase));
1061 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1063 //=============================================================================
1064 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
1066 HOMARD::HOMARD_Hypothesis_var myHypothesis = myStudyContext._mesHypotheses[nomHypothesis];
1067 ASSERT(!CORBA::is_nil(myHypothesis));
1068 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1070 //=============================================================================
1071 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* NomIterationation)
1073 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIterationation];
1074 ASSERT(!CORBA::is_nil(myIteration));
1075 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1077 //=============================================================================
1078 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::GetYACS(const char* nomYACS)
1080 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
1081 ASSERT(!CORBA::is_nil(myYACS));
1082 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
1084 //=============================================================================
1085 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
1087 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
1088 ASSERT(!CORBA::is_nil(myZone));
1089 return HOMARD::HOMARD_Zone::_duplicate(myZone);
1091 //=============================================================================
1092 //=============================================================================
1094 //=============================================================================
1095 //=============================================================================
1097 //=============================================================================
1098 //=============================================================================
1099 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)
1101 MESSAGE ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1102 MESSAGE ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte );
1107 if ( _PublisMeshIN != 0 ) option = 2 ;
1108 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, 0, option) ;
1109 myCase->SetDirName(DirName) ;
1111 myCase->MeshInfo(Qual, Diam, Conn, Tail, Inte) ;
1115 //=============================================================================
1116 //=============================================================================
1118 //=============================================================================
1119 //=============================================================================
1120 // Recuperation des structures par le contexte
1121 //=============================================================================
1122 //=============================================================================
1123 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::LastIteration(const char* nomCas)
1125 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
1126 ASSERT(!CORBA::is_nil(myCase));
1128 HOMARD::HOMARD_Iteration_var myIteration = myCase->LastIteration();
1129 ASSERT(!CORBA::is_nil(myIteration));
1131 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1133 //=============================================================================
1134 //=============================================================================
1136 //=============================================================================
1137 //=============================================================================
1138 // Nouvelles structures
1139 //=============================================================================
1140 //=============================================================================
1141 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1143 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1144 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
1145 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
1146 return aCase._retn();
1148 //=============================================================================
1149 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
1151 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1152 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
1153 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
1154 return aHypo._retn();
1156 //=============================================================================
1157 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
1159 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1160 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
1161 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
1162 return aIter._retn();
1164 //=============================================================================
1165 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1167 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1168 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
1169 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1170 return aBoundary._retn();
1172 //=============================================================================
1173 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
1175 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1176 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
1177 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
1178 return aZone._retn();
1180 //=============================================================================
1181 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::newYACS()
1183 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1184 HOMARD_YACS_i* aServant = new HOMARD_YACS_i(_orb, engine);
1185 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(aServant->_this());
1186 return aYACS._retn();
1188 //=============================================================================
1189 //=============================================================================
1191 //=============================================================================
1192 //=============================================================================
1193 // Creation des structures identifiees par leurs noms
1194 //=============================================================================
1195 //=============================================================================
1196 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
1198 // Creation d'un cas initial
1199 // nomCas : nom du cas a creer
1200 // MeshName, MeshFile : nom et fichier du maillage correspondant
1203 INFOS ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1206 if ( _PublisMeshIN != 0 ) option = 2 ;
1207 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 0, 0, option) ;
1209 // Valeurs par defaut des filtrages
1210 myCase->SetPyram(0);
1212 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1214 //=============================================================================
1215 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromIteration(const char* nomCas, const char* DirNameStart)
1217 // nomCas : nom du cas a creer
1218 // DirNameStart : nom du répertoire contenant l'iteration de reprise
1221 MESSAGE ( "CreateCaseFromIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1222 std::string nomDirWork = getenv("PWD") ;
1225 // A. Decodage du point de reprise
1226 // A.1. Controle du répertoire de depart de l'iteration
1227 codret = CHDIR(DirNameStart) ;
1230 SALOME::ExceptionStruct es;
1231 es.type = SALOME::BAD_PARAM;
1232 es.text = "The directory of the iteration does not exist.";
1233 throw SALOME::SALOME_Exception(es);
1236 // A.2. Reperage des fichiers du répertoire de reprise
1237 std::string file_configuration = "" ;
1238 std::string file_maillage_homard = "" ;
1242 struct dirent *dirp;
1243 dp = opendir(DirNameStart);
1244 while ( (dirp = readdir(dp)) != NULL )
1246 std::string file_name(dirp->d_name);
1247 // MESSAGE ( file_name );
1248 bilan = file_name.find("HOMARD.Configuration.") ;
1249 if ( bilan != string::npos ) { file_configuration = file_name ; }
1250 bilan = file_name.find("maill.") ;
1251 if ( bilan != string::npos )
1253 bilan = file_name.find(".hom.med") ;
1254 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1259 HANDLE hFind = INVALID_HANDLE_VALUE;
1260 WIN32_FIND_DATA ffd;
1261 hFind = FindFirstFile(DirNameStart, &ffd);
1262 if (INVALID_HANDLE_VALUE != hFind) {
1263 while (FindNextFile(hFind, &ffd) != 0) {
1264 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1265 std::string file_name(ffd.cFileName);
1266 bilan = file_name.find("HOMARD.Configuration.") ;
1267 if ( bilan != string::npos ) { file_configuration = file_name ; }
1268 bilan = file_name.find("maill.") ;
1269 if ( bilan != string::npos )
1271 bilan = file_name.find(".hom.med") ;
1272 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1278 MESSAGE ( "==> file_configuration : " << file_configuration ) ;
1279 MESSAGE ( "==> file_maillage_homard : " << file_maillage_homard ) ;
1281 if ( ( file_configuration == "" ) || ( file_maillage_homard == "" ) )
1283 SALOME::ExceptionStruct es;
1284 es.type = SALOME::BAD_PARAM;
1286 if ( file_configuration == "" ) { text = "The configuration file cannot be found." ; }
1287 else { text = "The HOMARD mesh file cannot be found." ; }
1288 es.text = CORBA::string_dup(text.c_str());
1289 throw SALOME::SALOME_Exception(es);
1292 // B. Lecture du fichier de configuration
1293 // ATTENTION : on doit veiller a la coherence entre HomardDriver et CreateCaseFromIteration
1300 // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1301 std::ifstream fichier( file_configuration.c_str() );
1302 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1304 std::string ligne; // variable contenant chaque ligne lue
1305 std::string mot_cle;
1306 std::string argument;
1308 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1309 while ( std::getline( fichier, ligne ) )
1311 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1312 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1313 ligne_bis >> mot_cle ;
1314 // B.2. Des valeurs entieres : le second bloc de la ligne
1315 if ( mot_cle == "NumeIter" )
1317 ligne_bis >> NumeIter ;
1320 // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1321 else if ( ( mot_cle == "TypeConf" ) || ( mot_cle == "TypeElem" ) )
1323 ligne_bis >> argument ;
1325 if ( mot_cle == "TypeConf" )
1327 if ( argument == "conforme" ) { TypeConf = 1 ; }
1328 else if ( argument == "non_conforme_1_noeud" ) { TypeConf = 2 ; }
1329 else if ( argument == "non_conforme_1_arete" ) { TypeConf = 3 ; }
1330 else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1332 else if ( mot_cle == "TypeElem" )
1334 if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1335 else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1338 // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1339 // il faut les supprimer
1340 else if ( ( mot_cle == "CCNoMNP1" ) || ( mot_cle == "CCMaiNP1" ) )
1342 ligne_bis >> argument ;
1343 if ( argument[0] == '"' ) { decalage = 1 ; }
1344 else { decalage = 0 ; }
1345 size_t size = argument.size() + 1 - 2*decalage ;
1347 if ( mot_cle == "CCNoMNP1" )
1349 MeshName = new char[ size ];
1350 strncpy( MeshName, argument.c_str()+decalage, size );
1351 MeshName[size-1] = '\0' ;
1353 else if ( mot_cle == "CCMaiNP1" )
1355 MeshFile = new char[ size ];
1356 strncpy( MeshFile, argument.c_str()+decalage, size );
1357 MeshFile[size-1] = '\0' ;
1361 MESSAGE ( "==> TypeConf : " << TypeConf ) ;
1362 MESSAGE ( "==> MeshName : " << MeshName ) ;
1363 MESSAGE ( "==> MeshFile : " << MeshFile ) ;
1364 MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1365 MESSAGE ( "==> Pyram : " << Pyram ) ;
1369 SALOME::ExceptionStruct es;
1370 es.type = SALOME::BAD_PARAM;
1371 std::string text = "The configuration file cannot be read." ;
1372 es.text = CORBA::string_dup(text.c_str());
1373 throw SALOME::SALOME_Exception(es);
1376 // C. Creation effective du cas
1379 if ( _PublisMeshIN != 0 ) option = 2 ;
1380 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, option) ;
1382 // D. Parametrages lus dans le fichier de configuration
1384 myCase->SetConfType (TypeConf) ;
1385 myCase->SetExtType (TypeExt) ;
1386 myCase->SetPyram (Pyram) ;
1388 // E. Copie du fichier de maillage homard
1389 // E.1. Répertoire associe au cas
1390 char* nomDirCase = myCase->GetDirName() ;
1391 // E.2. Répertoire associe a l'iteration de ce cas
1393 IterName = myCase->GetIter0Name() ;
1394 HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1395 char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1396 Iter->SetDirNameLoc(nomDirIter);
1397 std::string nomDirIterTotal ;
1398 nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1400 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1402 if (_mkdir(nomDirIterTotal.c_str()) != 0)
1405 MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1406 SALOME::ExceptionStruct es;
1407 es.type = SALOME::BAD_PARAM;
1408 std::string text = "The directory for the computation cannot be created." ;
1409 es.text = CORBA::string_dup(text.c_str());
1410 throw SALOME::SALOME_Exception(es);
1412 // E.3. Copie du maillage HOMARD au format MED
1413 codret = CHDIR(DirNameStart) ;
1414 std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1415 MESSAGE ( "commande : " << commande ) ;
1416 codret = system(commande.c_str()) ;
1417 MESSAGE ( "codret : " << codret ) ;
1420 SALOME::ExceptionStruct es;
1421 es.type = SALOME::BAD_PARAM;
1422 es.text = "The starting point for the case cannot be copied into the working directory.";
1423 throw SALOME::SALOME_Exception(es);
1432 CHDIR(nomDirWork.c_str());
1433 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1435 //=============================================================================
1436 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1438 // nomCas : nom du cas a creer
1439 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1442 MESSAGE ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1444 std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1446 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1447 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1449 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1451 //=============================================================================
1452 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1454 // nomCas : nom du cas a creer
1455 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1456 // Number : numero de l'iteration de depart
1459 MESSAGE ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1462 SALOME::ExceptionStruct es;
1463 es.type = SALOME::BAD_PARAM;
1464 es.text = "The number of iteration must be positive.";
1465 throw SALOME::SALOME_Exception(es);
1469 std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1471 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1472 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1474 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1476 //=============================================================================
1477 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1479 // Retourne le nom du répertoire ou se trouve l'iteration voulue.
1480 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1481 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1484 MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1485 std::string nomDirWork = getenv("PWD") ;
1486 std::string DirNameStartIter ;
1488 int NumeIterMax = -1 ;
1490 // A.1. Controle du répertoire de depart du cas
1491 codret = CHDIR(DirNameStart) ;
1494 SALOME::ExceptionStruct es;
1495 es.type = SALOME::BAD_PARAM;
1496 es.text = "The directory of the case for the pursuit does not exist.";
1497 throw SALOME::SALOME_Exception(es);
1500 // A.2. Reperage des sous-répertoire du répertoire de reprise
1501 bool existe = false ;
1504 struct dirent *dirp;
1505 dp = opendir(DirNameStart);
1506 while ( (dirp = readdir(dp)) != NULL ) {
1507 std::string DirName_1(dirp->d_name);
1509 HANDLE hFind = INVALID_HANDLE_VALUE;
1510 WIN32_FIND_DATA ffd;
1511 hFind = FindFirstFile(DirNameStart, &ffd);
1512 if (INVALID_HANDLE_VALUE != hFind) {
1513 while (FindNextFile(hFind, &ffd) != 0) {
1514 std::string DirName_1 = "";
1515 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1516 DirName_1 = std::string(ffd.cFileName);
1519 if ( ( DirName_1 != "." ) && ( DirName_1 != ".." ) )
1521 if ( CHDIR(DirName_1.c_str()) == 0 )
1523 // On cherche le fichier de configuration dans ce sous-répertoire
1524 codret = CHDIR(DirNameStart);
1527 struct dirent *dirp_1;
1528 dp_1 = opendir(DirName_1.c_str()) ;
1529 while ( (dirp_1 = readdir(dp_1)) != NULL )
1531 std::string file_name_1(dirp_1->d_name);
1533 HANDLE hFind1 = INVALID_HANDLE_VALUE;
1534 WIN32_FIND_DATA ffd1;
1535 hFind1 = FindFirstFile(DirName_1.c_str(), &ffd1);
1536 while (FindNextFile(hFind1, &ffd1) != 0)
1538 if (ffd1.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1539 std::string file_name_1(ffd1.cFileName);
1541 int bilan = file_name_1.find("HOMARD.Configuration.") ;
1542 if ( bilan != string::npos )
1544 // Decodage du fichier pour trouver le numero d'iteration
1545 CHDIR(DirName_1.c_str()) ;
1547 std::ifstream fichier( file_name_1.c_str() );
1548 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1551 std::string ligne; // variable contenant chaque ligne lue
1552 std::string mot_cle;
1553 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1554 while ( std::getline( fichier, ligne ) )
1556 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1557 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1558 ligne_bis >> mot_cle ;
1559 if ( mot_cle == "NumeIter" )
1561 ligne_bis >> NumeIter ;
1563 // MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1564 if ( Number == - 1 )
1566 if ( NumeIter >= NumeIterMax )
1568 NumeIterMax = NumeIter ;
1569 DirNameStartIter = DirName_1 ;
1574 if ( NumeIter == Number )
1576 DirNameStartIter = DirName_1 ;
1586 SALOME::ExceptionStruct es;
1587 es.type = SALOME::BAD_PARAM;
1588 std::string text = "The configuration file cannot be read." ;
1589 es.text = CORBA::string_dup(text.c_str());
1590 throw SALOME::SALOME_Exception(es);
1592 CHDIR(DirNameStart) ;
1594 if ( existe ) { break ; }
1601 if ( existe ) { break ; }
1610 CHDIR(nomDirWork.c_str());
1612 if ( ( Number >= 0 && ( !existe ) ) || ( Number < 0 && ( NumeIterMax == -1 ) ) )
1614 SALOME::ExceptionStruct es;
1615 es.type = SALOME::BAD_PARAM;
1616 es.text = "The directory of the iteration does not exist.";
1617 throw SALOME::SALOME_Exception(es);
1621 return DirNameStartIter ;
1623 //=============================================================================
1624 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)
1626 // nomCas : nom du cas a creer
1627 // MeshName, MeshFile : nom et fichier du maillage correspondant
1628 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1629 // 1 : le maillage fourni peut ne pas exister ==> on continue si absent
1630 // -1 : le maillage n'est pas fourni
1631 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1632 // Option : multiple de nombres premiers
1633 // 1 : aucune option
1634 // x2 : publication du maillage dans SMESH
1636 MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1637 MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1638 MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1644 // A.2. Controle du nom :
1645 if ((myStudyContext._mesCas).find(nomCas)!=(myStudyContext._mesCas).end())
1647 SALOME::ExceptionStruct es;
1648 es.type = SALOME::BAD_PARAM;
1649 es.text = "This case has already been defined.";
1650 throw SALOME::SALOME_Exception(es);
1654 // A.3. Controle du fichier du maillage
1655 int existeMeshFile ;
1656 if ( MeshOption >= 0 )
1658 existeMeshFile = MEDFileExist ( MeshFile ) ;
1659 MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1660 if ( ( existeMeshFile == 0 ) && ( MeshOption == 0 ) )
1662 SALOME::ExceptionStruct es;
1663 es.type = SALOME::BAD_PARAM;
1664 es.text = "The mesh file does not exist.";
1665 throw SALOME::SALOME_Exception(es);
1669 else { existeMeshFile = 0 ; }
1671 // B. Creation de l'objet cas et publication
1672 // MESSAGE ( "CreateCase0 : Creation de l'objet" );
1673 HOMARD::HOMARD_Cas_var myCase = newCase();
1674 myCase->SetName(nomCas);
1675 SALOMEDS::SObject_var aSO;
1676 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myCase, nomCas);
1677 myStudyContext._mesCas[nomCas] = myCase;
1679 // C. Caracteristiques du maillage
1680 if ( existeMeshFile != 0 )
1682 // Les valeurs extremes des coordonnées
1683 // MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnées" );
1684 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1685 HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1686 if (LesExtremes.size()!=10) { return 0; }
1688 for (int i =0 ; i< LesExtremes.size() ; i++)
1689 aSeq[i]=LesExtremes[i] ;
1690 myCase->SetBoundingBox(aSeq) ;
1692 // MESSAGE ( "CreateCase0 : Les groupes" );
1693 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile) ;
1694 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1695 aSeqGroupe->length(LesGroupes.size());
1696 std::set<std::string>::const_iterator it ;
1698 for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1699 aSeqGroupe[i++]=(*it).c_str() ;
1700 myCase->SetGroups(aSeqGroupe) ;
1703 // D. L'iteration initiale du cas
1704 MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1705 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1706 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1708 std::string NomIteration = std::string(MeshName) ;
1709 while ( (myStudyContext._mesIterations).find(NomIteration) != (myStudyContext._mesIterations.end()) )
1711 std::ostringstream nom;
1712 nom << MeshName << monNum;
1713 NomIteration = nom.str();
1716 MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1718 // D.2. Creation de l'iteration
1719 HOMARD::HOMARD_Iteration_var anIter = newIteration();
1720 myStudyContext._mesIterations[NomIteration] = anIter;
1721 anIter->SetName(NomIteration.c_str());
1722 AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1724 // D.4. Maillage correspondant
1725 if ( existeMeshFile != 0 )
1727 anIter->SetMeshFile(MeshFile);
1728 if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1730 anIter->SetMeshName(MeshName);
1732 // D.5. Numero d'iteration
1733 anIter->SetNumber(NumeIter);
1736 SetEtatIter(NomIteration.c_str(), -NumeIter);
1739 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1741 //=============================================================================
1742 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1744 MESSAGE ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1747 // A. Controle du nom :
1748 if ((myStudyContext._mesHypotheses).find(nomHypothesis) != (myStudyContext._mesHypotheses).end())
1750 SALOME::ExceptionStruct es;
1751 es.type = SALOME::BAD_PARAM;
1752 es.text = "This hypothesis has already been defined.";
1753 throw SALOME::SALOME_Exception(es);
1757 // B. Creation de l'objet
1758 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1759 if (CORBA::is_nil(myHypothesis))
1761 SALOME::ExceptionStruct es;
1762 es.type = SALOME::BAD_PARAM;
1763 es.text = "Unable to create the hypothesis";
1764 throw SALOME::SALOME_Exception(es);
1767 myHypothesis->SetName(nomHypothesis);
1769 // C. Enregistrement
1770 myStudyContext._mesHypotheses[nomHypothesis] = myHypothesis;
1772 SALOMEDS::SObject_var aSO;
1773 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myHypothesis, nomHypothesis);
1775 // D. Valeurs par defaut des options avancees
1776 myHypothesis->SetNivMax(-1);
1777 myHypothesis->SetDiamMin(-1.0);
1778 myHypothesis->SetAdapInit(0);
1779 myHypothesis->SetExtraOutput(1);
1781 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1784 //=============================================================================
1785 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1786 //=============================================================================
1788 MESSAGE ("CreateIteration : NomIteration = " << NomIteration << ", nomIterParent = " << nomIterParent);
1791 HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterParent];
1792 if (CORBA::is_nil(myIterationParent))
1794 SALOME::ExceptionStruct es;
1795 es.type = SALOME::BAD_PARAM;
1796 es.text = "The parent iteration is not defined.";
1797 throw SALOME::SALOME_Exception(es);
1801 const char* nomCas = myIterationParent->GetCaseName();
1802 MESSAGE ("CreateIteration : nomCas = " << nomCas);
1803 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
1804 if (CORBA::is_nil(myCase))
1806 SALOME::ExceptionStruct es;
1807 es.type = SALOME::BAD_PARAM;
1808 es.text = "Invalid case context";
1809 throw SALOME::SALOME_Exception(es);
1812 const char* nomDirCase = myCase->GetDirName();
1814 // Controle du nom :
1815 if ((myStudyContext._mesIterations).find(NomIteration)!=(myStudyContext._mesIterations).end())
1817 SALOME::ExceptionStruct es;
1818 es.type = SALOME::BAD_PARAM;
1819 es.text = "This iteration has already been defined.";
1820 throw SALOME::SALOME_Exception(es);
1824 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1825 if (CORBA::is_nil(myIteration))
1827 SALOME::ExceptionStruct es;
1828 es.type = SALOME::BAD_PARAM;
1829 es.text = "Unable to create the iteration";
1830 throw SALOME::SALOME_Exception(es);
1833 myStudyContext._mesIterations[std::string(NomIteration)] = myIteration;
1834 // Nom de l'iteration et du maillage
1835 myIteration->SetName(NomIteration);
1836 myIteration->SetMeshName(NomIteration);
1837 myIteration->SetState(1);
1839 int numero = myIterationParent->GetNumber() + 1;
1840 myIteration->SetNumber(numero);
1842 // Nombre d'iterations deja connues pour le cas, permettant
1843 // la creation d'un sous-répertoire unique
1844 int nbitercase = myCase->GetNumberofIter();
1845 char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1846 myIteration->SetDirNameLoc(nomDirIter);
1848 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1849 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1850 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1851 // situation la plus frequente.
1852 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1853 // le nombre d'iterations du cas permet d'eviter les collisions.
1855 if ( nbitercase < 100 ) { jaux = 2 ; }
1856 else if ( nbitercase < 1000 ) { jaux = 3 ; }
1857 else if ( nbitercase < 10000 ) { jaux = 4 ; }
1858 else if ( nbitercase < 100000 ) { jaux = 5 ; }
1860 std::ostringstream iaux ;
1861 iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1862 std::stringstream MeshFile;
1863 MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1864 myIteration->SetMeshFile(MeshFile.str().c_str());
1866 // Association avec le cas
1867 std::string label = "IterationHomard_" + std::string(nomIterParent);
1868 AssociateCaseIter(nomCas, NomIteration, label.c_str());
1869 // Lien avec l'iteration precedente
1870 myIterationParent->LinkNextIteration(NomIteration);
1871 myIteration->SetIterParentName(nomIterParent);
1872 // Gestion de l'arbre d'etudes
1873 SALOMEDS::SObject_var aIterSOParent = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIterationParent)));
1874 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
1875 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
1876 aStudyBuilder->NewCommand();
1877 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
1878 aStudyBuilder->Addreference(aSubSO, aIterSOParent);
1879 aStudyBuilder->CommitCommand();
1881 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1883 //=============================================================================
1884 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1886 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1889 // Controle du nom :
1890 if ((myStudyContext._mesBoundarys).find(BoundaryName)!=(myStudyContext._mesBoundarys).end())
1892 MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1893 SALOME::ExceptionStruct es;
1894 es.type = SALOME::BAD_PARAM;
1895 es.text = "This boundary has already been defined";
1896 throw SALOME::SALOME_Exception(es);
1900 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1901 myBoundary->SetName(BoundaryName);
1902 myBoundary->SetType(BoundaryType);
1904 myStudyContext._mesBoundarys[BoundaryName] = myBoundary;
1906 SALOMEDS::SObject_var aSO;
1907 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myBoundary, BoundaryName);
1909 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1911 //=============================================================================
1912 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCAO(const char* BoundaryName, const char* CAOFile)
1914 MESSAGE ("CreateBoundaryCAO : BoundaryName = " << BoundaryName << ", CAOFile = " << CAOFile );
1915 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, -1);
1916 myBoundary->SetDataFile( CAOFile ) ;
1918 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1920 //=============================================================================
1921 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1923 MESSAGE ("CreateBoundaryDi : BoundaryName = " << BoundaryName << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1924 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1925 myBoundary->SetDataFile( MeshFile ) ;
1926 myBoundary->SetMeshName( MeshName ) ;
1928 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1930 //=============================================================================
1931 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1932 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1933 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1934 CORBA::Double Rayon)
1936 MESSAGE ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
1938 SALOME::ExceptionStruct es;
1941 { es.text = "The radius must be positive." ;
1943 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1944 if ( daux < 0.0000001 )
1945 { es.text = "The axis must be a non 0 vector." ;
1949 es.type = SALOME::BAD_PARAM;
1950 throw SALOME::SALOME_Exception(es);
1954 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1955 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1957 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1959 //=============================================================================
1960 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1961 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1962 CORBA::Double Rayon)
1964 MESSAGE ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
1966 SALOME::ExceptionStruct es;
1969 { es.text = "The radius must be positive." ;
1973 es.type = SALOME::BAD_PARAM;
1974 throw SALOME::SALOME_Exception(es);
1978 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1979 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1981 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1983 //=============================================================================
1984 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
1985 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
1986 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
1988 MESSAGE ("CreateBoundaryConeA : BoundaryName = " << BoundaryName ) ;
1990 SALOME::ExceptionStruct es;
1992 if ( Angle <= 0.0 || Angle >= 90.0 )
1993 { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
1995 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1996 if ( daux < 0.0000001 )
1997 { es.text = "The axis must be a non 0 vector." ;
2001 es.type = SALOME::BAD_PARAM;
2002 throw SALOME::SALOME_Exception(es);
2006 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
2007 myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
2009 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2011 //=============================================================================
2012 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
2013 CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
2014 CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
2016 MESSAGE ("CreateBoundaryConeR : BoundaryName = " << BoundaryName ) ;
2018 SALOME::ExceptionStruct es;
2020 if ( Rayon1 < 0.0 || Rayon2 < 0.0 )
2021 { es.text = "The radius must be positive." ;
2023 double daux = fabs(Rayon2-Rayon1) ;
2024 if ( daux < 0.0000001 )
2025 { es.text = "The radius must be different." ;
2027 daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
2028 if ( daux < 0.0000001 )
2029 { es.text = "The centers must be different." ;
2033 es.type = SALOME::BAD_PARAM;
2034 throw SALOME::SALOME_Exception(es);
2038 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
2039 myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
2041 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2043 //=============================================================================
2044 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryTorus(const char* BoundaryName,
2045 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2046 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2047 CORBA::Double RayonRev, CORBA::Double RayonPri)
2049 MESSAGE ("CreateBoundaryTorus : BoundaryName = " << BoundaryName ) ;
2051 SALOME::ExceptionStruct es;
2053 if ( ( RayonRev <= 0.0 ) || ( RayonPri <= 0.0 ) )
2054 { es.text = "The radius must be positive." ;
2056 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2057 if ( daux < 0.0000001 )
2058 { es.text = "The axis must be a non 0 vector." ;
2062 es.type = SALOME::BAD_PARAM;
2063 throw SALOME::SALOME_Exception(es);
2067 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 5) ;
2068 myBoundary->SetTorus( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, RayonRev, RayonPri ) ;
2070 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2072 //=============================================================================
2073 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
2075 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
2078 // Controle du nom :
2079 if ((myStudyContext._mesZones).find(ZoneName)!=(myStudyContext._mesZones).end())
2081 SALOME::ExceptionStruct es;
2082 es.type = SALOME::BAD_PARAM;
2083 es.text = "This zone has already been defined";
2084 throw SALOME::SALOME_Exception(es);
2088 HOMARD::HOMARD_Zone_var myZone = newZone();
2089 myZone->SetName(ZoneName);
2090 myZone->SetType(ZoneType);
2092 myStudyContext._mesZones[ZoneName] = myZone;
2094 SALOMEDS::SObject_var aSO;
2095 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myZone, ZoneName);
2097 return HOMARD::HOMARD_Zone::_duplicate(myZone);
2099 //=============================================================================
2100 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
2101 CORBA::Double Xmini, CORBA::Double Xmaxi,
2102 CORBA::Double Ymini, CORBA::Double Ymaxi,
2103 CORBA::Double Zmini, CORBA::Double Zmaxi)
2105 MESSAGE ("CreateZoneBox : ZoneName = " << ZoneName ) ;
2107 SALOME::ExceptionStruct es;
2109 if ( Xmini > Xmaxi )
2110 { es.text = "The X coordinates are not coherent." ;
2112 if ( Ymini > Ymaxi )
2113 { es.text = "The Y coordinates are not coherent." ;
2115 if ( Zmini > Zmaxi )
2116 { es.text = "The Z coordinates are not coherent." ;
2120 es.type = SALOME::BAD_PARAM;
2121 throw SALOME::SALOME_Exception(es);
2125 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
2126 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2128 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2130 //=============================================================================
2131 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
2132 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
2134 MESSAGE ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
2136 SALOME::ExceptionStruct es;
2139 { es.text = "The radius must be positive." ;
2143 es.type = SALOME::BAD_PARAM;
2144 throw SALOME::SALOME_Exception(es);
2148 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
2149 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2151 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2153 //=============================================================================
2154 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
2155 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2156 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2157 CORBA::Double Rayon, CORBA::Double Haut)
2159 MESSAGE ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
2161 SALOME::ExceptionStruct es;
2164 { es.text = "The radius must be positive." ;
2166 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2167 if ( daux < 0.0000001 )
2168 { es.text = "The axis must be a non 0 vector." ;
2171 { es.text = "The height must be positive." ;
2175 es.type = SALOME::BAD_PARAM;
2176 throw SALOME::SALOME_Exception(es);
2180 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
2181 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
2183 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2185 //=============================================================================
2186 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
2187 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2188 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2189 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
2191 MESSAGE ("CreateZonePipe : ZoneName = " << ZoneName ) ;
2193 SALOME::ExceptionStruct es;
2195 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2196 { es.text = "The radius must be positive." ;
2198 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2199 if ( daux < 0.0000001 )
2200 { es.text = "The axis must be a non 0 vector." ;
2203 { es.text = "The height must be positive." ;
2205 if ( Rayon <= Rayonint )
2206 { es.text = "The external radius must be higher than the internal radius." ;
2210 es.type = SALOME::BAD_PARAM;
2211 throw SALOME::SALOME_Exception(es);
2215 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
2216 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
2218 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2220 //=============================================================================
2221 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
2222 CORBA::Double Umini, CORBA::Double Umaxi,
2223 CORBA::Double Vmini, CORBA::Double Vmaxi,
2226 MESSAGE ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
2227 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
2228 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
2229 // MESSAGE ("Orient = " << Orient ) ;
2231 SALOME::ExceptionStruct es;
2233 if ( Umini > Umaxi )
2234 { es.text = "The first coordinates are not coherent." ;
2236 if ( Vmini > Vmaxi )
2237 { es.text = "The second coordinates are not coherent." ;
2239 if ( Orient < 1 || Orient > 3 )
2240 { es.text = "The orientation must be 1, 2 or 3." ;
2244 es.type = SALOME::BAD_PARAM;
2245 throw SALOME::SALOME_Exception(es);
2249 double Xmini, Xmaxi ;
2250 double Ymini, Ymaxi ;
2251 double Zmini, Zmaxi ;
2259 else if ( Orient == 2 )
2266 else if ( Orient == 3 )
2273 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2275 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2276 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2278 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2280 //=============================================================================
2281 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2282 CORBA::Double Ucentre, CORBA::Double Vcentre,
2283 CORBA::Double Rayon,
2286 MESSAGE ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
2288 SALOME::ExceptionStruct es;
2291 { es.text = "The radius must be positive." ;
2293 if ( Orient < 1 || Orient > 3 )
2294 { es.text = "The orientation must be 1, 2 or 3." ;
2298 es.type = SALOME::BAD_PARAM;
2299 throw SALOME::SALOME_Exception(es);
2307 { Xcentre = Ucentre ;
2310 else if ( Orient == 2 )
2313 Zcentre = Vcentre ; }
2314 else if ( Orient == 3 )
2315 { Xcentre = Vcentre ;
2317 Zcentre = Ucentre ; }
2318 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2320 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2321 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2323 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2325 //=============================================================================
2326 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2327 CORBA::Double Ucentre, CORBA::Double Vcentre,
2328 CORBA::Double Rayon, CORBA::Double Rayonint,
2331 MESSAGE ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
2333 SALOME::ExceptionStruct es;
2335 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2336 { es.text = "The radius must be positive." ;
2338 if ( Orient < 1 || Orient > 3 )
2339 { es.text = "The orientation must be 1, 2 or 3." ;
2341 if ( Rayon <= Rayonint )
2342 { es.text = "The external radius must be higher than the internal radius." ;
2346 es.type = SALOME::BAD_PARAM;
2347 throw SALOME::SALOME_Exception(es);
2355 { Xcentre = Ucentre ;
2358 else if ( Orient == 2 )
2361 Zcentre = Vcentre ; }
2362 else if ( Orient == 3 )
2363 { Xcentre = Vcentre ;
2365 Zcentre = Ucentre ; }
2366 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2368 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2369 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2371 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2373 //=============================================================================
2374 //=============================================================================
2379 //=============================================================================
2380 //=============================================================================
2381 // Traitement d'une iteration
2382 // etatMenage = 1 : destruction du répertoire d'execution
2383 // modeHOMARD = 1 : adaptation
2384 // != 1 : information avec les options modeHOMARD
2385 // Option1 >0 : appel depuis python
2386 // <0 : appel depuis GUI
2387 // Option2 : multiple de nombres premiers
2388 // 1 : aucune option
2389 // x2 : publication du maillage dans SMESH
2390 //=============================================================================
2391 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2393 INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2398 // A.1. L'objet iteration
2399 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIteration];
2400 ASSERT(!CORBA::is_nil(myIteration));
2402 // A.2. Controle de la possibilite d'agir
2403 // A.2.1. Etat de l'iteration
2404 int etat = myIteration->GetState();
2405 MESSAGE ( "etat = "<<etat );
2406 // A.2.2. On ne calcule pas l'iteration initiale, ni une iteration deja calculee
2407 if ( modeHOMARD == 1 )
2411 SALOME::ExceptionStruct es;
2412 es.type = SALOME::BAD_PARAM;
2413 es.text = "This iteration is the first of the case and cannot be computed.";
2414 throw SALOME::SALOME_Exception(es);
2417 else if ( ( etat == 2 ) & ( modeHOMARD == 1 ) )
2419 SALOME::ExceptionStruct es;
2420 es.type = SALOME::BAD_PARAM;
2421 es.text = "This iteration is already computed.";
2422 throw SALOME::SALOME_Exception(es);
2426 // A.2.3. On n'analyse pas une iteration non calculee
2431 SALOME::ExceptionStruct es;
2432 es.type = SALOME::BAD_PARAM;
2433 es.text = "This iteration is not computed.";
2434 throw SALOME::SALOME_Exception(es);
2439 // A.3. Numero de l'iteration
2440 // siterp1 : numero de l'iteration a traiter
2442 // siter : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2443 // Ou si information :
2445 int NumeIter = myIteration->GetNumber();
2446 std::string siterp1 ;
2447 std::stringstream saux1 ;
2449 siterp1 = saux1.str() ;
2450 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2453 if ( modeHOMARD==1 )
2455 std::stringstream saux0 ;
2456 int iaux = max(0, NumeIter-1) ;
2458 siter = saux0.str() ;
2459 if (NumeIter < 11) { siter = "0" + siter ; }
2462 { siter = siterp1 ; }
2465 const char* nomCas = myIteration->GetCaseName();
2466 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
2467 ASSERT(!CORBA::is_nil(myCase));
2469 // B. Les répertoires
2470 // B.1. Le répertoire courant
2471 std::string nomDirWork = getenv("PWD") ;
2472 // B.2. Le sous-répertoire de l'iteration a traiter
2473 char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2474 MESSAGE( ". DirCompute = " << DirCompute );
2476 // C. Le fichier des messages
2477 // C.1. Le deroulement de l'execution de HOMARD
2478 std::string LogFile = DirCompute ;
2479 LogFile += "/Liste" ;
2480 if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2482 MESSAGE (". LogFile = " << LogFile);
2483 if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2484 // C.2. Le bilan de l'analyse du maillage
2485 std::string FileInfo = DirCompute ;
2487 if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2489 { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2490 else { FileInfo += "info_ap" ; }
2492 FileInfo += "." + siterp1 + ".bilan" ;
2493 myIteration->SetFileInfo(FileInfo.c_str());
2495 // D. On passe dans le répertoire de l'iteration a calculer
2496 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2499 // E. Les données de l'exécution HOMARD
2500 // E.1. L'objet du texte du fichier de configuration
2501 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2502 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2504 // E.2. Le maillage associe a l'iteration
2505 const char* NomMesh = myIteration->GetMeshName();
2506 MESSAGE ( ". NomMesh = " << NomMesh );
2507 const char* MeshFile = myIteration->GetMeshFile();
2508 MESSAGE ( ". MeshFile = " << MeshFile );
2510 // E.3. Les données du traitement HOMARD
2512 if ( modeHOMARD == 1 )
2515 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2516 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2517 codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2521 InvalideIterInfo(NomIteration);
2522 myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2524 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2525 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2526 myDriver->CreeFichierDonn();
2529 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2530 int BoundaryOption = DriverTexteBoundary(myCase, myDriver) ;
2532 // E.5. Ecriture du texte dans le fichier
2533 MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2535 { myDriver->CreeFichier(); }
2539 int codretexec = 1789 ;
2542 codretexec = myDriver->ExecuteHomard(Option1);
2544 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2545 // En mode adaptation, on ajuste l'etat de l'iteration
2546 if ( modeHOMARD == 1 )
2548 if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2549 else { SetEtatIter(NomIteration,1); }
2550 // GERALD -- QMESSAGE BOX
2554 // H. Gestion des resultats
2557 std::string Commentaire ;
2558 // H.1. Le fichier des messages, dans tous les cas
2559 Commentaire = "log" ;
2560 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2561 else { Commentaire += "Info" ; }
2562 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2564 // H.2. Si tout s'est bien passe :
2565 if (codretexec == 0)
2567 // H.2.1. Le fichier de bilan
2568 Commentaire = "Summary" ;
2569 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2570 else { Commentaire += "Info" ; }
2571 PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2572 // H.2.2. Le fichier de maillage obtenu
2573 if ( modeHOMARD == 1 )
2575 std::stringstream saux0 ;
2576 Commentaire = "Mesh" ;
2577 Commentaire += " " + siterp1 ;
2578 PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2579 if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2582 // H.3 Message d'erreur
2583 if (codretexec != 0)
2585 std::string text = "" ;
2586 // Message d'erreur en cas de probleme en adaptation
2587 if ( modeHOMARD == 1 )
2589 text = "Error during the adaptation.\n" ;
2590 bool stopvu = false ;
2591 std::ifstream fichier( LogFile.c_str() );
2592 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
2594 std::string ligne; // variable contenant chaque ligne lue
2595 while ( std::getline( fichier, ligne ) )
2599 { text += ligne+ "\n"; }
2602 int position = ligne.find( "===== HOMARD ===== STOP =====" ) ;
2603 if ( position > 0 ) { stopvu = true ; }
2608 text += "\n\nSee the file " + LogFile + "\n" ;
2610 SALOME::ExceptionStruct es;
2611 es.type = SALOME::BAD_PARAM;
2612 es.text = CORBA::string_dup(text.c_str());
2613 throw SALOME::SALOME_Exception(es);
2615 // En mode information, on force le succes pour pouvoir consulter le fichier log
2616 if ( modeHOMARD != 1 ) { codretexec = 0 ; }
2620 // I. Menage et retour dans le répertoire du cas
2624 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2626 CHDIR(nomDirWork.c_str());
2629 // J. Suivi de la frontière CAO
2630 // std::cout << "- codret : " << codret << std::endl;
2631 // std::cout << "- modeHOMARD : " << modeHOMARD << std::endl;
2632 // std::cout << "- BoundaryOption : " << BoundaryOption << std::endl;
2633 // std::cout << "- codretexec : " << codretexec << std::endl;
2636 if ( ( modeHOMARD == 1 ) && ( BoundaryOption % 5 == 0 ) && (codretexec == 0) )
2638 MESSAGE ( "Suivi de frontière CAO" );
2639 codret = ComputeCAO(myCase, myIteration, Option1, Option2) ;
2645 //=============================================================================
2646 // Calcul d'une iteration : partie spécifique à l'adaptation
2647 //=============================================================================
2648 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)
2650 MESSAGE ( "ComputeAdap avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2655 // Numero de l'iteration
2656 int NumeIter = myIteration->GetNumber();
2657 std::stringstream saux0 ;
2658 saux0 << NumeIter-1 ;
2659 std::string siter = saux0.str() ;
2660 if (NumeIter < 11) { siter = "0" + siter ; }
2662 // A.2. On verifie qu il y a une hypothese (erreur improbable);
2663 const char* nomHypo = myIteration->GetHypoName();
2664 if (std::string(nomHypo) == std::string(""))
2666 SALOME::ExceptionStruct es;
2667 es.type = SALOME::BAD_PARAM;
2668 es.text = "This iteration does not have any associated hypothesis.";
2669 throw SALOME::SALOME_Exception(es);
2672 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
2673 ASSERT(!CORBA::is_nil(myHypo));
2675 // B. L'iteration parent
2676 const char* nomIterationParent = myIteration->GetIterParentName();
2677 HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterationParent];
2678 ASSERT(!CORBA::is_nil(myIterationParent));
2679 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2680 if ( myIterationParent->GetState() == 1 )
2683 int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2686 // GERALD -- QMESSAGE BOX
2687 VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2691 // C. Le sous-répertoire de l'iteration precedente
2692 char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2693 MESSAGE( ". DirComputePa = " << DirComputePa );
2695 // D. Les données de l'adaptation HOMARD
2696 // D.1. Le type de conformite
2697 int ConfType = myCase->GetConfType();
2698 MESSAGE ( ". ConfType = " << ConfType );
2700 // D.1. Le type externe
2701 int ExtType = myCase->GetExtType();
2702 MESSAGE ( ". ExtType = " << ExtType );
2704 // D.3. Le maillage de depart
2705 const char* NomMeshParent = myIterationParent->GetMeshName();
2706 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2707 const char* MeshFileParent = myIterationParent->GetMeshFile();
2708 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2710 // D.4. Le maillage associe a l'iteration
2711 const char* MeshFile = myIteration->GetMeshFile();
2712 MESSAGE ( ". MeshFile = " << MeshFile );
2713 FILE *file = fopen(MeshFile,"r");
2717 if (etatMenage == 0)
2719 SALOME::ExceptionStruct es;
2720 es.type = SALOME::BAD_PARAM;
2721 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2722 es.text = CORBA::string_dup(text.c_str());
2723 throw SALOME::SALOME_Exception(es);
2728 std::string commande = "rm -f " + std::string(MeshFile);
2729 codret = system(commande.c_str());
2732 SALOME::ExceptionStruct es;
2733 es.type = SALOME::BAD_PARAM;
2734 es.text = "The mesh file cannot be deleted.";
2735 throw SALOME::SALOME_Exception(es);
2741 // D.5. Les types de raffinement et de deraffinement
2742 // Les appels corba sont lourds, il vaut mieux les grouper
2743 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2744 ASSERT(ListTypes->length() == 3);
2745 int TypeAdap = (*ListTypes)[0];
2746 int TypeRaff = (*ListTypes)[1];
2747 int TypeDera = (*ListTypes)[2];
2748 // MESSAGE ( ". TypeAdap = " << TypeAdap << ", TypeRaff = " << TypeRaff << ", TypeDera = " << TypeDera );
2750 // E. Texte du fichier de configuration
2751 // E.1. Incontournables du texte
2752 myDriver->TexteAdap(ExtType);
2754 myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2755 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2756 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2758 // E.2. Ajout des informations liees aux zones eventuelles
2759 if ( TypeAdap == 0 )
2760 { DriverTexteZone(myHypo, myDriver) ; }
2762 // E.3. Ajout des informations liees aux champs eventuels
2763 if ( TypeAdap == 1 )
2764 { DriverTexteField(myIteration, myHypo, myDriver) ; }
2766 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2767 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2768 int numberOfGroups = listeGroupes->length();
2769 MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2770 if (numberOfGroups > 0)
2772 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2774 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2775 MESSAGE( "... GroupName = " << GroupName );
2776 myDriver->TexteGroup(GroupName);
2780 // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2781 DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2783 // E.6. Ajout des options avancees
2784 int Pyram = myCase->GetPyram();
2785 MESSAGE ( ". Pyram = " << Pyram );
2786 int NivMax = myHypo->GetNivMax();
2787 MESSAGE ( ". NivMax = " << NivMax );
2788 double DiamMin = myHypo->GetDiamMin() ;
2789 MESSAGE ( ". DiamMin = " << DiamMin );
2790 int AdapInit = myHypo->GetAdapInit();
2791 MESSAGE ( ". AdapInit = " << AdapInit );
2792 int ExtraOutput = myHypo->GetExtraOutput();
2793 MESSAGE ( ". ExtraOutput = " << ExtraOutput );
2794 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, ExtraOutput);
2796 // E.7. Ajout des informations sur le deroulement de l'execution
2797 int MessInfo = myIteration->GetInfoCompute();
2798 MESSAGE ( ". MessInfo = " << MessInfo );
2799 myDriver->TexteInfoCompute(MessInfo);
2803 //=============================================================================
2804 // Calcul d'une iteration : partie spécifique au suivi de frontière CAO
2805 //=============================================================================
2806 CORBA::Long HOMARD_Gen_i::ComputeCAO(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long Option1, CORBA::Long Option2)
2808 MESSAGE ( "ComputeCAO avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2813 // A.2. Le sous-répertoire de l'iteration en cours de traitement
2814 char* DirCompute = myIteration->GetDirName();
2815 // A.3. Le maillage résultat de l'iteration en cours de traitement
2816 char* MeshFile = myIteration->GetMeshFile();
2818 // B. Les données pour FrontTrack
2819 // B.1. Le maillage à modifier
2820 const std::string theInputMedFile = MeshFile;
2821 MESSAGE ( ". theInputMedFile = " << theInputMedFile );
2823 // B.2. Le maillage après modification : fichier identique
2824 const std::string theOutputMedFile = MeshFile ;
2825 MESSAGE ( ". theOutputMedFile = " << theInputMedFile );
2827 // B.3. La liste des fichiers contenant les numéros des noeuds à bouger
2828 std::vector< std::string > theInputNodeFiles ;
2829 MESSAGE ( ". DirCompute = " << DirCompute );
2834 struct dirent *dirp;
2835 dp = opendir(DirCompute);
2836 while ( (dirp = readdir(dp)) != NULL )
2838 std::string file_name(dirp->d_name);
2839 bilan = file_name.find("fr") ;
2840 if ( bilan != string::npos )
2842 std::stringstream filename_total ;
2843 filename_total << DirCompute << "/" << file_name ;
2844 theInputNodeFiles.push_back(filename_total.str()) ;
2849 HANDLE hFind = INVALID_HANDLE_VALUE;
2850 WIN32_FIND_DATA ffd;
2851 hFind = FindFirstFile(DirNameStart, &ffd);
2852 if (INVALID_HANDLE_VALUE != hFind) {
2853 while (FindNextFile(hFind, &ffd) != 0) {
2854 std::string file_name(ffd.cFileName);
2855 bilan = file_name.find("fr") ;
2856 if ( bilan != string::npos )
2858 std::stringstream filename_total ;
2859 filename_total << DirCompute << "/" << file_name ;
2860 theInputNodeFiles.push_back(filename_total.str()) ;
2867 for ( int i = 0; i < icpt; i++ )
2868 { MESSAGE ( ". theInputNodeFiles["<< i << "] = " << theInputNodeFiles[i] ); }
2870 // B.4. Le fichier de la CAO
2871 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2872 std::string BoundaryName = std::string((*ListBoundaryGroupType)[0]);
2873 MESSAGE ( ". BoundaryName = " << BoundaryName );
2874 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
2875 const std::string theXaoFileName = myBoundary->GetDataFile();
2876 MESSAGE ( ". theXaoFileName = " << theXaoFileName );
2878 // B.5. Parallélisme
2879 bool theIsParallel = false;
2881 // C. Lancement des projections
2882 MESSAGE ( ". Lancement des projections" );
2883 FrontTrack* myFrontTrack = new FrontTrack();
2884 myFrontTrack->track(theInputMedFile, theOutputMedFile, theInputNodeFiles, theXaoFileName, theIsParallel);
2886 // D. Transfert des coordonnées modifiées dans le fichier historique de HOMARD
2887 // On lance une exécution spéciale de HOMARD en attendant de savoir le faire avec MEDCoupling
2888 MESSAGE ( ". Transfert des coordonnées" );
2889 codret = ComputeCAObis(myIteration, Option1, Option2) ;
2893 //=============================================================================
2894 //=============================================================================
2895 // Transfert des coordonnées en suivi de frontière CAO
2896 // Option1 >0 : appel depuis python
2897 // <0 : appel depuis GUI
2898 // Option2 : multiple de nombres premiers
2899 // 1 : aucune option
2900 // x2 : publication du maillage dans SMESH
2901 //=============================================================================
2902 CORBA::Long HOMARD_Gen_i::ComputeCAObis(HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long Option1, CORBA::Long Option2)
2904 MESSAGE ( "ComputeCAObis, avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2909 // A.1. Controle de la possibilite d'agir
2910 // A.1.1. Etat de l'iteration
2911 int etat = myIteration->GetState();
2912 MESSAGE ( "etat = "<<etat );
2913 // A.1.2. L'iteration doit être calculee
2916 SALOME::ExceptionStruct es;
2917 es.type = SALOME::BAD_PARAM;
2918 es.text = "This iteration is not computed.";
2919 throw SALOME::SALOME_Exception(es);
2922 // A.2. Numero de l'iteration
2923 // siterp1 : numero de l'iteration a traiter
2924 int NumeIter = myIteration->GetNumber();
2925 std::string siterp1 ;
2926 std::stringstream saux1 ;
2928 siterp1 = saux1.str() ;
2929 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2930 MESSAGE ( "siterp1 = "<<siterp1 );
2933 const char* CaseName = myIteration->GetCaseName();
2934 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[CaseName];
2935 ASSERT(!CORBA::is_nil(myCase));
2937 // A.4. Le sous-répertoire de l'iteration a traiter
2938 char* DirCompute = myIteration->GetDirName();
2939 MESSAGE( ". DirCompute = " << DirCompute );
2941 // C. Le fichier des messages
2942 std::string LogFile = DirCompute ;
2943 LogFile += "/Liste." + siterp1 + ".maj_coords.log" ;
2944 MESSAGE (". LogFile = " << LogFile);
2945 myIteration->SetFileInfo(LogFile.c_str());
2947 // D. On passe dans le répertoire de l'iteration a calculer
2948 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2951 // E. Les données de l'exécution HOMARD
2952 // E.1. L'objet du texte du fichier de configuration
2953 HomardDriver* myDriver = new HomardDriver("", siterp1);
2954 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2956 // E.2. Le maillage associe a l'iteration
2957 const char* NomMesh = myIteration->GetMeshName();
2958 MESSAGE ( ". NomMesh = " << NomMesh );
2959 const char* MeshFile = myIteration->GetMeshFile();
2960 MESSAGE ( ". MeshFile = " << MeshFile );
2962 // E.3. Les données du traitement HOMARD
2964 myDriver->TexteMajCoords( NumeIter ) ;
2966 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2967 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2969 // E.4. Ecriture du texte dans le fichier
2970 MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2972 { myDriver->CreeFichier(); }
2976 int codretexec = 1789 ;
2979 codretexec = myDriver->ExecuteHomard(Option1);
2980 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2983 // G. Gestion des resultats
2986 // G.1. Le fichier des messages, dans tous les cas
2987 const char* NomIteration = myIteration->GetName();
2988 std::string Commentaire = "logmaj_coords" ;
2989 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2990 // G.2 Message d'erreur
2991 if (codretexec != 0)
2993 std::string text = "\n\nSee the file " + LogFile + "\n" ;
2995 SALOME::ExceptionStruct es;
2996 es.type = SALOME::BAD_PARAM;
2997 es.text = CORBA::string_dup(text.c_str());
2998 throw SALOME::SALOME_Exception(es);
3000 // On force le succes pour pouvoir consulter le fichier log
3005 // H. Menage et retour dans le répertoire du cas
3006 if (codret == 0) { delete myDriver; }
3010 //=============================================================================
3011 // Creation d'un nom de sous-répertoire pour l'iteration au sein d'un répertoire parent
3012 // nomrep : nom du répertoire parent
3013 // num : le nom du sous-répertoire est sous la forme 'In', n est >= num
3014 //=============================================================================
3015 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
3017 MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
3018 // On verifie que le répertoire parent existe
3019 int codret = CHDIR(nomrep) ;
3022 SALOME::ExceptionStruct es;
3023 es.type = SALOME::BAD_PARAM;
3024 es.text = "The directory of the case does not exist.";
3025 throw SALOME::SALOME_Exception(es);
3028 std::string nomDirActuel = getenv("PWD") ;
3029 std::string DirName ;
3030 // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un répertoire inconnu
3031 bool a_chercher = true ;
3032 while ( a_chercher )
3034 // On passe dans le répertoire parent
3037 // On recherche un nom sous la forme Iabc, avec abc representant le numero
3039 if ( num < 100 ) { jaux = 2 ; }
3040 else if ( num < 1000 ) { jaux = 3 ; }
3041 else if ( num < 10000 ) { jaux = 4 ; }
3042 else if ( num < 100000 ) { jaux = 5 ; }
3044 std::ostringstream iaux ;
3045 iaux << std::setw(jaux) << std::setfill('0') << num ;
3046 std::ostringstream DirNameA ;
3047 DirNameA << "I" << iaux.str();
3048 // Si on ne pas peut entrer dans le répertoire, on doit verifier
3049 // que c'est bien un probleme d'absence
3050 if ( CHDIR(DirNameA.str().c_str()) != 0 )
3052 bool existe = false ;
3055 struct dirent *dirp;
3056 dp = opendir(nomrep);
3057 while ( (dirp = readdir(dp)) != NULL )
3059 std::string file_name(dirp->d_name);
3061 HANDLE hFind = INVALID_HANDLE_VALUE;
3062 WIN32_FIND_DATA ffd;
3063 hFind = FindFirstFile(nomrep, &ffd);
3064 if (INVALID_HANDLE_VALUE != hFind) {
3065 while (FindNextFile(hFind, &ffd) != 0) {
3066 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
3067 std::string file_name(ffd.cFileName);
3069 if ( file_name == DirNameA.str() ) { existe = true ; }
3078 DirName = DirNameA.str() ;
3079 a_chercher = false ;
3086 MESSAGE ( "==> DirName = " << DirName);
3087 MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
3088 CHDIR(nomDirActuel.c_str());
3089 return CORBA::string_dup( DirName.c_str() );
3091 //=============================================================================
3092 // Calcul d'une iteration : gestion du répertoire de calcul
3093 // Si le sous-répertoire existe :
3094 // etatMenage = 0 : on sort en erreur si le répertoire n'est pas vide
3095 // etatMenage = 1 : on fait le menage du répertoire
3096 // etatMenage = -1 : on ne fait rien
3097 //=============================================================================
3098 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
3100 MESSAGE ( "ComputeDirManagement : répertoires pour le calcul" );
3101 // B.2. Le répertoire du cas
3102 const char* nomDirCase = myCase->GetDirName();
3103 MESSAGE ( ". nomDirCase = " << nomDirCase );
3105 // B.3. Le sous-répertoire de l'iteration a calculer, puis le répertoire complet a creer
3106 // B.3.1. Le nom du sous-répertoire
3107 const char* nomDirIt = myIteration->GetDirNameLoc();
3109 // B.3.2. Le nom complet du sous-répertoire
3110 std::stringstream DirCompute ;
3111 DirCompute << nomDirCase << "/" << nomDirIt;
3112 MESSAGE (". DirCompute = " << DirCompute.str() );
3114 // B.3.3. Si le sous-répertoire n'existe pas, on le cree
3115 if (CHDIR(DirCompute.str().c_str()) != 0)
3118 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
3120 if (_mkdir(DirCompute.str().c_str()) != 0)
3123 // GERALD -- QMESSAGE BOX
3124 std::cerr << "Pb Creation du répertoire DirCompute = " << DirCompute.str() << std::endl;
3125 VERIFICATION("Pb a la creation du répertoire" == 0);
3130 // Le répertoire existe
3131 // On demande de faire le menage de son contenu :
3132 if (etatMenage == 1)
3134 MESSAGE (". Menage du répertoire DirCompute = " << DirCompute.str());
3135 std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
3136 int codret = system(commande.c_str());
3139 // GERALD -- QMESSAGE BOX
3140 std::cerr << ". Menage du répertoire de calcul" << DirCompute.str() << std::endl;
3141 VERIFICATION("Pb au menage du répertoire de calcul" == 0);
3144 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
3147 if (etatMenage == 0)
3151 struct dirent *dirp;
3152 dp = opendir(DirCompute.str().c_str());
3154 while ((dirp = readdir(dp)) != NULL && result )
3156 std::string file_name(dirp->d_name);
3157 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3161 HANDLE hFind = INVALID_HANDLE_VALUE;
3162 WIN32_FIND_DATA ffd;
3163 hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
3165 if (INVALID_HANDLE_VALUE != hFind) {
3166 while (FindNextFile(hFind, &ffd) != 0) {
3167 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
3168 std::string file_name(ffd.cFileName);
3169 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3174 if ( result == false)
3176 SALOME::ExceptionStruct es;
3177 es.type = SALOME::BAD_PARAM;
3178 std::string text = "Directory : " + DirCompute.str() + " is not empty";
3179 es.text = CORBA::string_dup(text.c_str());
3180 throw SALOME::SALOME_Exception(es);
3181 VERIFICATION("Directory is not empty" == 0);
3187 return CORBA::string_dup( DirCompute.str().c_str() );
3189 //=============================================================================
3190 // Calcul d'une iteration : gestion du répertoire de calcul de l'iteration parent
3191 //=============================================================================
3192 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
3194 MESSAGE ( "ComputeDirPaManagement : répertoires pour le calcul" );
3195 // Le répertoire du cas
3196 const char* nomDirCase = myCase->GetDirName();
3197 MESSAGE ( ". nomDirCase = " << nomDirCase );
3199 // Le sous-répertoire de l'iteration precedente
3201 const char* nomIterationParent = myIteration->GetIterParentName();
3202 HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterationParent];
3203 const char* nomDirItPa = myIterationParent->GetDirNameLoc();
3204 std::stringstream DirComputePa ;
3205 DirComputePa << nomDirCase << "/" << nomDirItPa;
3206 MESSAGE( ". nomDirItPa = " << nomDirItPa);
3207 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
3209 return CORBA::string_dup( DirComputePa.str().c_str() );
3211 //=============================================================================
3212 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
3213 //=============================================================================
3214 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3216 MESSAGE ( "... DriverTexteZone" );
3217 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3218 int numberOfZonesx2 = ListZone->length();
3221 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3223 std::string ZoneName = std::string((*ListZone)[iaux]);
3224 MESSAGE ( "... ZoneName = " << ZoneName);
3225 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
3226 ASSERT(!CORBA::is_nil(myZone));
3228 int ZoneType = myZone->GetType();
3229 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
3230 int TypeUse = atoi( TypeUsestr.c_str() );
3231 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
3232 NumZone = iaux/2 + 1 ;
3233 HOMARD::double_array* zone = myZone->GetCoords();
3234 if ( ZoneType == 2 || ( ZoneType>=11 && ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
3235 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
3236 else if ( ZoneType == 4 ) // Cas d une sphere
3237 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
3238 else if ( ZoneType == 5 || ( ZoneType>=31 && ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
3239 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
3240 else if ( ZoneType == 7 || ( ZoneType>=61 && ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
3241 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
3242 else { VERIFICATION("ZoneType est incorrect." == 0) ; }
3247 //=============================================================================
3248 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
3249 //=============================================================================
3250 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3252 MESSAGE ( "... DriverTexteField" );
3253 // Le fichier du champ
3254 char* FieldFile = myIteration->GetFieldFile();
3255 MESSAGE ( ". FieldFile = " << FieldFile );
3256 if (strlen(FieldFile) == 0)
3258 // GERALD -- QMESSAGE BOX
3259 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
3260 VERIFICATION("The file for the field is not given." == 0);
3262 // Les caracteristiques d'instants du champ de pilotage
3263 int TimeStep = myIteration->GetTimeStep();
3264 MESSAGE( ". TimeStep = " << TimeStep );
3265 int Rank = myIteration->GetRank();
3266 MESSAGE( ". Rank = " << Rank );
3267 // Les informations sur les champs
3268 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
3270 const char* FieldName = aInfosHypo->FieldName;
3272 int TypeThR = aInfosHypo->TypeThR;
3273 double ThreshR = aInfosHypo->ThreshR;
3274 int TypeThC = aInfosHypo->TypeThC;
3275 double ThreshC = aInfosHypo->ThreshC;
3276 // Saut entre mailles ou non ?
3277 int UsField = aInfosHypo->UsField;
3278 MESSAGE( ". UsField = " << UsField );
3279 // L'usage des composantes
3280 int UsCmpI = aInfosHypo->UsCmpI;
3281 MESSAGE( ". UsCmpI = " << UsCmpI );
3283 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
3286 HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
3287 int numberOfCompos = mescompo->length();
3288 MESSAGE( ". numberOfCompos = " << numberOfCompos );
3289 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
3291 std::string nomCompo = std::string((*mescompo)[NumeComp]);
3292 MESSAGE( "... nomCompo = " << nomCompo );
3293 myDriver->TexteCompo(NumeComp, nomCompo);
3297 //=============================================================================
3298 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
3299 // On ecrit dans l'ordre :
3300 // 1. la definition des frontieres
3301 // 2. les liens avec les groupes
3302 // 3. un entier resumant le type de comportement pour les frontieres
3303 //=============================================================================
3304 int HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
3306 MESSAGE ( "... DriverTexteBoundary" );
3307 // 1. Recuperation des frontieres
3308 std::list<std::string> ListeBoundaryTraitees ;
3309 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3310 int numberOfitems = ListBoundaryGroupType->length();
3311 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
3312 int BoundaryOption = 1 ;
3313 // 2. Parcours des frontieres pour ecrire leur description
3314 int NumBoundaryAnalytical = 0 ;
3315 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3317 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3318 MESSAGE ( "... BoundaryName = " << BoundaryName);
3319 // 2.1. La frontiere a-t-elle deja ete ecrite ?
3320 // Cela arrive quand elle est liee a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
3322 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3323 while (it != ListeBoundaryTraitees.end())
3325 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3326 if ( BoundaryName == *it ) { A_faire = 0 ; }
3329 // 2.2. Ecriture de la frontiere
3332 // 2.2.1. Caracteristiques de la frontiere
3333 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
3334 ASSERT(!CORBA::is_nil(myBoundary));
3335 int BoundaryType = myBoundary->GetType();
3336 MESSAGE ( "... BoundaryType = " << BoundaryType );
3337 // 2.2.2. Ecriture selon le type
3338 // 2.2.2.1. Cas d une frontiere CAO
3339 if (BoundaryType == -1)
3341 // const char* CAOFile = myBoundary->GetDataFile() ;
3342 // MESSAGE ( ". CAOFile = " << CAOFile );
3343 if ( BoundaryOption % 5 != 0 ) { BoundaryOption = BoundaryOption*5 ; }
3345 // 2.2.2.2. Cas d une frontiere discrete
3346 else if (BoundaryType == 0)
3348 const char* MeshName = myBoundary->GetMeshName() ;
3349 MESSAGE ( ". MeshName = " << MeshName );
3350 const char* MeshFile = myBoundary->GetDataFile() ;
3351 MESSAGE ( ". MeshFile = " << MeshFile );
3352 myDriver->TexteBoundaryDi( MeshName, MeshFile);
3353 if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
3355 // 2.2.2.3. Cas d une frontiere analytique
3358 NumBoundaryAnalytical++ ;
3359 HOMARD::double_array* coor = myBoundary->GetCoords();
3360 if (BoundaryType == 1) // Cas d un cylindre
3362 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3363 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3365 else if (BoundaryType == 2) // Cas d une sphere
3367 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
3368 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3370 else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
3372 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3373 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3375 else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
3377 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3378 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3380 else if (BoundaryType == 5) // Cas d un tore
3382 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3383 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3386 // 2.2.3. Memorisation du traitement
3387 ListeBoundaryTraitees.push_back( BoundaryName );
3390 // 3. Parcours des frontieres pour ecrire les liens avec les groupes
3391 NumBoundaryAnalytical = 0 ;
3392 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3394 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3395 MESSAGE ( "... BoundaryName = " << BoundaryName);
3396 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
3397 ASSERT(!CORBA::is_nil(myBoundary));
3398 int BoundaryType = myBoundary->GetType();
3399 MESSAGE ( "... BoundaryType = " << BoundaryType );
3400 // 3.1. Recuperation du nom du groupe
3401 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
3402 MESSAGE ( "... GroupName = " << GroupName);
3403 // 3.2. Cas d une frontiere CAO
3404 if ( BoundaryType == -1 )
3406 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryCAOGr ( GroupName ) ; }
3408 // 3.3. Cas d une frontiere discrete
3409 else if ( BoundaryType == 0 )
3411 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
3413 // 3.4. Cas d une frontiere analytique
3416 NumBoundaryAnalytical++ ;
3417 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
3420 // 4. Ecriture de l'option finale
3421 myDriver->TexteBoundaryOption(BoundaryOption);
3423 return BoundaryOption ;
3425 //=============================================================================
3426 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3427 //=============================================================================
3428 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3430 MESSAGE ( "... DriverTexteFieldInterp" );
3431 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3432 MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3433 if (TypeFieldInterp != 0)
3435 // Le fichier des champs
3436 char* FieldFile = myIteration->GetFieldFile();
3437 MESSAGE ( ". FieldFile = " << FieldFile );
3438 if (strlen(FieldFile) == 0)
3440 // GERALD -- QMESSAGE BOX
3441 VERIFICATION("The file for the field is not given." == 0);
3444 const char* MeshFile = myIteration->GetMeshFile();
3445 myDriver->TexteFieldInterp(FieldFile, MeshFile);
3448 // Interpolation de tous les champs
3449 if ( TypeFieldInterp == 1 )
3451 myDriver->TexteFieldInterpAll();
3453 // Interpolation de certains champs
3454 else if (TypeFieldInterp == 2)
3456 // Les champs et leurs instants pour l'iteration
3457 HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3458 int numberOfFieldsx3 = ListFieldTSR->length();
3459 MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3460 // Les champs pour l'hypothese
3461 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3462 int numberOfFieldsx2 = ListField->length();
3463 MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3464 // On parcourt tous les champs de l'hypothese
3466 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3469 std::string FieldName = std::string((*ListField)[iaux]) ;
3470 // Le type d'interpolation
3471 std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3472 MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3473 // On cherche ?? savoir si des instants ont ??t?? pr??cis??s pour cette it??ration
3475 for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3478 std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3479 MESSAGE( "..... FieldName2 = " << FieldName2 );
3480 // Quand c'est le bon champ, on ecrit le pas de temps
3481 if ( FieldName == FieldName2 )
3485 std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3486 // Le numero d'ordre
3487 std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3488 MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3490 int TimeStep = atoi( TimeStepstr.c_str() );
3491 int Rank = atoi( Rankstr.c_str() );
3492 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3496 // Si aucun instant n'a été défini
3500 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3508 //===========================================================================
3509 //===========================================================================
3512 //===========================================================================
3513 //===========================================================================
3515 //===========================================================================
3516 //===========================================================================
3517 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::SObject_ptr theSObject,
3518 CORBA::Object_ptr theObject,
3519 const char* theName)
3521 MESSAGE("PublishInStudy pour " << theName);
3522 SALOMEDS::SObject_var aResultSO;
3523 if (CORBA::is_nil(myStudy))
3525 SALOME::ExceptionStruct es;
3526 es.type = SALOME::BAD_PARAM;
3527 es.text = "Invalid study context";
3528 throw SALOME::SALOME_Exception(es);
3532 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3533 // Rq : Iteration est publiee ailleurs
3534 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3535 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
3536 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3537 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3538 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3542 // Controle de la non publication d'un objet de meme nom
3543 if ( (!aBoundary->_is_nil()) || (!aHypo->_is_nil()) || (!aYACS->_is_nil()) || (!aZone->_is_nil()) )
3545 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(theName, ComponentDataType());
3546 if (listSO->length() >= 1)
3548 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3549 aResultSO = listSO[0];
3550 return aResultSO._retn();
3554 // Caracteristiques de l'etude
3555 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
3556 aStudyBuilder->NewCommand();
3557 if(!aBoundary->_is_nil())
3558 aResultSO = PublishBoundaryInStudy(aStudyBuilder, aBoundary, theName);
3559 else if(!aCase->_is_nil())
3560 aResultSO = PublishCaseInStudy(aStudyBuilder, aCase, theName);
3561 else if(!aHypo->_is_nil())
3562 aResultSO = PublishHypotheseInStudy(aStudyBuilder, aHypo, theName);
3563 else if(!aYACS->_is_nil())
3564 aResultSO = PublishYACSInStudy(aStudyBuilder, aYACS, theName);
3565 else if(!aZone->_is_nil())
3566 aResultSO = PublishZoneInStudy(aStudyBuilder, aZone, theName);
3568 aStudyBuilder->CommitCommand();
3570 return aResultSO._retn();
3572 //=============================================================================
3573 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy( SALOMEDS::StudyBuilder_var aStudyBuilder,
3574 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3576 MESSAGE("PublishBoundaryStudy pour "<<theName);
3577 SALOMEDS::SObject_var aResultSO;
3579 // Caracteristique de la Boundary
3580 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[theName];
3582 // On recupere le module pere dans l etude
3583 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3584 if (theFatherHomard->_is_nil())
3586 MESSAGE("theFatherHomard->_is_nil()");
3587 return aResultSO._retn();
3590 // On ajoute la categorie des boundarys dans l etude si necessaire
3591 if ( _tag_boun == 0 )
3594 _tag_boun = _tag_gene ;
3596 MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3597 SALOMEDS::SObject_var aSObject;
3598 if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3600 MESSAGE("Ajout de la categorie des boundarys");
3601 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3602 PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3604 else { MESSAGE("La categorie des boundarys existe deja."); }
3606 CORBA::Long BoundaryType = myBoundary->GetType();
3607 // MESSAGE("BoundaryType : "<<BoundaryType);
3610 switch (BoundaryType)
3613 { value = "BoundaryCAOHomard" ;
3614 icone = "geometry.png" ;
3618 { value = "BoundaryDiHomard" ;
3619 icone = "mesh_tree_mesh.png" ;
3623 { value = "BoundaryAnHomard" ;
3624 icone = "cylinderpointvector_2.png" ;
3628 { value = "BoundaryAnHomard" ;
3629 icone = "spherepoint_2.png" ;
3633 { value = "BoundaryAnHomard" ;
3634 icone = "conepointvector.png" ;
3638 { value = "BoundaryAnHomard" ;
3639 icone = "conedxyz.png" ;
3643 { value = "BoundaryAnHomard" ;
3644 icone = "toruspointvector.png" ;
3648 aResultSO = aStudyBuilder->NewObject(aSObject);
3649 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3650 return aResultSO._retn();
3652 //=============================================================================
3653 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3654 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3656 MESSAGE("PublishCaseInStudy pour "<<theName);
3657 SALOMEDS::SObject_var aResultSO;
3659 if (CORBA::is_nil(theObject)) {
3660 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3661 return aResultSO._retn();
3663 if (myStudy->_is_nil()) {
3664 MESSAGE("HOMARD_Gen_i::myStudy->_is_nil()");
3665 return aResultSO._retn();
3668 // On recupere le module pere dans l etude
3669 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3670 if (theFatherHomard->_is_nil())
3672 MESSAGE("theFatherHomard->_is_nil()");
3673 return aResultSO._retn();
3677 MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3678 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3679 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3680 _orb->object_to_string(theObject) ) ;
3682 return aResultSO._retn();
3684 //=============================================================================
3685 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3686 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3688 MESSAGE("PublishHypotheseInStudy pour "<<theName);
3689 SALOMEDS::SObject_var aResultSO;
3691 // On recupere le module pere dans l etude
3692 // On ajoute la categorie des hypotheses dans l etude si necessaire
3693 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3694 if (theFatherHomard->_is_nil())
3696 MESSAGE("theFatherHomard->_is_nil()");
3697 return aResultSO._retn();
3700 // On ajoute la categorie des hypotheses dans l etude si necessaire
3701 SALOMEDS::SObject_var aSObject;
3702 if ( _tag_hypo == 0 )
3705 _tag_hypo = _tag_gene ;
3707 MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3708 if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3710 MESSAGE("Ajout de la categorie des hypotheses");
3711 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3712 PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3714 else { MESSAGE("La categorie des hypotheses existe deja."); }
3716 // Creation du resultat dans l'etude
3717 aResultSO = aStudyBuilder->NewObject(aSObject);
3718 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3720 return aResultSO._retn();
3722 //=============================================================================
3723 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3724 HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3726 MESSAGE("PublishYACSInStudy pour "<<theName);
3727 SALOMEDS::SObject_var aResultSO;
3729 // On recupere le module pere dans l etude
3730 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3731 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3732 if (theFatherHomard->_is_nil())
3734 MESSAGE("theFatherHomard->_is_nil()");
3735 return aResultSO._retn();
3737 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3738 if ( _tag_yacs == 0 )
3741 _tag_yacs = _tag_gene ;
3743 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3744 SALOMEDS::SObject_var aSObject;
3745 if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3747 MESSAGE("Ajout de la categorie des schemas YACS");
3748 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3749 PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3751 else { MESSAGE("La categorie des schemas YACS existe deja."); }
3753 // Creation du resultat dans l'etude
3754 aResultSO = aStudyBuilder->NewObject(aSObject);
3755 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3757 return aResultSO._retn();
3760 //=============================================================================
3761 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3762 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3764 MESSAGE("PublishZoneStudy pour "<<theName);
3765 SALOMEDS::SObject_var aResultSO;
3766 if (CORBA::is_nil(theObject))
3768 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3769 return aResultSO._retn();
3771 if (myStudy->_is_nil())
3773 MESSAGE("PublishZoneInStudy : myStudy->_is_nil()");
3774 return aResultSO._retn();
3776 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3777 if (theFatherHomard->_is_nil())
3779 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3780 return aResultSO._retn();
3783 // Caracteristique de la zone
3784 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[theName];
3785 CORBA::Long ZoneType = myZone->GetType();
3787 // On ajoute la categorie des zones dans l etude si necessaire
3788 if ( _tag_zone == 0 )
3791 _tag_zone = _tag_gene ;
3793 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3794 SALOMEDS::SObject_var aSObject;
3795 if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3797 MESSAGE("Ajout de la categorie des zones");
3798 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3799 PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3801 else { MESSAGE("La categorie des zones existe deja."); }
3803 aResultSO = aStudyBuilder->NewObject(aSObject);
3812 { icone = "boxdxy_2.png" ;
3816 { icone = "boxdxyz_2.png" ;
3824 { icone = "disk_2.png" ;
3828 { icone = "spherepoint_2.png" ;
3832 { icone = "cylinderpointvector_2.png" ;
3840 { icone = "diskwithhole_2.png" ;
3844 { icone = "pipe_2.png" ;
3848 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3850 return aResultSO._retn();
3852 //===========================================================================
3853 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3854 SALOMEDS::SObject_var aResultSO,
3855 const char* name, const char* comment, const char* icone, const char* ior)
3857 MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3858 // MESSAGE("icone = "<<icone);
3859 // MESSAGE("ior = "<<ior);
3860 SALOMEDS::GenericAttribute_var anAttr ;
3864 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3865 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3866 aNameAttrib->SetValue(name);
3869 // Ajout du commentaire
3870 if ( comment != NULL )
3872 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3873 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3874 aCommentAttrib->SetValue(comment);
3878 if ( icone != NULL )
3880 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3881 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3882 aPixmap->SetPixMap(icone);
3888 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3889 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3890 anIOR->SetValue(ior);
3894 //=====================================================================================
3895 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3897 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3899 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[CaseName];
3900 ASSERT(!CORBA::is_nil(myCase));
3901 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3902 ASSERT(!CORBA::is_nil(aCaseSO));
3904 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
3905 ASSERT(!CORBA::is_nil(myBoundary));
3906 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3907 ASSERT(!CORBA::is_nil(aBoundarySO));
3909 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
3911 aStudyBuilder->NewCommand();
3913 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3914 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3915 // aStudyBuilder->RemoveReference(aSubSO);
3917 aStudyBuilder->CommitCommand();
3920 //=====================================================================================
3921 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3923 MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3925 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
3926 ASSERT(!CORBA::is_nil(myYACS));
3927 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3928 ASSERT(!CORBA::is_nil(aYACSSO));
3930 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[CaseName];
3931 ASSERT(!CORBA::is_nil(myCase));
3932 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3933 ASSERT(!CORBA::is_nil(aCaseSO));
3935 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
3937 aStudyBuilder->NewCommand();
3939 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3940 aStudyBuilder->Addreference(aSubSO, aCaseSO);
3942 aStudyBuilder->CommitCommand();
3945 //=============================================================================
3946 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3947 // Option = 0 : fichier issu d'une importation
3948 // Option = 1 : fichier issu d'une execution HOMARD
3950 MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3951 if (CORBA::is_nil(myStudy))
3953 SALOME::ExceptionStruct es;
3954 es.type = SALOME::BAD_PARAM;
3955 es.text = "Invalid study context";
3956 throw SALOME::SALOME_Exception(es);
3960 // Le module SMESH est-il actif ?
3961 SALOMEDS::SObject_var aSmeshSO = myStudy->FindComponent("SMESH");
3963 if (!CORBA::is_nil(aSmeshSO))
3965 // On verifie que le fichier n est pas deja publie
3966 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aSmeshSO);
3967 for (; aIter->More(); aIter->Next())
3969 SALOMEDS::SObject_var aSO = aIter->Value();
3970 SALOMEDS::GenericAttribute_var aGAttr;
3971 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3973 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3974 CORBA::String_var value=anAttr->Value();
3975 if (strcmp((const char*)value,NomFich) == 0)
3977 MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3978 // Pour un fichier importe, on ne republie pas
3979 if ( Option == 0 ) { return; }
3980 // Pour un fichier calcule, on commence par faire la depublication
3983 MESSAGE ( "PublishResultInSmesh : depublication" );
3984 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3985 CORBA::String_var value2=anAttr2->Value();
3986 std::string MeshName = string(value2) ;
3987 MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3988 DeleteResultInSmesh(NomFich, MeshName) ;
3995 // On enregistre le fichier
3996 MESSAGE( "Enregistrement du fichier");
3998 SMESH::SMESH_Gen_var aSmeshEngine = this->retrieveSMESHInst();
4000 ASSERT(!CORBA::is_nil(aSmeshEngine));
4001 aSmeshEngine->UpdateStudy();
4002 SMESH::DriverMED_ReadStatus theStatus;
4003 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
4005 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
4006 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
4007 for (int i = 0; i < mesMaillages->length(); i++)
4009 MESSAGE( ". Mise a jour des attributs du maillage");
4010 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
4011 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
4012 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4013 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
4014 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
4015 anAttr->SetValue(NomFich);
4016 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
4017 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
4019 if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
4020 else { icone = "mesh_tree_mesh.png" ; }
4021 anAttr2->SetPixMap( icone );
4025 //=============================================================================
4026 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
4028 MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
4029 if (CORBA::is_nil(myStudy))
4031 SALOME::ExceptionStruct es;
4032 es.type = SALOME::BAD_PARAM;
4033 es.text = "Invalid study context";
4034 throw SALOME::SALOME_Exception(es);
4038 // Le module SMESH est-il actif ?
4039 SALOMEDS::SObject_var aSmeshSO = myStudy->FindComponent("SMESH");
4041 if (CORBA::is_nil(aSmeshSO))
4045 // On verifie que le fichier est deja publie
4046 SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
4047 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aSmeshSO);
4048 for (; aIter->More(); aIter->Next())
4050 SALOMEDS::SObject_var aSO = aIter->Value();
4051 SALOMEDS::GenericAttribute_var aGAttr;
4052 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
4054 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
4055 CORBA::String_var value=anAttr->Value();
4056 if (strcmp((const char*)value,NomFich.c_str()) == 0)
4058 if (aSO->FindAttribute(aGAttr,"AttributeName"))
4060 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
4061 CORBA::String_var value2=anAttr2->Value();
4062 if (strcmp((const char*)value2,MeshName.c_str()) == 0)
4064 myBuilder->RemoveObjectWithChildren( aSO ) ;
4072 //=============================================================================
4073 void HOMARD_Gen_i::PublishMeshIterInSmesh(const char* NomIter)
4075 MESSAGE( "PublishMeshIterInSmesh " << NomIter);
4076 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIter];
4078 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
4079 if (CORBA::is_nil(myIteration))
4081 SALOME::ExceptionStruct es;
4082 es.type = SALOME::BAD_PARAM;
4083 es.text = "Invalid iterationStudy Object";
4084 throw SALOME::SALOME_Exception(es);
4087 const char* MeshFile = myIteration->GetMeshFile() ;
4088 const char* MeshName = myIteration->GetMeshName() ;
4089 CORBA::Long Option = -1 ;
4090 int etat = myIteration->GetState();
4091 // Iteration initiale
4092 if ( etat <= 0 ) { Option = 0 ; }
4093 // ou iteration calculee
4094 else if ( etat == 2 ) { Option = 1 ; }
4095 // Publication effective apres menage eventuel
4098 DeleteResultInSmesh(MeshFile, MeshName) ;
4099 PublishResultInSmesh(MeshFile, Option) ;
4103 //=============================================================================
4104 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
4106 // MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
4107 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIter];
4109 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
4110 if (CORBA::is_nil(myIteration))
4112 SALOME::ExceptionStruct es;
4113 es.type = SALOME::BAD_PARAM;
4114 es.text = "Invalid iterationStudy Object";
4115 throw SALOME::SALOME_Exception(es);
4119 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4121 aStudyBuilder->NewCommand();
4123 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
4124 // Pour les fichiers med, on affiche une icone de maillage
4125 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
4126 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
4128 std::string ior = " " ;
4129 if ( Commentaire[0] == 'M' )
4130 { icone = "med.png" ; }
4132 { icone = "texte_2.png" ; }
4133 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
4135 aStudyBuilder->CommitCommand();
4138 //=============================================================================
4139 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
4141 // MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
4142 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
4144 SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
4145 if (CORBA::is_nil(myYACS))
4147 SALOME::ExceptionStruct es;
4148 es.type = SALOME::BAD_PARAM;
4149 es.text = "Invalid YACSStudy Object";
4150 throw SALOME::SALOME_Exception(es);
4154 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4156 aStudyBuilder->NewCommand();
4158 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
4159 std::string icone = "texte_2.png" ;
4160 std::string ior = " " ;
4161 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
4163 aStudyBuilder->CommitCommand();
4166 //=============================================================================
4167 //=============================================================================
4169 //=============================================================================
4170 //=============================================================================
4171 //=============================================================================
4172 // Creation d'un schema YACS
4173 // nomCas : nom du cas a traiter
4174 // FileName : nom du fichier contenant le script de lancement du calcul
4175 // DirName : le répertoire de lancement des calculs du schéma
4176 //=============================================================================
4177 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
4179 MESSAGE ( "CreateYACSSchema : Schema YACS " << nomYACS );
4180 MESSAGE ( ". nomCas : " << nomCas);
4181 MESSAGE ( ". ScriptFile : " << ScriptFile);
4182 MESSAGE ( ". DirName : " << DirName);
4183 MESSAGE ( ". MeshFile : " << MeshFile);
4185 // A. Controle du nom :
4186 if ((myStudyContext._mesYACSs).find(nomYACS) != (myStudyContext._mesYACSs).end())
4188 SALOME::ExceptionStruct es;
4189 es.type = SALOME::BAD_PARAM;
4190 es.text = "This schema YACS has already been defined.";
4191 throw SALOME::SALOME_Exception(es);
4195 // B. Creation de l'objet
4196 HOMARD::HOMARD_YACS_var myYACS = newYACS();
4197 if (CORBA::is_nil(myYACS))
4199 SALOME::ExceptionStruct es;
4200 es.type = SALOME::BAD_PARAM;
4201 es.text = "Unable to create the schema YACS";
4202 throw SALOME::SALOME_Exception(es);
4205 myYACS->SetName( nomYACS ) ;
4207 // C. Enregistrement
4208 myStudyContext._mesYACSs[nomYACS] = myYACS;
4210 SALOMEDS::SObject_var aSO;
4211 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myYACS, nomYACS);
4213 PublishCaseUnderYACS(nomYACS, nomCas);
4215 // D. Caracterisation
4217 myYACS->SetDirName( DirName ) ;
4218 myYACS->SetMeshFile( MeshFile ) ;
4219 myYACS->SetScriptFile( ScriptFile ) ;
4220 myYACS->SetCaseName( nomCas ) ;
4223 // D.2.1. Type constant
4224 myYACS->SetType( 1 ) ;
4225 // D.2.2. Convergence
4226 defaut_i = GetYACSMaxIter() ;
4227 myYACS->SetMaxIter( defaut_i ) ;
4228 defaut_i = GetYACSMaxNode() ;
4229 myYACS->SetMaxNode( defaut_i ) ;
4230 defaut_i = GetYACSMaxElem() ;
4231 myYACS->SetMaxElem( defaut_i ) ;
4232 // D.3. Fichier de sauvegarde dans le répertoire du cas
4233 HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
4234 std::string dirnamecase = caseyacs->GetDirName() ;
4235 std::string XMLFile ;
4236 XMLFile = dirnamecase + "/schema.xml" ;
4237 myYACS->SetXMLFile( XMLFile.c_str() ) ;
4239 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
4241 //=============================================================================
4242 // Ecriture d'un schema YACS
4243 //=============================================================================
4244 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
4246 MESSAGE ( "YACSWrite : Ecriture de " << nomYACS );
4247 // Le répertoire du cas
4248 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
4249 ASSERT(!CORBA::is_nil(myYACS));
4250 // Le nom du fichier du schema
4251 std::string XMLFile ;
4252 XMLFile = myYACS->GetXMLFile() ;
4254 int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
4258 //=============================================================================
4259 // Ecriture d'un schema YACS sur un fichier donne
4260 //=============================================================================
4261 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
4263 MESSAGE ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
4270 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
4271 ASSERT(!CORBA::is_nil(myYACS));
4272 // B.2. Les caracteristiques
4273 std::string DirName = myYACS->GetDirName() ;
4274 std::string MeshFile = myYACS->GetMeshFile() ;
4275 std::string ScriptFile = myYACS->GetScriptFile() ;
4276 // B.3. Les caracteristiques de convergence
4277 int MaxIter = myYACS->GetMaxIter() ;
4278 int MaxNode = myYACS->GetMaxNode() ;
4279 int MaxElem = myYACS->GetMaxElem() ;
4283 const char* nomCas = myYACS->GetCaseName();
4284 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
4285 ASSERT(!CORBA::is_nil(myCase));
4286 // C.2. Les instructions python associees au cas
4287 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4288 std::string pythonCas = dumpCorbaCase.in();
4289 MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
4291 // D. Les iterations
4292 // D.1. L'iteration initiale
4293 HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
4294 std::string Iter0Name = myCase->GetIter0Name() ;
4295 MESSAGE (". Iter0Name = " << Iter0Name);
4296 std::string MeshName = Iter0->GetMeshName();
4297 MESSAGE (". MeshName = " << MeshName);
4298 // D.2. L'iteration numero 1
4299 HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
4300 int numberOfIter = maListe->length();
4301 if ( numberOfIter > 1 )
4303 MESSAGE (". numberOfIter = " << numberOfIter);
4304 SALOME::ExceptionStruct es ;
4305 es.type = SALOME::BAD_PARAM;
4306 std::string text = "Une seule iteration est permise." ;
4307 es.text = CORBA::string_dup(text.c_str());
4308 throw SALOME::SALOME_Exception(es);
4311 std::string Iter1Name = std::string((*maListe)[0]);
4312 MESSAGE ("... Iter1Name = " << Iter1Name);
4313 HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
4314 // D.3. Les instructions python associees a l'iteration
4315 CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
4316 std::string pythonIter = dumpCorbaIter.in();
4317 MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
4319 // E. L'hypothese pour passer de l'iteration initiale a la suivante
4320 // E.1. La structure
4321 std::string nomHypo = Iter1->GetHypoName();
4322 MESSAGE (". nomHypo = " << nomHypo);
4323 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
4324 ASSERT(!CORBA::is_nil(myHypo));
4325 // E.2. Les caracteristiques de l'adaptation
4326 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
4327 ASSERT(ListTypes->length() == 3);
4328 int TypeAdap = (*ListTypes)[0];
4329 // int TypeRaff = (*ListTypes)[1];
4330 // int TypeDera = (*ListTypes)[2];
4331 // E.3. Les instructions python associees a l'hypothese
4332 CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
4333 std::string pythonHypo = dumpCorbaHypo.in();
4334 MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
4336 // F. Le fichier du schema de reference
4337 // HOMARD_ROOT_DIR : répertoire ou se trouve le module HOMARD
4338 std::string XMLFile_base ;
4339 if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
4342 SALOME::ExceptionStruct es ;
4343 es.type = SALOME::BAD_PARAM;
4344 std::string text = "HOMARD_ROOT_DIR est inconnu." ;
4345 es.text = CORBA::string_dup(text.c_str());
4346 throw SALOME::SALOME_Exception(es);
4349 XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
4351 MESSAGE("XMLFile_base ="<<XMLFile_base);
4353 // G. Lecture du schema de reference et insertion des données propres au fil de la rencontre des mots-cles
4354 YACSDriver* myDriver = new YACSDriver(XMLFile, DirName, _LangueShort);
4355 std::ifstream fichier( XMLFile_base.c_str() );
4356 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
4358 // G.1. Lecture du schema de reference et insertion des données propres au fil de la rencontre des mots-cles
4359 std::string ligne; // variable contenant chaque ligne lue
4360 std::string mot_cle;
4361 while ( std::getline( fichier, ligne ) )
4363 // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
4364 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
4365 ligne_bis >> mot_cle ;
4366 // G.1.2. Le maillage initial
4367 if ( mot_cle == "DataInit_MeshFile" )
4368 { myDriver->Texte_DataInit_MeshFile(MeshFile); }
4369 // G.1.3. Le script de lancement
4370 else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
4371 { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
4372 // G.1.4. Les options du cas
4373 else if ( mot_cle == "Iter_1_Case_Options" )
4374 { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
4375 // G.1.5. Execution de HOMARD : le répertoire du cas
4376 else if ( mot_cle == "HOMARD_Exec_DirName" )
4377 { myDriver->Texte_HOMARD_Exec_DirName(); }
4378 // G.1.6. Execution de HOMARD : le nom du maillage
4379 else if ( mot_cle == "HOMARD_Exec_MeshName" )
4381 myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
4383 if ( _LangueShort == "fr" ) { node = "Boucle_de_convergence.Alternance_Calcul_HOMARD" ; }
4384 else { node = "Convergence_Loop.Alternation_Computation_HOMARD" ; }
4385 node += ".Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
4386 myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
4388 // G.1.7. Execution de HOMARD : les options de l'hypothese
4389 else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
4390 { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ; }
4391 // G.1.8. Execution de HOMARD : les options de l'iteration
4392 else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
4393 { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ; }
4394 // G.1.9. a. Creation eventuelles des zones et frontieres
4396 else if ( mot_cle == "Iter_1" )
4398 std::string texte_control = "" ;
4399 if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
4400 texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
4401 texte_control += myDriver->Texte_Iter_1_control() ;
4402 myDriver->TexteAdd(texte_control);
4404 // G.1.10. Les tests de convergence
4405 else if ( mot_cle == "Analyse_Test_Convergence" )
4406 { myDriver->TexteAnalyse_Test_Convergence(MaxIter, MaxNode, MaxElem); }
4407 // G.1.11. Les parametres
4408 else if ( mot_cle == "PARAMETRES" )
4409 { myDriver->TexteAddParametres(); }
4410 // G.1.n. La ligne est recopiee telle quelle
4411 else { myDriver->TexteAdd(ligne); }
4413 // G.2. Ecriture du texte dans le fichier
4415 { myDriver->CreeFichier(); }
4419 SALOME::ExceptionStruct es;
4420 es.type = SALOME::BAD_PARAM;
4421 std::string text = "The reference file for the YACS schema cannot be read." ;
4422 es.text = CORBA::string_dup(text.c_str());
4423 throw SALOME::SALOME_Exception(es);
4428 // H. Publication du fichier dans l'arbre
4430 std::string Commentaire = "xml" ;
4431 PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
4435 //=============================================================================
4436 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
4437 //=============================================================================
4438 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
4440 MESSAGE ( "YACSDriverTexteZone" );
4441 // A. Les zones associees a cette hypothese
4442 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
4443 int numberOfZonesx2 = ListZone->length();
4445 // B. Parcours des zones
4446 std::string texte_control ;
4447 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
4449 // 1. Reperage de la zone
4450 std::string ZoneName = std::string((*ListZone)[iaux]);
4451 MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
4452 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
4453 ASSERT(!CORBA::is_nil(myZone));
4454 // 2. Les instructions python associees a la zone
4455 // La premiere ligne est un commentaire a eliminer
4456 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4457 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4458 std::string pythonStructure_0 = dumpCorbaZone.in();
4459 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4460 std::istringstream tout (pythonStructure_0) ;
4462 std::string pythonStructure ;
4463 while ( std::getline( tout, ligne ) )
4464 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4465 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4466 // 3. Decodage du nom du service
4467 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4468 MESSAGE ( "... methode = " << methode);
4469 // 4. Mise en place des instructions
4470 int ZoneType = myZone->GetType();
4471 MESSAGE ( "... ZoneType = " << ZoneType);
4472 std::string texte_control_0 ;
4473 texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
4474 texte_control += texte_control_0 ;
4479 return texte_control ;
4481 //=============================================================================
4482 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4483 //=============================================================================
4484 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4486 MESSAGE ( "YACSDriverTexteBoundary" );
4487 // A. Les frontieres associees au cas
4488 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4489 int numberOfitems = ListBoundaryGroupType->length();
4491 // B. Parcours des frontieres
4492 std::string texte_control ;
4493 std::list<std::string> ListeBoundaryTraitees ;
4494 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4496 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4497 MESSAGE ( "... BoundaryName = " << BoundaryName);
4498 // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4499 // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4501 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4502 while (it != ListeBoundaryTraitees.end())
4504 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4505 if ( BoundaryName == *it ) { A_faire = 0 ; }
4510 // 1. Caracteristiques de la frontiere
4511 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
4512 ASSERT(!CORBA::is_nil(myBoundary));
4513 // 2. Les instructions python associees a la frontiere
4514 // La premiere ligne est un commentaire a eliminer
4515 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4516 CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4517 std::string pythonStructure_0 = dumpCorbaBoundary.in();
4518 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4519 std::istringstream tout (pythonStructure_0) ;
4521 std::string pythonStructure ;
4522 while ( std::getline( tout, ligne ) )
4523 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4524 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4525 // 3. Decodage du nom du service
4526 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4527 MESSAGE ( "... methode = " << methode);
4528 // 4. Mise en place des instructions
4529 int BoundaryType = myBoundary->GetType();
4530 MESSAGE ( "... BoundaryType = " << BoundaryType);
4531 const char* MeshName ;
4532 const char* DataFile ;
4533 if (BoundaryType == -1)
4535 DataFile = myBoundary->GetDataFile() ;
4536 MESSAGE ( ". CAOFile = " << DataFile );
4538 else if (BoundaryType == 0)
4540 MeshName = myBoundary->GetMeshName() ;
4541 MESSAGE ( ". MeshName = " << MeshName );
4542 DataFile = myBoundary->GetDataFile() ;
4543 MESSAGE ( ". MeshFile = " << DataFile );
4545 std::string texte_control_0 ;
4546 texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName, MeshName, DataFile );
4547 texte_control += texte_control_0 ;
4548 // 5. Memorisation du traitement
4549 ListeBoundaryTraitees.push_back( BoundaryName );
4553 return texte_control ;
4556 //=============================================================================
4557 //=============================================================================
4558 // Next functions are inherited from SALOMEDS::Driver interface
4559 //=============================================================================
4560 //=============================================================================
4561 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4563 CORBA::Boolean isMultiFile)
4565 MESSAGE ("Save for theURL = "<< theURL);
4566 SALOMEDS::TMPFile_var aStreamFile;
4568 // get temporary directory name
4569 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4571 StudyContext& context = myStudyContext;
4573 // HOMARD data file name
4574 std::string aFileName = "";
4576 aFileName = SALOMEDS_Tool::GetNameFromPath(Kernel_Utils::encode(myStudy->URL()));
4577 aFileName += "_HOMARD.dat";
4579 // initialize sequence of file names
4580 SALOMEDS_Tool::ListOfFiles aFileSeq;
4581 aFileSeq.reserve(1);
4582 aFileSeq.push_back(CORBA::string_dup(aFileName.c_str())) ;
4584 // get full path to the data file
4585 aFileName = tmpDir + aFileName;
4589 std::ofstream f(aFileName.c_str());
4591 // clear temporary id map
4592 context._idmap.clear();
4597 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4598 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4599 HOMARD::HOMARD_Cas_var aCas = it_case->second;
4600 PortableServer::ServantBase_var aServant = GetServant(aCas);
4601 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4603 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4604 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4608 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4609 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4610 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4611 PortableServer::ServantBase_var aServant = GetServant(aZone);
4612 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4614 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4615 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4618 // -> save hypotheses
4619 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4620 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4621 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4622 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4623 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4625 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4626 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4629 // -> save iterations
4630 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4631 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4632 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4633 PortableServer::ServantBase_var aServant = GetServant(aIter);
4634 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4636 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4637 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4640 // -> save boundaries
4641 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4642 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4643 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4644 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4645 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4646 if (aBoundaryServant) {
4647 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4648 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4652 MESSAGE ("close file");
4655 // put temporary files to the stream
4656 MESSAGE ("put temporary files to the stream");
4657 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq, isMultiFile);
4659 // remove temporary files
4660 MESSAGE ("remove temporary files");
4661 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq, true);
4663 // return data stream
4664 MESSAGE ("return data stream");
4665 return aStreamFile._retn();
4668 //===========================================================================
4669 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4671 CORBA::Boolean isMultiFile)
4673 // No specific ASCII persistence
4674 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4675 return aStreamFile._retn();
4678 //===========================================================================
4679 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4680 const SALOMEDS::TMPFile& theStream,
4682 CORBA::Boolean isMultiFile)
4684 MESSAGE ("Load pour theURL = "<< theURL);
4686 // set current study
4687 if (myStudy->_is_nil())
4690 // get temporary directory name
4691 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4693 // Convert the stream into sequence of files to process
4694 SALOMEDS_Tool::ListOfFiles aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4697 // HOMARD data file name
4698 std::string aFileName = "";
4700 aFileName = SALOMEDS_Tool::GetNameFromPath(Kernel_Utils::encode(myStudy->URL()));
4701 aFileName = tmpDir + aFileName + "_HOMARD.dat";
4703 StudyContext& context = myStudyContext;
4707 std::ifstream f(aFileName.c_str());
4710 context._mesCas.clear();
4711 context._mesHypotheses.clear();
4712 context._mesIterations.clear();
4713 context._mesZones.clear();
4714 context._mesBoundarys.clear();
4715 context._idmap.clear();
4721 std::getline(f, line);
4722 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4723 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4724 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4725 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4726 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4727 std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4728 if (line.substr(0, bounSignature.size()) == bounSignature) {
4729 // re-create boundary
4730 MESSAGE ("Recreation de la frontiere" );
4731 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4732 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4733 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4734 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4735 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4736 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4739 else if (line.substr(0, caseSignature.size()) == caseSignature) {
4741 MESSAGE ("Recreation du cas" );
4742 HOMARD::HOMARD_Cas_var aCase = newCase();
4743 PortableServer::ServantBase_var aServant = GetServant(aCase);
4744 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4745 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4746 context._mesCas[aCase->GetName()] = aCase;
4747 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4750 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4751 // re-create hypothesis
4752 MESSAGE ("Recreation de l hypothese" );
4753 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4754 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4755 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4756 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4757 context._mesHypotheses[aHypo->GetName()] = aHypo;
4758 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4761 else if (line.substr(0, iterSignature.size()) == iterSignature) {
4762 // re-create iteration
4763 MESSAGE ("Recreation de l'iteration" );
4764 HOMARD::HOMARD_Iteration_var aIter = newIteration();
4765 PortableServer::ServantBase_var aServant = GetServant(aIter);
4766 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4767 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4768 context._mesIterations[aIter->GetName()] = aIter;
4769 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4772 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4773 MESSAGE ("Recreation de la zone" );
4775 HOMARD::HOMARD_Zone_var aZone = newZone();
4776 PortableServer::ServantBase_var aServant = GetServant(aZone);
4777 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4778 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4779 context._mesZones[aZone->GetName()] = aZone;
4780 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4783 else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4784 MESSAGE ("Recreation du schema YACS" );
4786 HOMARD::HOMARD_YACS_var aYACS = newYACS();
4787 PortableServer::ServantBase_var aServant = GetServant(aYACS);
4788 HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4789 if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4790 context._mesYACSs[aYACS->GetName()] = aYACS;
4791 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4800 // Remove temporary files created from the stream
4802 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq, true);
4807 //===========================================================================
4808 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4809 const SALOMEDS::TMPFile& theStream,
4811 CORBA::Boolean isMultiFile)
4813 // No specific ASCII persistence
4814 return Load(theComponent, theStream, theURL, isMultiFile);
4817 //===========================================================================
4818 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4822 //===========================================================================
4823 char* HOMARD_Gen_i::ComponentDataType()
4825 return CORBA::string_dup("HOMARD");
4828 //===========================================================================
4829 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4830 const char* IORString,
4831 CORBA::Boolean isMultiFile,
4832 CORBA::Boolean isASCII)
4834 CORBA::String_var aString("");
4835 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4836 StudyContext context = myStudyContext;
4837 CORBA::Object_var anObj = _orb->string_to_object(IORString);
4838 if (!CORBA::is_nil(anObj)) {
4839 PortableServer::ServantBase_var aServant = GetServant(anObj);
4840 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4842 std::map<int, PortableServer::ServantBase*>::const_iterator it;
4843 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4844 if (it->second == aStorable) {
4845 std::stringstream os;
4847 aString = CORBA::string_dup(os.str().c_str());
4853 return aString._retn();
4856 //===========================================================================
4857 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4858 const char* aLocalPersistentID,
4859 CORBA::Boolean isMultiFile,
4860 CORBA::Boolean isASCII)
4862 CORBA::String_var aString("");
4863 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4864 StudyContext context = myStudyContext;
4865 int id = atoi(aLocalPersistentID);
4866 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4867 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4868 if (!CORBA::is_nil(object)) {
4869 aString = _orb->object_to_string(object);
4873 return aString._retn();
4876 //===========================================================================
4877 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4879 if(CORBA::is_nil(myStudy))
4882 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4883 if(!aCas->_is_nil())
4886 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4887 if(!aHypo->_is_nil())
4890 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4891 if(!aZone->_is_nil())
4894 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4895 if(!aBoundary->_is_nil())
4898 /* Iteration is not published directly
4899 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4900 if(!aIter->_is_nil())
4906 //===========================================================================
4907 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4909 // No Copy/Paste support
4913 //===========================================================================
4914 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4915 CORBA::Long& theObjectID)
4917 // No Copy/Paste support
4918 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4919 return aStreamFile._retn();
4922 //===========================================================================
4923 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
4924 CORBA::Long theObjectID)
4926 // No Copy/Paste support
4930 //===========================================================================
4931 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4932 CORBA::Long theObjectID,
4933 SALOMEDS::SObject_ptr theSObject)
4935 // No Copy/Paste support
4936 SALOMEDS::SObject_var aResultSO;
4937 return aResultSO._retn();
4940 //===========================================================================
4941 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4943 PortableServer::Servant aServant = 0;
4944 if (!CORBA::is_nil(theObject)) {
4946 aServant = _poa->reference_to_servant(theObject);
4954 //==========================================================================
4955 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Boolean isPublished,
4956 CORBA::Boolean isMultiFile,
4957 CORBA::Boolean& isValidScript)
4959 MESSAGE ("Entree dans DumpPython");
4962 SALOMEDS::SObject_var aSO = myStudy->FindComponent("HOMARD");
4963 if(CORBA::is_nil(aSO))
4964 return new Engines::TMPFile(0);
4966 std::string aScript = "\"\"\"\n";
4967 aScript += "Python script for HOMARD\n";
4968 aScript += "Copyright 1996, 2011, 2015 EDF\n";
4969 aScript += "\"\"\"\n";
4970 aScript += "__revision__ = \"V1.2\"\n";
4971 aScript += "import HOMARD\n";
4973 aScript += "import salome\n";
4974 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4975 aScript += "\thomard.UpdateStudy()\n";
4976 MESSAGE (". Au depart \n"<<aScript);
4979 if (myStudyContext._mesBoundarys.size() > 0)
4981 MESSAGE (". Ecritures des frontieres");
4982 aScript += "#\n# Creation of the boundaries";
4983 aScript += "\n# ==========================";
4985 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4986 for (it_boundary = myStudyContext._mesBoundarys.begin();
4987 it_boundary != myStudyContext._mesBoundarys.end(); ++it_boundary)
4989 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4990 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4991 std::string dumpBoundary = dumpCorbaBoundary.in();
4992 MESSAGE (dumpBoundary<<"\n");
4993 aScript += dumpBoundary;
4997 if (myStudyContext._mesZones.size() > 0)
4999 MESSAGE (". Ecritures des zones");
5000 aScript += "#\n# Creation of the zones";
5001 aScript += "\n# =====================";
5003 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
5004 for ( it_zone = myStudyContext._mesZones.begin();
5005 it_zone != myStudyContext._mesZones.end(); ++it_zone)
5007 HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
5008 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
5009 std::string dumpZone = dumpCorbaZone.in();
5010 MESSAGE (dumpZone<<"\n");
5011 aScript += dumpZone;
5015 if (myStudyContext._mesHypotheses.size() > 0)
5017 MESSAGE (". Ecritures des hypotheses");
5018 aScript += "#\n# Creation of the hypotheses";
5019 aScript += "\n# ==========================";
5021 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
5022 for ( it_hypo = myStudyContext._mesHypotheses.begin();
5023 it_hypo != myStudyContext._mesHypotheses.end(); it_hypo++)
5025 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
5026 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
5027 std::string dumpHypo = dumpCorbaHypo.in();
5028 MESSAGE (dumpHypo<<"\n");
5029 aScript += dumpHypo;
5033 if (myStudyContext._mesCas.size() > 0)
5035 MESSAGE (". Ecritures des cas");
5036 aScript += "#\n# Creation of the cases";
5037 aScript += "\n# =====================";
5039 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
5040 for (it_cas = myStudyContext._mesCas.begin();
5041 it_cas != myStudyContext._mesCas.end(); it_cas++)
5043 std::string nomCas = (*it_cas).first;
5044 std::string dumpCas = std::string("\n# Creation of the case ") ;
5045 dumpCas += nomCas + std::string("\n");
5046 dumpCas += std::string("\t") + nomCas;
5047 dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
5049 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
5050 CORBA::String_var cIter0= myCase->GetIter0Name();
5051 std::string iter0 = cIter0.in();
5053 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[iter0];
5054 CORBA::String_var cMesh0= myIteration->GetMeshFile();
5055 std::string mesh0 = cMesh0.in();
5056 CORBA::String_var cMeshName0= myIteration->GetMeshName();
5057 std::string meshName0 = cMeshName0.in();
5058 dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
5059 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
5060 std::string dumpCas2= dumpCorbaCase.in();
5062 MESSAGE (dumpCas<<dumpCas2<<"\n");
5063 aScript += dumpCas + dumpCas2;
5067 if (myStudyContext._mesIterations.size() > 0)
5069 MESSAGE (". Ecritures des iterations");
5070 aScript += "#\n# Creation of the iterations" ;
5071 aScript += "\n# ==========================";
5073 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
5074 for (it_iter = myStudyContext._mesIterations.begin();
5075 it_iter != myStudyContext._mesIterations.end(); ++it_iter)
5077 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
5078 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
5079 std::string dumpIter = dumpCorbaIter.in();
5080 MESSAGE (dumpIter<<"\n");
5081 aScript += dumpIter;
5085 if (myStudyContext._mesYACSs.size() > 0)
5087 MESSAGE (". Ecritures des schemas YACS");
5088 aScript += "#\n# Creation of the schemas YACS";
5089 aScript += "\n# ============================";
5091 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
5092 for ( it_yacs = myStudyContext._mesYACSs.begin();
5093 it_yacs != myStudyContext._mesYACSs.end(); ++it_yacs)
5095 HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
5096 CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
5097 std::string dumpYACS = dumpCorbaYACS.in();
5098 MESSAGE (dumpYACS<<"\n");
5099 aScript += dumpYACS;
5102 MESSAGE (". Ecritures finales");
5104 aScript += "\n\tpass";
5107 if( !isMultiFile ) // remove unnecessary tabulation
5108 aScript = RemoveTabulation( aScript );
5110 // MESSAGE ("A ecrire \n"<<aScript);
5111 const size_t aLen = strlen(aScript.c_str());
5112 char* aBuffer = new char[aLen+1];
5113 strcpy(aBuffer, aScript.c_str());
5115 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
5116 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
5118 MESSAGE ("Sortie de DumpPython");
5119 return aStreamFile._retn();
5123 //=============================================================================
5124 //=============================================================================
5126 //=============================================================================
5127 //=============================================================================
5128 void HOMARD_Gen_i::IsValidStudy( )
5130 // MESSAGE( "IsValidStudy" );
5131 if (CORBA::is_nil(myStudy))
5133 SALOME::ExceptionStruct es;
5134 es.type = SALOME::BAD_PARAM;
5135 es.text = "Invalid study context";
5136 throw SALOME::SALOME_Exception(es);
5141 //=============================================================================
5142 char* HOMARD_Gen_i::VerifieDir(const char* nomDir)
5144 std::string casename = std::string("") ;
5145 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
5146 for (it = myStudyContext._mesCas.begin();
5147 it != myStudyContext._mesCas.end(); it++)
5149 if (std::string(nomDir) == std::string(it->second->GetDirName()))
5151 casename = std::string(it->second->GetName()) ;
5155 return CORBA::string_dup( casename.c_str() );
5157 /*//=============================================================================
5158 void SALOMEException( std::string message )
5160 SALOME::ExceptionStruct es;
5161 es.type = SALOME::BAD_PARAM;
5163 throw SALOME::SALOME_Exception(es);
5166 //=============================================================================
5167 char* HOMARD_Gen_i::getVersion()
5169 #if HOMARD_DEVELOPMENT
5170 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
5172 return CORBA::string_dup(HOMARD_VERSION_STR);
5175 //===============================================================================
5176 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un caractere
5177 // ligne : la ligne a manipuler
5178 // caractere : le caractere a reperer
5179 // option : 0 : la chaine avant la premiere apparition du caractere
5180 // 1 : la chaine apres la premiere apparition du caractere
5181 // 2 : la chaine avant la derniere apparition du caractere
5182 // 3 : la chaine apres la derniere apparition du caractere
5183 // Si le caractere est absent, on retourne la chaine totale
5184 //===============================================================================
5185 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string caractere, int option )
5187 // MESSAGE("GetStringInTexte, recherche de '"<<caractere<<"' dans '"<<ligne<<"'"<<", option = "<<option);
5189 std::string chaine = ligne ;
5191 if ( option < 2 ) { position = ligne.find_first_of( caractere ) ; }
5192 else { position = ligne.find_last_of( caractere ) ; }
5193 // MESSAGE("position = "<<position);
5194 // MESSAGE("a = "<<ligne.substr( 0, position ).c_str());
5195 // MESSAGE("b = "<<ligne.substr( position+1 ).c_str());
5197 if ( position != std::string::npos )
5199 if ( ( option == 0 ) || ( option == 2 ) ) { chaine = ligne.substr( 0, position ) ; }
5200 else { chaine = ligne.substr( position+1 ) ; }
5205 //=============================================================================
5206 //=============================================================================
5207 // Gestion des preferences
5208 //=============================================================================
5209 //=============================================================================
5210 // Decodage du fichier d'arcihvage des preferences
5212 void HOMARD_Gen_i::SetPreferences( )
5214 MESSAGE ( "SetPreferences" );
5216 std::string ligne, mot_cle, salome_version ;
5219 // A. Les valeurs par defaut ; elles doivent etre coherentes
5220 std::string LanguageShort = "en" ;
5221 int PublisMeshIN = 0 ;
5222 int PublisMeshOUT = 0 ;
5223 int YACSMaxIter = 0 ;
5224 int YACSMaxNode = 0 ;
5225 int YACSMaxElem = 0 ;
5226 std::string YACSTypeTestchaine = "None" ;
5228 // B. La version de salome
5229 // Cela se presente sous la forme :
5230 // [SALOME KERNEL] : 7.3.0
5232 File = getenv("KERNEL_ROOT_DIR") ;
5233 File += "/bin/salome/VERSION" ;
5234 MESSAGE ( "File = "<<File ) ;
5235 std::ifstream fichier0( File.c_str() ) ;
5236 if ( fichier0 ) // ce test échoue si le fichier n'est pas ouvert
5238 std::string ligne; // variable contenant chaque ligne lue
5239 while ( std::getline( fichier0, ligne ) )
5241 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5242 ligne_bis >> mot_cle ;
5243 if ( mot_cle == "[SALOME" )
5245 salome_version = GetStringInTexte ( ligne, " ", 3 ) ;
5246 // MESSAGE ( "salome_version = "<<salome_version<<"|||");
5251 else { ok = false ; }
5253 // B. Decodage du fichier de preferences
5256 std::string PrefFile ;
5257 PrefFile = Kernel_Utils::HomePath() ;
5258 PrefFile += "/.config/salome/SalomeApprc." + salome_version ;
5259 MESSAGE ( "PrefFile = "<<PrefFile ) ;
5261 std::ifstream fichier( PrefFile.c_str() );
5262 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
5264 bool section_langue = false ;
5265 bool section_homard = false ;
5266 while ( std::getline( fichier, ligne ) )
5268 std::string chaine ;
5269 // 1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
5270 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5271 ligne_bis >> mot_cle ;
5274 // 2.1. Debut d'une section
5275 // MESSAGE(mot_cle);
5276 if ( mot_cle == "<section" )
5277 { /*MESSAGE ( "Debut de la section : "<< ligne);*/
5278 ligne_bis >> mot_cle ;
5279 chaine = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5280 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5281 if ( chaine == "language" ) { section_langue = true ; }
5282 if ( chaine == "HOMARD" ) { section_homard = true ; }
5283 // MESSAGE ( "section_langue = "<<section_langue<<", section_homard = "<<section_homard);
5285 // 2.2. Fin d'une section
5286 else if ( mot_cle == "</section>" )
5287 { /*MESSAGE ( "Fin de la section : "<< ligne<<", section_langue = "<<section_langue<<", section_homard = "<<section_homard);*/
5288 section_langue = false ;
5289 section_homard = false ; }
5293 else if ( section_langue || section_homard )
5294 { MESSAGE ( "a decoder : "<< ligne);
5295 // La valeur : entre les deux premieres quotes
5296 chaine = GetStringInTexte ( ligne, "\"", 1 ) ;
5297 // MESSAGE("chaine 1 = |"<<chaine<<"|");
5298 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5299 // MESSAGE("chaine = |"<<chaine<<"|");
5300 // Le mot_cle : entre les deux dernieres quotes
5301 std::string chaine2 = GetStringInTexte ( ligne, "\"", 2 ) ;
5302 // MESSAGE("chaine2 1 = |"<<chaine2<<"|");
5303 chaine2 = GetStringInTexte ( chaine2, "\"", 3 ) ;
5304 // MESSAGE("chaine2 = |"<<chaine2<<"|");
5306 if ( section_langue )
5307 { if ( chaine2 == "language" ) { LanguageShort = chaine ; } }
5309 if ( section_homard )
5311 std::istringstream chainebis( chaine ) ;
5312 // 3.2.1. Les publications
5313 if ( chaine2 == "publish_mesh_in" ) { chainebis >> PublisMeshIN ; }
5314 if ( chaine2 == "publish_mesh_out" ) { chainebis >> PublisMeshOUT ; }
5315 // 3.2.2. Les maximum pour YACS
5316 if ( chaine2 == "yacs_max_iter" ) { chainebis >> YACSMaxIter ; }
5317 if ( chaine2 == "yacs_max_node" ) { chainebis >> YACSMaxNode ; }
5318 if ( chaine2 == "yacs_max_elem" ) { chainebis >> YACSMaxElem ; }
5319 if ( chaine2 == "yacs_type_test" ) { YACSTypeTestchaine = chaine ; }
5326 // C. Enregistrements
5327 MESSAGE ("Enregistrement de LanguageShort = " << LanguageShort );
5328 SetLanguageShort( LanguageShort.c_str() ) ;
5330 MESSAGE ("Enregistrement de PublisMeshIN = " << PublisMeshIN<<", PublisMeshOUT = "<< PublisMeshOUT);
5331 SetPublisMesh(PublisMeshIN, PublisMeshOUT) ;
5333 MESSAGE ("Enregistrement de YACSMaxIter = " << YACSMaxIter<<", YACSMaxNode = "<< YACSMaxNode<<", YACSMaxElem = "<< YACSMaxElem);
5334 SetYACSMaximum(YACSMaxIter, YACSMaxNode, YACSMaxElem) ;
5336 MESSAGE ("Enregistrement de TypeTest = " << YACSTypeTestchaine.c_str() );
5338 if ( ( YACSTypeTestchaine == "VTest > VRef" ) || ( YACSTypeTestchaine == "VTest > VRef" ) ) { YACSTypeTest = 1 ; }
5339 else if ( ( YACSTypeTestchaine == "VTest < VRef" ) || ( YACSTypeTestchaine == "VTest < VRef" ) ) { YACSTypeTest = 2 ; }
5340 else { YACSTypeTest = 0 ; }
5341 MESSAGE ("==> TypeTest = " << YACSTypeTest );
5342 SetYACSConvergenceType( YACSTypeTest ) ;
5346 //===============================================================================
5348 //===============================================================================
5349 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
5351 // MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
5352 _LangueShort = LanguageShort ;
5353 if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
5354 else { _Langue = "English" ; }
5357 char* HOMARD_Gen_i::GetLanguageShort()
5359 // MESSAGE ("GetLanguageShort");
5360 return CORBA::string_dup( _LangueShort.c_str() );
5362 //===============================================================================
5363 // Options de publications
5364 //===============================================================================
5365 void HOMARD_Gen_i::SetPublisMesh(CORBA::Long PublisMeshIN, CORBA::Long PublisMeshOUT)
5367 _PublisMeshIN = PublisMeshIN ;
5368 _PublisMeshOUT = PublisMeshOUT ;
5371 CORBA::Long HOMARD_Gen_i::GetPublisMeshIN()
5373 return _PublisMeshIN ;
5375 CORBA::Long HOMARD_Gen_i::GetPublisMeshOUT()
5377 return _PublisMeshOUT ;
5379 //===============================================================================
5380 // YACS - test de convergence
5381 //===============================================================================
5382 void HOMARD_Gen_i::SetYACSMaximum(CORBA::Long YACSMaxIter, CORBA::Long YACSMaxNode, CORBA::Long YACSMaxElem)
5384 _YACSMaxIter = YACSMaxIter ;
5385 _YACSMaxNode = YACSMaxNode ;
5386 _YACSMaxElem = YACSMaxElem ;
5389 CORBA::Long HOMARD_Gen_i::GetYACSMaxIter()
5391 return _YACSMaxIter ;
5393 CORBA::Long HOMARD_Gen_i::GetYACSMaxNode()
5395 return _YACSMaxNode ;
5397 CORBA::Long HOMARD_Gen_i::GetYACSMaxElem()
5399 return _YACSMaxElem ;
5401 void HOMARD_Gen_i::SetYACSConvergenceType(CORBA::Long YACSTypeTest)
5403 _YACSTypeTest = YACSTypeTest ;
5406 CORBA::Long HOMARD_Gen_i::GetYACSConvergenceType()
5408 return _YACSTypeTest ;