1 // Copyright (C) 2011-2016 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 "Utils_SINGLETON.hxx"
39 #include "Utils_CorbaException.hxx"
40 #include "SALOMEDS_Tool.hxx"
41 #include "SALOME_LifeCycleCORBA.hxx"
42 #include "SALOMEconfig.h"
43 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
44 #include CORBA_CLIENT_HEADER(SMESH_Gen)
67 //=============================================================================
69 //=============================================================================
70 std::string RemoveTabulation( std::string theScript )
72 std::string::size_type aPos = 0;
73 while( aPos < theScript.length() )
75 aPos = theScript.find( "\n\t", aPos );
76 if( aPos == std::string::npos )
78 theScript.replace( aPos, 2, "\n" );
83 //=============================================================================
85 * standard constructor
87 //=============================================================================
88 HOMARD_Gen_i::HOMARD_Gen_i( CORBA::ORB_ptr orb,
89 PortableServer::POA_ptr poa,
90 PortableServer::ObjectId * contId,
91 const char *instanceName,
92 const char *interfaceName) :
93 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
95 MESSAGE("constructor");
97 _id = _poa->activate_object(_thisObj);
99 myHomard = new ::HOMARD_Gen();
100 _NS = SINGLETON_<SALOME_NamingService>::Instance();
101 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
112 //=================================
114 * standard destructor
116 //================================
117 HOMARD_Gen_i::~HOMARD_Gen_i()
120 //=============================================================================
121 //=============================================================================
122 // Utilitaires pour l'étude
123 //=============================================================================
124 //=============================================================================
125 void HOMARD_Gen_i::addInStudy(SALOMEDS::Study_ptr theStudy)
127 ASSERT(!CORBA::is_nil(theStudy));
128 MESSAGE("addInStudy: ajout eventuel du composant HOMARD dans current study ID = " << GetCurrentStudyID()) ;
129 SALOMEDS::StudyBuilder_var myBuilder = theStudy->NewBuilder();
131 // Create SComponent labelled 'homard' if it doesn't already exit
132 SALOMEDS::SComponent_var homardFather = theStudy->FindComponent(ComponentDataType());
133 if (CORBA::is_nil(homardFather))
135 myBuilder->NewCommand();
136 MESSAGE("Add Component HOMARD");
138 bool aLocked = theStudy->GetProperties()->IsLocked();
139 if (aLocked) theStudy->GetProperties()->SetLocked(false);
141 homardFather = myBuilder->NewComponent(ComponentDataType());
142 SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
143 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
144 CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
145 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
146 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
147 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
148 if (!Comp->_is_nil())
150 aName->SetValue(ComponentDataType());
153 anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributePixMap");
154 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
155 aPixmap->SetPixMap("HOMARD_2.png");
156 myBuilder->DefineComponentInstance(homardFather, HOMARD_Gen::_this());
158 if (aLocked) theStudy->GetProperties()->SetLocked(true);
159 myBuilder->CommitCommand();
162 //=============================================================================
163 void HOMARD_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy)
165 MESSAGE("SetCurrentStudy: current study Id = " << GetCurrentStudyID());
166 myCurrentStudy = SALOMEDS::Study::_duplicate(theStudy);
167 this->addInStudy(myCurrentStudy);
169 //=============================================================================
170 SALOMEDS::Study_ptr HOMARD_Gen_i::GetCurrentStudy()
171 //=============================================================================
173 MESSAGE("GetCurrentStudy: study Id = " << GetCurrentStudyID());
174 return SALOMEDS::Study::_duplicate(myCurrentStudy);
176 //=============================================================================
177 CORBA::Long HOMARD_Gen_i::GetCurrentStudyID()
178 //=============================================================================
180 return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId();
182 //=============================================================================
183 //=============================================================================
185 //=============================================================================
186 //=============================================================================
187 // Utilitaires pour l'iteration
188 //=============================================================================
189 //=============================================================================
190 void HOMARD_Gen_i::SetEtatIter(const char* nomIter, const CORBA::Long Etat)
191 //=====================================================================================
193 MESSAGE( "SetEtatIter : affectation de l'etat " << Etat << " a l'iteration " << nomIter );
194 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
195 if (CORBA::is_nil(myIteration))
197 SALOME::ExceptionStruct es;
198 es.type = SALOME::BAD_PARAM;
199 es.text = "Invalid iteration";
200 throw SALOME::SALOME_Exception(es);
204 myIteration->SetState(Etat);
206 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
207 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
211 icone = "iter0.png" ;
212 else if ( Etat == 2 )
213 icone = "iter_calculee.png" ;
215 icone = "iter_non_calculee.png" ;
216 PublishInStudyAttr(aStudyBuilder, aIterSO, NULL , NULL, icone.c_str(), NULL) ;
218 aStudyBuilder->CommitCommand();
221 //=============================================================================
222 //=============================================================================
224 //=============================================================================
225 //=============================================================================
226 // Destruction des structures identifiees par leurs noms
227 //=============================================================================
228 //=============================================================================
229 CORBA::Long HOMARD_Gen_i::DeleteBoundary(const char* BoundaryName)
231 MESSAGE ( "DeleteBoundary : BoundaryName = " << BoundaryName );
232 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
233 if (CORBA::is_nil(myBoundary))
235 SALOME::ExceptionStruct es;
236 es.type = SALOME::BAD_PARAM;
237 es.text = "Invalid boundary";
238 throw SALOME::SALOME_Exception(es);
242 // On verifie que la frontiere n'est plus utilisee
243 HOMARD::listeCases* maListe = GetAllCasesName();
244 int numberOfCases = maListe->length();
245 MESSAGE ( ".. Nombre de cas = " << numberOfCases );
246 std::string CaseName ;
247 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType ;
249 HOMARD::HOMARD_Cas_var myCase ;
250 for (int NumeCas = 0; NumeCas< numberOfCases; NumeCas++)
252 CaseName = std::string((*maListe)[NumeCas]);
253 MESSAGE ( "... Examen du cas = " << CaseName.c_str() );
254 myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
255 ASSERT(!CORBA::is_nil(myCase));
256 ListBoundaryGroupType = myCase->GetBoundaryGroup();
257 numberOfitems = ListBoundaryGroupType->length();
258 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
259 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
261 if ( std::string((*ListBoundaryGroupType)[NumBoundary]) == BoundaryName )
263 SALOME::ExceptionStruct es;
264 es.type = SALOME::BAD_PARAM;
265 es.text = "This boundary is used in a case and cannot be deleted.";
266 throw SALOME::SALOME_Exception(es);
272 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
273 myContextMap[GetCurrentStudyID()]._mesBoundarys.erase(BoundaryName);
274 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(BoundaryName, ComponentDataType());
275 SALOMEDS::SObject_var aSO =listSO[0];
276 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
277 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
281 //=============================================================================
282 CORBA::Long HOMARD_Gen_i::DeleteCase(const char* nomCas, CORBA::Long Option)
284 // Pour detruire un cas
285 MESSAGE ( "DeleteCase : nomCas = " << nomCas << ", avec option = " << Option );
286 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
287 if (CORBA::is_nil(myCase))
289 SALOME::ExceptionStruct es;
290 es.type = SALOME::BAD_PARAM;
291 es.text = "Invalid case context";
292 throw SALOME::SALOME_Exception(es);
295 // On commence par detruire toutes les iterations en partant de l'initiale et y compris elle
296 CORBA::String_var nomIter = myCase->GetIter0Name();
297 CORBA::Long Option1 = 0 ;
298 if ( DeleteIterationOption(nomIter, Option1, Option) != 0 )
303 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
304 myContextMap[GetCurrentStudyID()]._mesCas.erase(nomCas);
305 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomCas, ComponentDataType());
306 SALOMEDS::SObject_var aSO =listSO[0];
307 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
308 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
312 //=============================================================================
313 CORBA::Long HOMARD_Gen_i::DeleteHypo(const char* nomHypo)
315 MESSAGE ( "DeleteHypo : nomHypo = " << nomHypo );
316 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
317 if (CORBA::is_nil(myHypo))
319 SALOME::ExceptionStruct es;
320 es.type = SALOME::BAD_PARAM;
321 es.text = "Invalid hypothesis";
322 throw SALOME::SALOME_Exception(es);
326 // On verifie que l'hypothese n'est plus utilisee
327 HOMARD::listeIters* maListeIter = myHypo->GetIterations();
328 int numberOfIter = maListeIter->length();
329 if ( numberOfIter > 0 )
331 SALOME::ExceptionStruct es;
332 es.type = SALOME::BAD_PARAM;
333 es.text = "This hypothesis is used in an iteration and cannot be deleted.";
334 throw SALOME::SALOME_Exception(es);
338 // suppression du lien avec les zones eventuelles
339 HOMARD::listeZonesHypo* maListe = myHypo->GetZones();
340 int numberOfZones = maListe->length();
341 MESSAGE ( ".. Nombre de zones = " << numberOfZones );
342 for (int NumeZone = 0; NumeZone< numberOfZones; NumeZone++)
344 std::string ZoneName = std::string((*maListe)[NumeZone]);
345 MESSAGE ( ".. suppression du lien avec la zone = " << ZoneName.c_str() );
346 DissociateHypoZone(nomHypo, ZoneName.c_str()) ;
350 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
351 myContextMap[GetCurrentStudyID()]._mesHypotheses.erase(nomHypo);
352 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomHypo, ComponentDataType());
353 SALOMEDS::SObject_var aSO =listSO[0];
354 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
355 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
359 //=============================================================================
360 CORBA::Long HOMARD_Gen_i::DeleteIteration(const char* nomIter, CORBA::Long Option)
362 // Option = 0 : On ne supprime pas le fichier du maillage associe
363 // Option = 1 : On supprime le fichier du maillage associe
364 // Pour detruire une iteration courante
365 MESSAGE ( "DeleteIteration : nomIter = " << nomIter << ", avec option = " << Option );
366 CORBA::Long Option1 = 1 ;
367 return DeleteIterationOption(nomIter, Option1, Option);
369 //=============================================================================
370 CORBA::Long HOMARD_Gen_i::DeleteIterationOption(const char* nomIter, CORBA::Long Option1, CORBA::Long Option2)
372 // Option1 = 0 : On autorise la destruction de l'iteration 0
373 // Option1 = 1 : On interdit la destruction de l'iteration 0
375 // Option2 = 0 : On ne supprime pas le fichier du maillage associe
376 // Option2 = 1 : On supprime le fichier du maillage associe
377 MESSAGE ( "DeleteIterationOption : nomIter = " << nomIter << ", avec options = " << Option1<< ", " << Option2 );
378 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
379 if (CORBA::is_nil(myIteration))
381 SALOME::ExceptionStruct es;
382 es.type = SALOME::BAD_PARAM;
383 es.text = "Invalid iteration";
384 throw SALOME::SALOME_Exception(es);
388 int numero = myIteration->GetNumber();
389 MESSAGE ( "DeleteIterationOption : numero = " << numero );
390 if ( numero == 0 && Option1 == 1 )
392 SALOME::ExceptionStruct es;
393 es.type = SALOME::BAD_PARAM;
394 es.text = "This iteration cannot be deleted.";
395 throw SALOME::SALOME_Exception(es);
399 // On detruit recursivement toutes les filles
400 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
401 int numberOfIter = maListe->length();
402 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
404 std::string nomIterFille = std::string((*maListe)[NumeIter]);
405 MESSAGE ( ".. appel recursif de DeleteIterationOption pour nomIter = " << nomIterFille.c_str() );
406 DeleteIterationOption(nomIterFille.c_str(), Option1, Option2);
409 // On arrive ici pour une iteration sans fille
410 MESSAGE ( "Destruction effective de " << nomIter );
411 // On commence par invalider l'iteration pour faire le menage des dependances
412 // et eventuellement du maillage associe
414 if ( numero == 0 ) { option = 0 ; }
415 else { option = Option2 ; }
416 InvalideIterOption(nomIter, option) ;
418 // Retrait dans la descendance de l'iteration parent
421 std::string nomIterationParent = myIteration->GetIterParentName();
422 MESSAGE ( "Retrait dans la descendance de nomIterationParent " << nomIterationParent );
423 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
424 if (CORBA::is_nil(myIterationParent))
426 SALOME::ExceptionStruct es;
427 es.type = SALOME::BAD_PARAM;
428 es.text = "Invalid iteration";
429 throw SALOME::SALOME_Exception(es);
432 myIterationParent->UnLinkNextIteration(nomIter);
435 // suppression du lien avec l'hypothese
438 std::string nomHypo = myIteration->GetHypoName();
439 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
440 ASSERT(!CORBA::is_nil(myHypo));
441 myHypo->UnLinkIteration(nomIter);
444 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
445 myContextMap[GetCurrentStudyID()]._mesIterations.erase(nomIter);
446 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomIter, ComponentDataType());
447 SALOMEDS::SObject_var aSO =listSO[0];
448 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
449 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
450 // on peut aussi faire RemoveObject
451 // MESSAGE ( "Au final" );
452 // HOMARD::listeIterations* Liste = GetAllIterationsName() ;
453 // numberOfIter = Liste->length();
454 // for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
456 // std::string nomIterFille = std::string((*Liste)[NumeIter]);
457 // MESSAGE ( ".. nomIter = " << nomIterFille.c_str() );
462 //=============================================================================
463 CORBA::Long HOMARD_Gen_i::DeleteYACS(const char* nomYACS, CORBA::Long Option)
465 // Option = 0 : On ne supprime pas le fichier du schema associe
466 // Option = 1 : On supprime le fichier du schema associe
467 MESSAGE ( "DeleteYACS : nomYACS = " << nomYACS << ", avec option = " << Option );
468 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
469 if (CORBA::is_nil(myYACS))
471 SALOME::ExceptionStruct es;
472 es.type = SALOME::BAD_PARAM;
473 es.text = "Invalid schema YACS";
474 throw SALOME::SALOME_Exception(es);
477 // Suppression eventuelle du fichier XML
480 std::string nomFichier = myYACS->GetXMLFile();
481 std::string commande = "rm -rf " + nomFichier ;
482 MESSAGE ( "commande = " << commande );
483 if ((system(commande.c_str())) != 0)
485 SALOME::ExceptionStruct es;
486 es.type = SALOME::BAD_PARAM;
487 es.text = "The xml file for the schema YACS cannot be removed." ;
488 throw SALOME::SALOME_Exception(es);
492 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
493 myContextMap[GetCurrentStudyID()]._mesYACSs.erase(nomYACS);
494 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomYACS, ComponentDataType());
495 SALOMEDS::SObject_var aSO =listSO[0];
496 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
497 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
501 //=============================================================================
502 CORBA::Long HOMARD_Gen_i::DeleteZone(const char* nomZone)
504 MESSAGE ( "DeleteZone : nomZone = " << nomZone );
505 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[nomZone];
506 if (CORBA::is_nil(myZone))
508 SALOME::ExceptionStruct es;
509 es.type = SALOME::BAD_PARAM;
510 es.text = "Invalid zone";
511 throw SALOME::SALOME_Exception(es);
515 // On verifie que la zone n'est plus utilisee
516 HOMARD::listeHypo* maListe = myZone->GetHypo();
517 int numberOfHypo = maListe->length();
518 MESSAGE ( ".. Nombre d'hypotheses = " << numberOfHypo );
519 if ( numberOfHypo > 0 )
521 SALOME::ExceptionStruct es;
522 es.type = SALOME::BAD_PARAM;
523 es.text = "This zone is used in a hypothesis and cannot be deleted.";
524 throw SALOME::SALOME_Exception(es);
528 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
529 myContextMap[GetCurrentStudyID()]._mesZones.erase(nomZone);
530 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomZone, ComponentDataType());
531 SALOMEDS::SObject_var aSO =listSO[0];
532 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
533 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
537 //=============================================================================
538 //=============================================================================
540 //=============================================================================
541 //=============================================================================
542 // Invalidation des structures identifiees par leurs noms
543 //=============================================================================
544 //=============================================================================
545 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
547 MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName );
548 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
549 if (CORBA::is_nil(myBoundary))
551 SALOME::ExceptionStruct es;
552 es.type = SALOME::BAD_PARAM;
553 es.text = "Invalid boundary";
554 throw SALOME::SALOME_Exception(es);
559 SALOME::ExceptionStruct es;
560 es.type = SALOME::BAD_PARAM;
561 es.text = "No change is allowed in a boundary. Ask for evolution.";
562 throw SALOME::SALOME_Exception(es);
566 //=============================================================================
567 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
569 MESSAGE( "InvalideHypo : nomHypo = " << nomHypo );
570 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
571 if (CORBA::is_nil(myHypo))
573 SALOME::ExceptionStruct es;
574 es.type = SALOME::BAD_PARAM;
575 es.text = "Invalid hypothesis";
576 throw SALOME::SALOME_Exception(es);
580 HOMARD::listeIters* maListe = myHypo->GetIterations();
581 int numberOfIter = maListe->length();
582 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
584 std::string nomIter = std::string((*maListe)[NumeIter]);
585 MESSAGE( ".. nomIter = " << nomIter );
586 InvalideIter(nomIter.c_str());
589 //=============================================================================
590 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
592 MESSAGE("InvalideIter : nomIter = " << nomIter);
593 // Pour invalider totalement une iteration courante
594 CORBA::Long Option = 1 ;
595 return InvalideIterOption(nomIter, Option);
597 //=============================================================================
598 void HOMARD_Gen_i::InvalideIterOption(const char* nomIter, CORBA::Long Option)
600 // Option = 0 : On ne supprime pas le fichier du maillage associe
601 // Option = 1 : On supprime le fichier du maillage associe
602 MESSAGE ( "InvalideIterOption : nomIter = " << nomIter << ", avec option = " << Option );
603 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
604 if (CORBA::is_nil(myIteration))
606 SALOME::ExceptionStruct es;
607 es.type = SALOME::BAD_PARAM;
608 es.text = "Invalid iteration";
609 throw SALOME::SALOME_Exception(es);
613 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
614 int numberOfIter = maListe->length();
615 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
617 std::string nomIterFille = std::string((*maListe)[NumeIter]);
618 MESSAGE ( ".. appel recursif de InvalideIter pour nomIter = " << nomIterFille.c_str() );
619 InvalideIter(nomIterFille.c_str());
622 // On arrive ici pour une iteration sans fille
623 MESSAGE ( "Invalidation effective de " << nomIter );
624 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
625 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
626 for (; aIter->More(); aIter->Next())
628 SALOMEDS::SObject_var so = aIter->Value();
629 SALOMEDS::GenericAttribute_var anAttr;
630 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
631 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
632 std::string value (aCommentAttr->Value());
633 if(value == std::string("IterationHomard")) continue;
634 if(value == std::string("HypoHomard")) continue;
635 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
636 aStudyBuilder->RemoveObject(so);
639 int etat = myIteration->GetState();
642 SetEtatIter(nomIter,1);
643 const char * nomCas = myIteration->GetCaseName();
644 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
645 if (CORBA::is_nil(myCase))
647 SALOME::ExceptionStruct es;
648 es.type = SALOME::BAD_PARAM;
649 es.text = "Invalid case context";
650 throw SALOME::SALOME_Exception(es);
653 std::string nomDir = myIteration->GetDirName();
654 std::string nomFichier = myIteration->GetMeshFile();
655 std::string commande = "rm -rf " + std::string(nomDir);
656 if ( Option == 1 ) { commande = commande + ";rm -rf " + std::string(nomFichier) ; }
657 MESSAGE ( "commande = " << commande );
658 if ((system(commande.c_str())) != 0)
660 SALOME::ExceptionStruct es;
661 es.type = SALOME::BAD_PARAM;
662 es.text = "The directory for the calculation cannot be cleared." ;
663 throw SALOME::SALOME_Exception(es);
666 // Suppression du maillage publie dans SMESH
667 std::string MeshName = myIteration->GetMeshName() ;
668 DeleteResultInSmesh(nomFichier, MeshName) ;
672 //=============================================================================
673 void HOMARD_Gen_i::InvalideIterInfo(const char* nomIter)
675 MESSAGE("InvalideIterInfo : nomIter = " << nomIter);
676 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
677 if (CORBA::is_nil(myIteration))
679 SALOME::ExceptionStruct es;
680 es.type = SALOME::BAD_PARAM;
681 es.text = "Invalid iteration";
682 throw SALOME::SALOME_Exception(es);
686 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
687 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
688 for (; aIter->More(); aIter->Next())
690 SALOMEDS::SObject_var so = aIter->Value();
691 SALOMEDS::GenericAttribute_var anAttr;
692 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
693 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
694 std::string value (aCommentAttr->Value());
695 /* MESSAGE("... value = " << value);*/
696 if( (value == std::string("logInfo")) || ( value == std::string("SummaryInfo")) )
698 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
699 aStudyBuilder->RemoveObject(so);
703 const char * nomCas = myIteration->GetCaseName();
704 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
705 if (CORBA::is_nil(myCase))
707 SALOME::ExceptionStruct es;
708 es.type = SALOME::BAD_PARAM;
709 es.text = "Invalid case context";
710 throw SALOME::SALOME_Exception(es);
713 const char* nomDir = myIteration->GetDirName();
714 std::string commande = "rm -f " + std::string(nomDir) + "/info* " ;
715 commande += std::string(nomDir) + "/Liste.*info" ;
716 /* MESSAGE ( "commande = " << commande );*/
717 if ((system(commande.c_str())) != 0)
719 SALOME::ExceptionStruct es;
720 es.type = SALOME::BAD_PARAM;
721 es.text = "The directory for the calculation cannot be cleared." ;
722 throw SALOME::SALOME_Exception(es);
726 //=============================================================================
727 void HOMARD_Gen_i::InvalideYACS(const char* YACSName)
729 MESSAGE( "InvalideYACS : YACSName = " << YACSName );
730 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[YACSName];
731 if (CORBA::is_nil(myYACS))
733 SALOME::ExceptionStruct es;
734 es.type = SALOME::BAD_PARAM;
735 es.text = "Invalid schema YACS";
736 throw SALOME::SALOME_Exception(es);
740 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
741 SALOMEDS::ChildIterator_var aYACS = myCurrentStudy->NewChildIterator(aYACSSO);
742 for (; aYACS->More(); aYACS->Next())
744 SALOMEDS::SObject_var so = aYACS->Value();
745 SALOMEDS::GenericAttribute_var anAttr;
746 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
747 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
748 std::string value (aCommentAttr->Value());
749 if( value == std::string("xml") )
751 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
752 aStudyBuilder->RemoveObject(so);
755 std::string nomFichier = myYACS->GetXMLFile();
756 std::string commande = "rm -rf " + std::string(nomFichier) ;
757 MESSAGE ( "commande = " << commande );
758 if ((system(commande.c_str())) != 0)
760 SALOME::ExceptionStruct es;
761 es.type = SALOME::BAD_PARAM;
762 es.text = "The XML file for the schema YACS cannot be removed." ;
763 throw SALOME::SALOME_Exception(es);
767 //=============================================================================
768 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
770 MESSAGE( "InvalideZone : ZoneName = " << ZoneName );
771 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
772 if (CORBA::is_nil(myZone))
774 SALOME::ExceptionStruct es;
775 es.type = SALOME::BAD_PARAM;
776 es.text = "Invalid zone";
777 throw SALOME::SALOME_Exception(es);
780 HOMARD::listeHypo* maListe = myZone->GetHypo();
781 int numberOfHypo = maListe->length();
782 MESSAGE( ".. numberOfHypo = " << numberOfHypo );
783 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
785 std::string nomHypo = std::string((*maListe)[NumeHypo]);
786 MESSAGE( ".. nomHypo = " << nomHypo );
787 InvalideHypo(nomHypo.c_str());
790 //=============================================================================
791 //=============================================================================
793 //=============================================================================
794 //=============================================================================
795 // Association de lien entre des structures identifiees par leurs noms
796 //=============================================================================
797 //=============================================================================
798 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
800 MESSAGE( "AssociateCaseIter : " << nomCas << ", " << nomIter << ", " << labelIter );
802 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
803 if (CORBA::is_nil(myCase))
805 SALOME::ExceptionStruct es;
806 es.type = SALOME::BAD_PARAM;
807 es.text = "Invalid case";
808 throw SALOME::SALOME_Exception(es);
812 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
813 if (CORBA::is_nil(myIteration))
815 SALOME::ExceptionStruct es;
816 es.type = SALOME::BAD_PARAM;
817 es.text = "Invalid iteration";
818 throw SALOME::SALOME_Exception(es);
822 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
823 SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
824 if (CORBA::is_nil(aCasSO))
826 SALOME::ExceptionStruct es;
827 es.type = SALOME::BAD_PARAM;
828 es.text = "Invalid case";
829 throw SALOME::SALOME_Exception(es);
833 aStudyBuilder->NewCommand();
834 SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
835 PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
836 "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
837 aStudyBuilder->CommitCommand();
839 myCase->AddIteration(nomIter);
840 myIteration->SetCaseName(nomCas);
842 //=====================================================================================
843 void HOMARD_Gen_i::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
845 MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
847 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
848 ASSERT(!CORBA::is_nil(myHypo));
849 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
850 ASSERT(!CORBA::is_nil(aHypoSO));
852 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
853 ASSERT(!CORBA::is_nil(myZone));
854 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
855 ASSERT(!CORBA::is_nil(aZoneSO));
857 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
859 aStudyBuilder->NewCommand();
861 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
862 aStudyBuilder->Addreference(aSubSO, aZoneSO);
864 aStudyBuilder->CommitCommand();
866 myZone->AddHypo(nomHypothesis);
867 myHypo->AddZone0(ZoneName, TypeUse);
869 //=============================================================================
870 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
872 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
874 // Verification de l'existence de l'hypothese
875 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
876 ASSERT(!CORBA::is_nil(myHypo));
877 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
878 ASSERT(!CORBA::is_nil(aHypoSO));
880 // Verification de l'existence de l'iteration
881 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
882 ASSERT(!CORBA::is_nil(myIteration));
883 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
884 ASSERT(!CORBA::is_nil(aIterSO));
886 // Gestion de l'arbre d'etudes
887 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
888 aStudyBuilder->NewCommand();
889 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
890 aStudyBuilder->Addreference(aSubSO, aHypoSO);
891 aStudyBuilder->CommitCommand();
894 myIteration->SetHypoName(nomHypo);
895 myHypo->LinkIteration(nomIter);
897 // On stocke les noms des champ a interpoler pour le futur controle de la donnée des pas de temps
898 myIteration->SupprFieldInterps() ;
899 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
900 int numberOfFieldsx2 = ListField->length();
901 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
903 std::string FieldName = std::string((*ListField)[iaux]) ;
904 myIteration->SetFieldInterp(FieldName.c_str()) ;
908 //=============================================================================
909 //=============================================================================
911 //=============================================================================
912 //=============================================================================
913 // Dissociation de lien entre des structures identifiees par leurs noms
914 //=============================================================================
915 //=============================================================================
916 void HOMARD_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
918 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
920 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
921 ASSERT(!CORBA::is_nil(myHypo));
922 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
923 ASSERT(!CORBA::is_nil(aHypoSO));
925 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
926 ASSERT(!CORBA::is_nil(myZone));
927 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
928 ASSERT(!CORBA::is_nil(aZoneSO));
930 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
932 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator(aHypoSO);
933 for (; it->More(); it->Next())
935 SALOMEDS::SObject_var aHypObj = it->Value();
936 SALOMEDS::SObject_var ptrObj;
937 if (aHypObj->ReferencedObject(ptrObj))
939 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
941 aStudyBuilder->NewCommand();
942 aStudyBuilder->RemoveObject(aHypObj);
943 aStudyBuilder->CommitCommand();
949 myZone->SupprHypo(nomHypothesis);
950 myHypo->SupprZone(ZoneName);
952 //=============================================================================
953 //=============================================================================
956 //=============================================================================
957 //=============================================================================
958 // Recuperation des listes
959 //=============================================================================
960 //=============================================================================
961 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
963 MESSAGE("GetAllBoundarysName");
966 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
967 ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
968 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
970 for (it = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
971 it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
973 ret[i++] = CORBA::string_dup((*it).first.c_str());
978 //=============================================================================
979 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
981 MESSAGE("GetAllCasesName");
984 HOMARD::listeCases_var ret = new HOMARD::listeCases;
985 ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
986 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
988 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
989 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
991 ret[i++] = CORBA::string_dup((*it).first.c_str());
996 //=============================================================================
997 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
999 MESSAGE("GetAllHypothesesName");
1002 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
1003 ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
1004 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
1006 for (it = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
1007 it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
1009 ret[i++] = CORBA::string_dup((*it).first.c_str());
1014 //=============================================================================
1015 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
1017 MESSAGE("GetAllIterationsName");
1020 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
1021 ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
1022 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
1024 for (it = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
1025 it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
1027 ret[i++] = CORBA::string_dup((*it).first.c_str());
1032 //=============================================================================
1033 HOMARD::listeYACSs* HOMARD_Gen_i::GetAllYACSsName()
1035 MESSAGE("GetAllYACSsName");
1038 HOMARD::listeYACSs_var ret = new HOMARD::listeYACSs;
1039 ret->length(myContextMap[GetCurrentStudyID()]._mesYACSs.size());
1040 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it;
1042 for (it = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
1043 it != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); it++)
1045 ret[i++] = CORBA::string_dup((*it).first.c_str());
1050 //=============================================================================
1051 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
1053 MESSAGE("GetAllZonesName");
1056 HOMARD::listeZones_var ret = new HOMARD::listeZones;
1057 ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
1058 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
1060 for (it = myContextMap[GetCurrentStudyID()]._mesZones.begin();
1061 it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
1063 ret[i++] = CORBA::string_dup((*it).first.c_str());
1068 //=============================================================================
1069 //=============================================================================
1071 //=============================================================================
1072 //=============================================================================
1073 // Recuperation des structures identifiees par leurs noms
1074 //=============================================================================
1075 //=============================================================================
1076 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
1078 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
1079 ASSERT(!CORBA::is_nil(myBoundary));
1080 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1082 //=============================================================================
1083 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
1085 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1086 ASSERT(!CORBA::is_nil(myCase));
1087 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1089 //=============================================================================
1090 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
1092 HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
1093 ASSERT(!CORBA::is_nil(myHypothesis));
1094 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1096 //=============================================================================
1097 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* NomIterationation)
1099 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIterationation];
1100 ASSERT(!CORBA::is_nil(myIteration));
1101 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1103 //=============================================================================
1104 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::GetYACS(const char* nomYACS)
1106 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
1107 ASSERT(!CORBA::is_nil(myYACS));
1108 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
1110 //=============================================================================
1111 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
1113 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1114 ASSERT(!CORBA::is_nil(myZone));
1115 return HOMARD::HOMARD_Zone::_duplicate(myZone);
1117 //=============================================================================
1118 //=============================================================================
1120 //=============================================================================
1121 //=============================================================================
1123 //=============================================================================
1124 //=============================================================================
1125 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)
1127 INFOS ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1128 INFOS ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte );
1133 if ( _PublisMeshIN != 0 ) option = 2 ;
1134 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, 0, option) ;
1135 myCase->SetDirName(DirName) ;
1137 myCase->MeshInfo(Qual, Diam, Conn, Tail, Inte) ;
1141 //=============================================================================
1142 //=============================================================================
1144 //=============================================================================
1145 //=============================================================================
1146 // Recuperation des structures par le contexte
1147 //=============================================================================
1148 //=============================================================================
1149 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::LastIteration(const char* nomCas)
1151 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1152 ASSERT(!CORBA::is_nil(myCase));
1154 HOMARD::HOMARD_Iteration_var myIteration = myCase->LastIteration();
1155 ASSERT(!CORBA::is_nil(myIteration));
1157 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1159 //=============================================================================
1160 //=============================================================================
1162 //=============================================================================
1163 //=============================================================================
1164 // Nouvelles structures
1165 //=============================================================================
1166 //=============================================================================
1167 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1169 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1170 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
1171 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
1172 return aCase._retn();
1174 //=============================================================================
1175 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
1177 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1178 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
1179 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
1180 return aHypo._retn();
1182 //=============================================================================
1183 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
1185 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1186 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
1187 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
1188 return aIter._retn();
1190 //=============================================================================
1191 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1193 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1194 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
1195 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1196 return aBoundary._retn();
1198 //=============================================================================
1199 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
1201 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1202 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
1203 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
1204 return aZone._retn();
1206 //=============================================================================
1207 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::newYACS()
1209 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1210 HOMARD_YACS_i* aServant = new HOMARD_YACS_i(_orb, engine);
1211 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(aServant->_this());
1212 return aYACS._retn();
1214 //=============================================================================
1215 //=============================================================================
1217 //=============================================================================
1218 //=============================================================================
1219 // Creation des structures identifiees par leurs noms
1220 //=============================================================================
1221 //=============================================================================
1222 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
1224 // Creation d'un cas initial
1225 // nomCas : nom du cas a creer
1226 // MeshName, MeshFile : nom et fichier du maillage correspondant
1229 INFOS ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1232 if ( _PublisMeshIN != 0 ) option = 2 ;
1233 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 0, 0, option) ;
1235 // Valeurs par defaut des filtrages
1236 myCase->SetPyram(0);
1238 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1240 //=============================================================================
1241 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromIteration(const char* nomCas, const char* DirNameStart)
1243 // nomCas : nom du cas a creer
1244 // DirNameStart : nom du répertoire contenant l'iteration de reprise
1247 INFOS ( "CreateCaseFromIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1248 std::string nomDirWork = getenv("PWD") ;
1251 // A. Decodage du point de reprise
1252 // A.1. Controle du répertoire de depart de l'iteration
1253 codret = CHDIR(DirNameStart) ;
1256 SALOME::ExceptionStruct es;
1257 es.type = SALOME::BAD_PARAM;
1258 es.text = "The directory of the iteration does not exist.";
1259 throw SALOME::SALOME_Exception(es);
1262 // A.2. Reperage des fichiers du répertoire de reprise
1263 std::string file_configuration = "" ;
1264 std::string file_maillage_homard = "" ;
1268 struct dirent *dirp;
1269 dp = opendir(DirNameStart);
1270 while ( (dirp = readdir(dp)) != NULL )
1272 std::string file_name(dirp->d_name);
1273 // MESSAGE ( file_name );
1274 bilan = file_name.find("HOMARD.Configuration.") ;
1275 if ( bilan != string::npos ) { file_configuration = file_name ; }
1276 bilan = file_name.find("maill.") ;
1277 if ( bilan != string::npos )
1279 bilan = file_name.find(".hom.med") ;
1280 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1285 HANDLE hFind = INVALID_HANDLE_VALUE;
1286 WIN32_FIND_DATA ffd;
1287 hFind = FindFirstFile(DirNameStart, &ffd);
1288 if (INVALID_HANDLE_VALUE != hFind) {
1289 while (FindNextFile(hFind, &ffd) != 0) {
1290 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1291 std::string file_name(ffd.cFileName);
1292 bilan = file_name.find("HOMARD.Configuration.") ;
1293 if ( bilan != string::npos ) { file_configuration = file_name ; }
1294 bilan = file_name.find("maill.") ;
1295 if ( bilan != string::npos )
1297 bilan = file_name.find(".hom.med") ;
1298 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1304 MESSAGE ( "==> file_configuration : " << file_configuration ) ;
1305 MESSAGE ( "==> file_maillage_homard : " << file_maillage_homard ) ;
1307 if ( ( file_configuration == "" ) || ( file_maillage_homard == "" ) )
1309 SALOME::ExceptionStruct es;
1310 es.type = SALOME::BAD_PARAM;
1312 if ( file_configuration == "" ) { text = "The configuration file cannot be found." ; }
1313 else { text = "The HOMARD mesh file cannot be found." ; }
1314 es.text = CORBA::string_dup(text.c_str());
1315 throw SALOME::SALOME_Exception(es);
1318 // B. Lecture du fichier de configuration
1319 // ATTENTION : on doit veiller a la coherence entre HomardDriver et CreateCaseFromIteration
1326 // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1327 std::ifstream fichier( file_configuration.c_str() );
1328 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1330 std::string ligne; // variable contenant chaque ligne lue
1331 std::string mot_cle;
1332 std::string argument;
1334 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1335 while ( std::getline( fichier, ligne ) )
1337 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1338 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1339 ligne_bis >> mot_cle ;
1340 // B.2. Des valeurs entieres : le second bloc de la ligne
1341 if ( mot_cle == "NumeIter" )
1343 ligne_bis >> NumeIter ;
1346 // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1347 else if ( ( mot_cle == "TypeConf" ) || ( mot_cle == "TypeElem" ) )
1349 ligne_bis >> argument ;
1351 if ( mot_cle == "TypeConf" )
1353 if ( argument == "conforme" ) { TypeConf = 1 ; }
1354 else if ( argument == "non_conforme_1_noeud" ) { TypeConf = 2 ; }
1355 else if ( argument == "non_conforme_1_arete" ) { TypeConf = 3 ; }
1356 else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1358 else if ( mot_cle == "TypeElem" )
1360 if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1361 else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1364 // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1365 // il faut les supprimer
1366 else if ( ( mot_cle == "CCNoMNP1" ) || ( mot_cle == "CCMaiNP1" ) )
1368 ligne_bis >> argument ;
1369 if ( argument[0] == '"' ) { decalage = 1 ; }
1370 else { decalage = 0 ; }
1371 size_t size = argument.size() + 1 - 2*decalage ;
1373 if ( mot_cle == "CCNoMNP1" )
1375 MeshName = new char[ size ];
1376 strncpy( MeshName, argument.c_str()+decalage, size );
1377 MeshName[size-1] = '\0' ;
1379 else if ( mot_cle == "CCMaiNP1" )
1381 MeshFile = new char[ size ];
1382 strncpy( MeshFile, argument.c_str()+decalage, size );
1383 MeshFile[size-1] = '\0' ;
1387 MESSAGE ( "==> TypeConf : " << TypeConf ) ;
1388 MESSAGE ( "==> MeshName : " << MeshName ) ;
1389 MESSAGE ( "==> MeshFile : " << MeshFile ) ;
1390 MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1391 MESSAGE ( "==> Pyram : " << Pyram ) ;
1395 SALOME::ExceptionStruct es;
1396 es.type = SALOME::BAD_PARAM;
1397 std::string text = "The configuration file cannot be read." ;
1398 es.text = CORBA::string_dup(text.c_str());
1399 throw SALOME::SALOME_Exception(es);
1402 // C. Creation effective du cas
1405 if ( _PublisMeshIN != 0 ) option = 2 ;
1406 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, option) ;
1408 // D. Parametrages lus dans le fichier de configuration
1410 myCase->SetConfType (TypeConf) ;
1411 myCase->SetExtType (TypeExt) ;
1412 myCase->SetPyram (Pyram) ;
1414 // E. Copie du fichier de maillage homard
1415 // E.1. Répertoire associe au cas
1416 char* nomDirCase = myCase->GetDirName() ;
1417 // E.2. Répertoire associe a l'iteration de ce cas
1419 IterName = myCase->GetIter0Name() ;
1420 HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1421 char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1422 Iter->SetDirNameLoc(nomDirIter);
1423 std::string nomDirIterTotal ;
1424 nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1426 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1428 if (_mkdir(nomDirIterTotal.c_str()) != 0)
1431 MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1432 SALOME::ExceptionStruct es;
1433 es.type = SALOME::BAD_PARAM;
1434 std::string text = "The directory for the computation cannot be created." ;
1435 es.text = CORBA::string_dup(text.c_str());
1436 throw SALOME::SALOME_Exception(es);
1438 // E.3. Copie du maillage HOMARD au format MED
1439 codret = CHDIR(DirNameStart) ;
1440 std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1441 MESSAGE ( "commande : " << commande ) ;
1442 codret = system(commande.c_str()) ;
1443 MESSAGE ( "codret : " << codret ) ;
1446 SALOME::ExceptionStruct es;
1447 es.type = SALOME::BAD_PARAM;
1448 es.text = "The starting point for the case cannot be copied into the working directory.";
1449 throw SALOME::SALOME_Exception(es);
1458 CHDIR(nomDirWork.c_str());
1459 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1461 //=============================================================================
1462 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1464 // nomCas : nom du cas a creer
1465 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1468 INFOS ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1470 std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1472 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1473 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1475 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1477 //=============================================================================
1478 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1480 // nomCas : nom du cas a creer
1481 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1482 // Number : numero de l'iteration de depart
1485 INFOS ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1488 SALOME::ExceptionStruct es;
1489 es.type = SALOME::BAD_PARAM;
1490 es.text = "The number of iteration must be positive.";
1491 throw SALOME::SALOME_Exception(es);
1495 std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1497 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1498 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1500 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1502 //=============================================================================
1503 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1505 // Retourne le nom du répertoire ou se trouve l'iteration voulue.
1506 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1507 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1510 MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1511 std::string nomDirWork = getenv("PWD") ;
1512 std::string DirNameStartIter ;
1514 int NumeIterMax = -1 ;
1516 // A.1. Controle du répertoire de depart du cas
1517 codret = CHDIR(DirNameStart) ;
1520 SALOME::ExceptionStruct es;
1521 es.type = SALOME::BAD_PARAM;
1522 es.text = "The directory of the case for the pursuit does not exist.";
1523 throw SALOME::SALOME_Exception(es);
1526 // A.2. Reperage des sous-répertoire du répertoire de reprise
1527 bool existe = false ;
1530 struct dirent *dirp;
1531 dp = opendir(DirNameStart);
1532 while ( (dirp = readdir(dp)) != NULL ) {
1533 std::string DirName_1(dirp->d_name);
1535 HANDLE hFind = INVALID_HANDLE_VALUE;
1536 WIN32_FIND_DATA ffd;
1537 hFind = FindFirstFile(DirNameStart, &ffd);
1538 if (INVALID_HANDLE_VALUE != hFind) {
1539 while (FindNextFile(hFind, &ffd) != 0) {
1540 std::string DirName_1 = "";
1541 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1542 DirName_1 = std::string(ffd.cFileName);
1545 if ( ( DirName_1 != "." ) && ( DirName_1 != ".." ) )
1547 if ( CHDIR(DirName_1.c_str()) == 0 )
1549 // On cherche le fichier de configuration dans ce sous-répertoire
1550 codret = CHDIR(DirNameStart);
1553 struct dirent *dirp_1;
1554 dp_1 = opendir(DirName_1.c_str()) ;
1555 while ( (dirp_1 = readdir(dp_1)) != NULL )
1557 std::string file_name_1(dirp_1->d_name);
1559 HANDLE hFind1 = INVALID_HANDLE_VALUE;
1560 WIN32_FIND_DATA ffd1;
1561 hFind1 = FindFirstFile(DirName_1.c_str(), &ffd1);
1562 while (FindNextFile(hFind1, &ffd1) != 0)
1564 if (ffd1.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1565 std::string file_name_1(ffd1.cFileName);
1567 int bilan = file_name_1.find("HOMARD.Configuration.") ;
1568 if ( bilan != string::npos )
1570 // Decodage du fichier pour trouver le numero d'iteration
1571 CHDIR(DirName_1.c_str()) ;
1573 std::ifstream fichier( file_name_1.c_str() );
1574 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1577 std::string ligne; // variable contenant chaque ligne lue
1578 std::string mot_cle;
1579 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1580 while ( std::getline( fichier, ligne ) )
1582 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1583 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1584 ligne_bis >> mot_cle ;
1585 if ( mot_cle == "NumeIter" )
1587 ligne_bis >> NumeIter ;
1589 // MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1590 if ( Number == - 1 )
1592 if ( NumeIter >= NumeIterMax )
1594 NumeIterMax = NumeIter ;
1595 DirNameStartIter = DirName_1 ;
1600 if ( NumeIter == Number )
1602 DirNameStartIter = DirName_1 ;
1612 SALOME::ExceptionStruct es;
1613 es.type = SALOME::BAD_PARAM;
1614 std::string text = "The configuration file cannot be read." ;
1615 es.text = CORBA::string_dup(text.c_str());
1616 throw SALOME::SALOME_Exception(es);
1618 CHDIR(DirNameStart) ;
1620 if ( existe ) { break ; }
1627 if ( existe ) { break ; }
1636 CHDIR(nomDirWork.c_str());
1638 if ( ( Number >= 0 && ( !existe ) ) || ( Number < 0 && ( NumeIterMax == -1 ) ) )
1640 SALOME::ExceptionStruct es;
1641 es.type = SALOME::BAD_PARAM;
1642 es.text = "The directory of the iteration does not exist.";
1643 throw SALOME::SALOME_Exception(es);
1647 return DirNameStartIter ;
1649 //=============================================================================
1650 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)
1652 // nomCas : nom du cas a creer
1653 // MeshName, MeshFile : nom et fichier du maillage correspondant
1654 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1655 // 1 : le maillage fourni peut ne pas exister ==> on continue si absent
1656 // -1 : le maillage n'est pas fourni
1657 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1658 // Option : multiple de nombres premiers
1659 // 1 : aucune option
1660 // x2 : publication du maillage dans SMESH
1662 MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1663 MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1664 MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1670 // A.2. Controle du nom :
1671 if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
1673 SALOME::ExceptionStruct es;
1674 es.type = SALOME::BAD_PARAM;
1675 es.text = "This case has already been defined.";
1676 throw SALOME::SALOME_Exception(es);
1680 // A.3. Controle du fichier du maillage
1681 int existeMeshFile ;
1682 if ( MeshOption >= 0 )
1684 existeMeshFile = MEDFileExist ( MeshFile ) ;
1685 MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1686 if ( ( existeMeshFile == 0 ) && ( MeshOption == 0 ) )
1688 SALOME::ExceptionStruct es;
1689 es.type = SALOME::BAD_PARAM;
1690 es.text = "The mesh file does not exist.";
1691 throw SALOME::SALOME_Exception(es);
1695 else { existeMeshFile = 0 ; }
1697 // B. Creation de l'objet cas et publication
1698 // MESSAGE ( "CreateCase0 : Creation de l'objet" );
1699 HOMARD::HOMARD_Cas_var myCase = newCase();
1700 myCase->SetName(nomCas);
1701 SALOMEDS::SObject_var aSO;
1702 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
1703 myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
1705 // C. Caracteristiques du maillage
1706 if ( existeMeshFile != 0 )
1708 // Les valeurs extremes des coordonnées
1709 // MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnées" );
1710 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1711 HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1712 if (LesExtremes.size()!=10) { return 0; }
1714 for (int i =0 ; i< LesExtremes.size() ; i++)
1715 aSeq[i]=LesExtremes[i] ;
1716 myCase->SetBoundingBox(aSeq) ;
1718 // MESSAGE ( "CreateCase0 : Les groupes" );
1719 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile) ;
1720 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1721 aSeqGroupe->length(LesGroupes.size());
1722 std::set<std::string>::const_iterator it ;
1724 for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1725 aSeqGroupe[i++]=(*it).c_str() ;
1726 myCase->SetGroups(aSeqGroupe) ;
1729 // D. L'iteration initiale du cas
1730 MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1731 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1732 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1734 std::string NomIteration = std::string(MeshName) ;
1735 while ( (myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()) )
1737 std::ostringstream nom;
1738 nom << MeshName << monNum;
1739 NomIteration = nom.str();
1742 MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1744 // D.2. Creation de l'iteration
1745 HOMARD::HOMARD_Iteration_var anIter = newIteration();
1746 myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration] = anIter;
1747 anIter->SetName(NomIteration.c_str());
1748 AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1750 // D.4. Maillage correspondant
1751 if ( existeMeshFile != 0 )
1753 anIter->SetMeshFile(MeshFile);
1754 if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1756 anIter->SetMeshName(MeshName);
1758 // D.5. Numero d'iteration
1759 anIter->SetNumber(NumeIter);
1762 SetEtatIter(NomIteration.c_str(), -NumeIter);
1765 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1767 //=============================================================================
1768 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1770 INFOS ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1773 // A. Controle du nom :
1774 if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
1776 SALOME::ExceptionStruct es;
1777 es.type = SALOME::BAD_PARAM;
1778 es.text = "This hypothesis has already been defined.";
1779 throw SALOME::SALOME_Exception(es);
1783 // B. Creation de l'objet
1784 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1785 if (CORBA::is_nil(myHypothesis))
1787 SALOME::ExceptionStruct es;
1788 es.type = SALOME::BAD_PARAM;
1789 es.text = "Unable to create the hypothesis";
1790 throw SALOME::SALOME_Exception(es);
1793 myHypothesis->SetName(nomHypothesis);
1795 // C. Enregistrement
1796 myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
1798 SALOMEDS::SObject_var aSO;
1799 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
1801 // D. Valeurs par defaut des options avancees
1802 myHypothesis->SetNivMax(-1);
1803 myHypothesis->SetDiamMin(-1.0);
1804 myHypothesis->SetAdapInit(0);
1805 myHypothesis->SetExtraOutput(1);
1807 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1810 //=============================================================================
1811 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1812 //=============================================================================
1814 INFOS ("CreateIteration : NomIteration = " << NomIteration << ", nomIterParent = " << nomIterParent);
1817 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
1818 if (CORBA::is_nil(myIterationParent))
1820 SALOME::ExceptionStruct es;
1821 es.type = SALOME::BAD_PARAM;
1822 es.text = "The parent iteration is not defined.";
1823 throw SALOME::SALOME_Exception(es);
1827 const char* nomCas = myIterationParent->GetCaseName();
1828 MESSAGE ("CreateIteration : nomCas = " << nomCas);
1829 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1830 if (CORBA::is_nil(myCase))
1832 SALOME::ExceptionStruct es;
1833 es.type = SALOME::BAD_PARAM;
1834 es.text = "Invalid case context";
1835 throw SALOME::SALOME_Exception(es);
1838 const char* nomDirCase = myCase->GetDirName();
1840 // Controle du nom :
1841 if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
1843 SALOME::ExceptionStruct es;
1844 es.type = SALOME::BAD_PARAM;
1845 es.text = "This iteration has already been defined.";
1846 throw SALOME::SALOME_Exception(es);
1850 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1851 if (CORBA::is_nil(myIteration))
1853 SALOME::ExceptionStruct es;
1854 es.type = SALOME::BAD_PARAM;
1855 es.text = "Unable to create the iteration";
1856 throw SALOME::SALOME_Exception(es);
1859 myContextMap[GetCurrentStudyID()]._mesIterations[std::string(NomIteration)] = myIteration;
1860 // Nom de l'iteration et du maillage
1861 myIteration->SetName(NomIteration);
1862 myIteration->SetMeshName(NomIteration);
1863 myIteration->SetState(1);
1865 int numero = myIterationParent->GetNumber() + 1;
1866 myIteration->SetNumber(numero);
1868 // Nombre d'iterations deja connues pour le cas, permettant
1869 // la creation d'un sous-répertoire unique
1870 int nbitercase = myCase->GetNumberofIter();
1871 char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1872 myIteration->SetDirNameLoc(nomDirIter);
1874 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1875 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1876 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1877 // situation la plus frequente.
1878 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1879 // le nombre d'iterations du cas permet d'eviter les collisions.
1881 if ( nbitercase < 100 ) { jaux = 2 ; }
1882 else if ( nbitercase < 1000 ) { jaux = 3 ; }
1883 else if ( nbitercase < 10000 ) { jaux = 4 ; }
1884 else if ( nbitercase < 100000 ) { jaux = 5 ; }
1886 std::ostringstream iaux ;
1887 iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1888 std::stringstream MeshFile;
1889 MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1890 myIteration->SetMeshFile(MeshFile.str().c_str());
1892 // Association avec le cas
1893 std::string label = "IterationHomard_" + std::string(nomIterParent);
1894 AssociateCaseIter(nomCas, NomIteration, label.c_str());
1895 // Lien avec l'iteration precedente
1896 myIterationParent->LinkNextIteration(NomIteration);
1897 myIteration->SetIterParentName(nomIterParent);
1898 // Gestion de l'arbre d'etudes
1899 SALOMEDS::SObject_var aIterSOParent = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIterationParent)));
1900 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
1901 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1902 aStudyBuilder->NewCommand();
1903 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
1904 aStudyBuilder->Addreference(aSubSO, aIterSOParent);
1905 aStudyBuilder->CommitCommand();
1907 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1909 //=============================================================================
1910 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1912 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1915 // Controle du nom :
1916 if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
1918 MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1919 SALOME::ExceptionStruct es;
1920 es.type = SALOME::BAD_PARAM;
1921 es.text = "This boundary has already been defined";
1922 throw SALOME::SALOME_Exception(es);
1926 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1927 myBoundary->SetName(BoundaryName);
1928 myBoundary->SetType(BoundaryType);
1930 myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
1932 SALOMEDS::SObject_var aSO;
1933 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
1935 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1937 //=============================================================================
1938 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCAO(const char* BoundaryName, const char* CAOFile)
1940 INFOS ("CreateBoundaryCAO : BoundaryName = " << BoundaryName << ", CAOFile = " << CAOFile );
1941 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, -1);
1942 myBoundary->SetDataFile( CAOFile ) ;
1944 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1946 //=============================================================================
1947 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1949 INFOS ("CreateBoundaryDi : BoundaryName = " << BoundaryName << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1950 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1951 myBoundary->SetDataFile( MeshFile ) ;
1952 myBoundary->SetMeshName( MeshName ) ;
1954 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1956 //=============================================================================
1957 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1958 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1959 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1960 CORBA::Double Rayon)
1962 INFOS ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
1964 SALOME::ExceptionStruct es;
1967 { es.text = "The radius must be positive." ;
1969 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1970 if ( daux < 0.0000001 )
1971 { es.text = "The axis must be a non 0 vector." ;
1975 es.type = SALOME::BAD_PARAM;
1976 throw SALOME::SALOME_Exception(es);
1980 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1981 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1983 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1985 //=============================================================================
1986 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1987 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1988 CORBA::Double Rayon)
1990 INFOS ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
1992 SALOME::ExceptionStruct es;
1995 { es.text = "The radius must be positive." ;
1999 es.type = SALOME::BAD_PARAM;
2000 throw SALOME::SALOME_Exception(es);
2004 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
2005 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2007 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2009 //=============================================================================
2010 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
2011 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
2012 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
2014 INFOS ("CreateBoundaryConeA : BoundaryName = " << BoundaryName ) ;
2016 SALOME::ExceptionStruct es;
2018 if ( Angle <= 0.0 || Angle >= 90.0 )
2019 { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
2021 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2022 if ( daux < 0.0000001 )
2023 { es.text = "The axis must be a non 0 vector." ;
2027 es.type = SALOME::BAD_PARAM;
2028 throw SALOME::SALOME_Exception(es);
2032 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
2033 myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
2035 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2037 //=============================================================================
2038 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
2039 CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
2040 CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
2042 INFOS ("CreateBoundaryConeR : BoundaryName = " << BoundaryName ) ;
2044 SALOME::ExceptionStruct es;
2046 if ( Rayon1 < 0.0 || Rayon2 < 0.0 )
2047 { es.text = "The radius must be positive." ;
2049 double daux = fabs(Rayon2-Rayon1) ;
2050 if ( daux < 0.0000001 )
2051 { es.text = "The radius must be different." ;
2053 daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
2054 if ( daux < 0.0000001 )
2055 { es.text = "The centers must be different." ;
2059 es.type = SALOME::BAD_PARAM;
2060 throw SALOME::SALOME_Exception(es);
2064 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
2065 myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
2067 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2069 //=============================================================================
2070 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryTorus(const char* BoundaryName,
2071 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2072 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2073 CORBA::Double RayonRev, CORBA::Double RayonPri)
2075 INFOS ("CreateBoundaryTorus : BoundaryName = " << BoundaryName ) ;
2077 SALOME::ExceptionStruct es;
2079 if ( ( RayonRev <= 0.0 ) || ( RayonPri <= 0.0 ) )
2080 { es.text = "The radius must be positive." ;
2082 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2083 if ( daux < 0.0000001 )
2084 { es.text = "The axis must be a non 0 vector." ;
2088 es.type = SALOME::BAD_PARAM;
2089 throw SALOME::SALOME_Exception(es);
2093 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 5) ;
2094 myBoundary->SetTorus( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, RayonRev, RayonPri ) ;
2096 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2098 //=============================================================================
2099 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
2101 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
2104 // Controle du nom :
2105 if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
2107 SALOME::ExceptionStruct es;
2108 es.type = SALOME::BAD_PARAM;
2109 es.text = "This zone has already been defined";
2110 throw SALOME::SALOME_Exception(es);
2114 HOMARD::HOMARD_Zone_var myZone = newZone();
2115 myZone->SetName(ZoneName);
2116 myZone->SetType(ZoneType);
2118 myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
2120 SALOMEDS::SObject_var aSO;
2121 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
2123 return HOMARD::HOMARD_Zone::_duplicate(myZone);
2125 //=============================================================================
2126 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
2127 CORBA::Double Xmini, CORBA::Double Xmaxi,
2128 CORBA::Double Ymini, CORBA::Double Ymaxi,
2129 CORBA::Double Zmini, CORBA::Double Zmaxi)
2131 INFOS ("CreateZoneBox : ZoneName = " << ZoneName ) ;
2133 SALOME::ExceptionStruct es;
2135 if ( Xmini > Xmaxi )
2136 { es.text = "The X coordinates are not coherent." ;
2138 if ( Ymini > Ymaxi )
2139 { es.text = "The Y coordinates are not coherent." ;
2141 if ( Zmini > Zmaxi )
2142 { es.text = "The Z coordinates are not coherent." ;
2146 es.type = SALOME::BAD_PARAM;
2147 throw SALOME::SALOME_Exception(es);
2151 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
2152 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2154 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2156 //=============================================================================
2157 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
2158 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
2160 INFOS ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
2162 SALOME::ExceptionStruct es;
2165 { es.text = "The radius must be positive." ;
2169 es.type = SALOME::BAD_PARAM;
2170 throw SALOME::SALOME_Exception(es);
2174 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
2175 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2177 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2179 //=============================================================================
2180 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
2181 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2182 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2183 CORBA::Double Rayon, CORBA::Double Haut)
2185 INFOS ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
2187 SALOME::ExceptionStruct es;
2190 { es.text = "The radius must be positive." ;
2192 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2193 if ( daux < 0.0000001 )
2194 { es.text = "The axis must be a non 0 vector." ;
2197 { es.text = "The height must be positive." ;
2201 es.type = SALOME::BAD_PARAM;
2202 throw SALOME::SALOME_Exception(es);
2206 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
2207 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
2209 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2211 //=============================================================================
2212 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
2213 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2214 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2215 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
2217 INFOS ("CreateZonePipe : ZoneName = " << ZoneName ) ;
2219 SALOME::ExceptionStruct es;
2221 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2222 { es.text = "The radius must be positive." ;
2224 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2225 if ( daux < 0.0000001 )
2226 { es.text = "The axis must be a non 0 vector." ;
2229 { es.text = "The height must be positive." ;
2231 if ( Rayon <= Rayonint )
2232 { es.text = "The external radius must be higher than the internal radius." ;
2236 es.type = SALOME::BAD_PARAM;
2237 throw SALOME::SALOME_Exception(es);
2241 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
2242 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
2244 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2246 //=============================================================================
2247 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
2248 CORBA::Double Umini, CORBA::Double Umaxi,
2249 CORBA::Double Vmini, CORBA::Double Vmaxi,
2252 INFOS ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
2253 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
2254 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
2255 // MESSAGE ("Orient = " << Orient ) ;
2257 SALOME::ExceptionStruct es;
2259 if ( Umini > Umaxi )
2260 { es.text = "The first coordinates are not coherent." ;
2262 if ( Vmini > Vmaxi )
2263 { es.text = "The second coordinates are not coherent." ;
2265 if ( Orient < 1 || Orient > 3 )
2266 { es.text = "The orientation must be 1, 2 or 3." ;
2270 es.type = SALOME::BAD_PARAM;
2271 throw SALOME::SALOME_Exception(es);
2275 double Xmini, Xmaxi ;
2276 double Ymini, Ymaxi ;
2277 double Zmini, Zmaxi ;
2285 else if ( Orient == 2 )
2292 else if ( Orient == 3 )
2299 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2301 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2302 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2304 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2306 //=============================================================================
2307 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2308 CORBA::Double Ucentre, CORBA::Double Vcentre,
2309 CORBA::Double Rayon,
2312 INFOS ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
2314 SALOME::ExceptionStruct es;
2317 { es.text = "The radius must be positive." ;
2319 if ( Orient < 1 || Orient > 3 )
2320 { es.text = "The orientation must be 1, 2 or 3." ;
2324 es.type = SALOME::BAD_PARAM;
2325 throw SALOME::SALOME_Exception(es);
2333 { Xcentre = Ucentre ;
2336 else if ( Orient == 2 )
2339 Zcentre = Vcentre ; }
2340 else if ( Orient == 3 )
2341 { Xcentre = Vcentre ;
2343 Zcentre = Ucentre ; }
2344 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2346 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2347 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2349 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2351 //=============================================================================
2352 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2353 CORBA::Double Ucentre, CORBA::Double Vcentre,
2354 CORBA::Double Rayon, CORBA::Double Rayonint,
2357 INFOS ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
2359 SALOME::ExceptionStruct es;
2361 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2362 { es.text = "The radius must be positive." ;
2364 if ( Orient < 1 || Orient > 3 )
2365 { es.text = "The orientation must be 1, 2 or 3." ;
2367 if ( Rayon <= Rayonint )
2368 { es.text = "The external radius must be higher than the internal radius." ;
2372 es.type = SALOME::BAD_PARAM;
2373 throw SALOME::SALOME_Exception(es);
2381 { Xcentre = Ucentre ;
2384 else if ( Orient == 2 )
2387 Zcentre = Vcentre ; }
2388 else if ( Orient == 3 )
2389 { Xcentre = Vcentre ;
2391 Zcentre = Ucentre ; }
2392 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2394 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2395 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2397 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2399 //=============================================================================
2400 //=============================================================================
2405 //=============================================================================
2406 //=============================================================================
2407 // Traitement d'une iteration
2408 // etatMenage = 1 : destruction du répertoire d'execution
2409 // modeHOMARD = 1 : adaptation
2410 // != 1 : information avec les options modeHOMARD
2411 // Option1 >0 : appel depuis python
2412 // <0 : appel depuis GUI
2413 // Option2 : multiple de nombres premiers
2414 // 1 : aucune option
2415 // x2 : publication du maillage dans SMESH
2416 //=============================================================================
2417 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2419 INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2424 // A.1. L'objet iteration
2425 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
2426 ASSERT(!CORBA::is_nil(myIteration));
2428 // A.2. Controle de la possibilite d'agir
2429 // A.2.1. Etat de l'iteration
2430 int etat = myIteration->GetState();
2431 MESSAGE ( "etat = "<<etat );
2432 // A.2.2. On ne calcule pas l'iteration initiale, ni une iteration deja calculee
2433 if ( modeHOMARD == 1 )
2437 SALOME::ExceptionStruct es;
2438 es.type = SALOME::BAD_PARAM;
2439 es.text = "This iteration is the first of the case and cannot be computed.";
2440 throw SALOME::SALOME_Exception(es);
2443 else if ( ( etat == 2 ) & ( modeHOMARD == 1 ) )
2445 SALOME::ExceptionStruct es;
2446 es.type = SALOME::BAD_PARAM;
2447 es.text = "This iteration is already computed.";
2448 throw SALOME::SALOME_Exception(es);
2452 // A.2.3. On n'analyse pas une iteration non calculee
2457 SALOME::ExceptionStruct es;
2458 es.type = SALOME::BAD_PARAM;
2459 es.text = "This iteration is not computed.";
2460 throw SALOME::SALOME_Exception(es);
2465 // A.3. Numero de l'iteration
2466 // siterp1 : numero de l'iteration a traiter
2468 // siter : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2469 // Ou si information :
2471 int NumeIter = myIteration->GetNumber();
2472 std::string siterp1 ;
2473 std::stringstream saux1 ;
2475 siterp1 = saux1.str() ;
2476 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2479 if ( modeHOMARD==1 )
2481 std::stringstream saux0 ;
2482 int iaux = max(0, NumeIter-1) ;
2484 siter = saux0.str() ;
2485 if (NumeIter < 11) { siter = "0" + siter ; }
2488 { siter = siterp1 ; }
2491 const char* nomCas = myIteration->GetCaseName();
2492 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
2493 ASSERT(!CORBA::is_nil(myCase));
2495 // B. Les répertoires
2496 // B.1. Le répertoire courant
2497 std::string nomDirWork = getenv("PWD") ;
2498 // B.2. Le sous-répertoire de l'iteration a traiter
2499 char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2500 MESSAGE( ". DirCompute = " << DirCompute );
2502 // C. Le fichier des messages
2503 // C.1. Le deroulement de l'execution de HOMARD
2504 std::string LogFile = DirCompute ;
2505 LogFile += "/Liste" ;
2506 if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2508 MESSAGE (". LogFile = " << LogFile);
2509 if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2510 // C.2. Le bilan de l'analyse du maillage
2511 std::string FileInfo = DirCompute ;
2513 if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2515 { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2516 else { FileInfo += "info_ap" ; }
2518 FileInfo += "." + siterp1 + ".bilan" ;
2519 myIteration->SetFileInfo(FileInfo.c_str());
2521 // D. On passe dans le répertoire de l'iteration a calculer
2522 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2525 // E. Les données de l'exécution HOMARD
2526 // E.1. L'objet du texte du fichier de configuration
2527 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2528 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2530 // E.2. Le maillage associe a l'iteration
2531 const char* NomMesh = myIteration->GetMeshName();
2532 MESSAGE ( ". NomMesh = " << NomMesh );
2533 const char* MeshFile = myIteration->GetMeshFile();
2534 MESSAGE ( ". MeshFile = " << MeshFile );
2536 // E.3. Les données du traitement HOMARD
2538 if ( modeHOMARD == 1 )
2541 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2542 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2543 codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2547 InvalideIterInfo(NomIteration);
2548 myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2550 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2551 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2552 myDriver->CreeFichierDonn();
2555 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2556 int BoundaryOption = DriverTexteBoundary(myCase, myDriver) ;
2558 // E.5. Ecriture du texte dans le fichier
2559 MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2561 { myDriver->CreeFichier(); }
2565 int codretexec = 1789 ;
2568 codretexec = myDriver->ExecuteHomard(Option1);
2570 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2571 // En mode adaptation, on ajuste l'etat de l'iteration
2572 if ( modeHOMARD == 1 )
2574 if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2575 else { SetEtatIter(NomIteration,1); }
2576 // GERALD -- QMESSAGE BOX
2580 // H. Gestion des resultats
2583 std::string Commentaire ;
2584 // H.1. Le fichier des messages, dans tous les cas
2585 Commentaire = "log" ;
2586 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2587 else { Commentaire += "Info" ; }
2588 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2590 // H.2. Si tout s'est bien passe :
2591 if (codretexec == 0)
2593 // H.2.1. Le fichier de bilan
2594 Commentaire = "Summary" ;
2595 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2596 else { Commentaire += "Info" ; }
2597 PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2598 // H.2.2. Le fichier de maillage obtenu
2599 if ( modeHOMARD == 1 )
2601 std::stringstream saux0 ;
2602 Commentaire = "Mesh" ;
2603 Commentaire += " " + siterp1 ;
2604 PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2605 if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2608 // H.3 Message d'erreur
2609 if (codretexec != 0)
2611 std::string text = "" ;
2612 // Message d'erreur en cas de probleme en adaptation
2613 if ( modeHOMARD == 1 )
2615 text = "Error during the adaptation.\n" ;
2616 bool stopvu = false ;
2617 std::ifstream fichier( LogFile.c_str() );
2618 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
2620 std::string ligne; // variable contenant chaque ligne lue
2621 while ( std::getline( fichier, ligne ) )
2625 { text += ligne+ "\n"; }
2628 int position = ligne.find( "===== HOMARD ===== STOP =====" ) ;
2629 if ( position > 0 ) { stopvu = true ; }
2634 text += "\n\nSee the file " + LogFile + "\n" ;
2636 SALOME::ExceptionStruct es;
2637 es.type = SALOME::BAD_PARAM;
2638 es.text = CORBA::string_dup(text.c_str());
2639 throw SALOME::SALOME_Exception(es);
2641 // En mode information, on force le succes pour pouvoir consulter le fichier log
2642 if ( modeHOMARD != 1 ) { codretexec = 0 ; }
2646 // I. Menage et retour dans le répertoire du cas
2650 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2652 CHDIR(nomDirWork.c_str());
2655 // J. Suivi de la frontière CAO
2656 // std::cout << "- codret : " << codret << std::endl;
2657 // std::cout << "- modeHOMARD : " << modeHOMARD << std::endl;
2658 // std::cout << "- BoundaryOption : " << BoundaryOption << std::endl;
2659 // std::cout << "- codretexec : " << codretexec << std::endl;
2662 if ( ( modeHOMARD == 1 ) && ( BoundaryOption % 5 == 0 ) && (codretexec == 0) )
2664 INFOS ( "Suivi de frontière CAO" );
2665 codret = ComputeCAO(myCase, myIteration, Option1, Option2) ;
2671 //=============================================================================
2672 // Calcul d'une iteration : partie spécifique à l'adaptation
2673 //=============================================================================
2674 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)
2676 MESSAGE ( "ComputeAdap avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2681 // Numero de l'iteration
2682 int NumeIter = myIteration->GetNumber();
2683 std::stringstream saux0 ;
2684 saux0 << NumeIter-1 ;
2685 std::string siter = saux0.str() ;
2686 if (NumeIter < 11) { siter = "0" + siter ; }
2688 // A.2. On verifie qu il y a une hypothese (erreur improbable);
2689 const char* nomHypo = myIteration->GetHypoName();
2690 if (std::string(nomHypo) == std::string(""))
2692 SALOME::ExceptionStruct es;
2693 es.type = SALOME::BAD_PARAM;
2694 es.text = "This iteration does not have any associated hypothesis.";
2695 throw SALOME::SALOME_Exception(es);
2698 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
2699 ASSERT(!CORBA::is_nil(myHypo));
2701 // B. L'iteration parent
2702 const char* nomIterationParent = myIteration->GetIterParentName();
2703 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2704 ASSERT(!CORBA::is_nil(myIterationParent));
2705 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2706 if ( myIterationParent->GetState() == 1 )
2709 int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2712 // GERALD -- QMESSAGE BOX
2713 VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2717 // C. Le sous-répertoire de l'iteration precedente
2718 char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2719 MESSAGE( ". DirComputePa = " << DirComputePa );
2721 // D. Les données de l'adaptation HOMARD
2722 // D.1. Le type de conformite
2723 int ConfType = myCase->GetConfType();
2724 MESSAGE ( ". ConfType = " << ConfType );
2726 // D.1. Le type externe
2727 int ExtType = myCase->GetExtType();
2728 MESSAGE ( ". ExtType = " << ExtType );
2730 // D.3. Le maillage de depart
2731 const char* NomMeshParent = myIterationParent->GetMeshName();
2732 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2733 const char* MeshFileParent = myIterationParent->GetMeshFile();
2734 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2736 // D.4. Le maillage associe a l'iteration
2737 const char* MeshFile = myIteration->GetMeshFile();
2738 MESSAGE ( ". MeshFile = " << MeshFile );
2739 FILE *file = fopen(MeshFile,"r");
2743 if (etatMenage == 0)
2745 SALOME::ExceptionStruct es;
2746 es.type = SALOME::BAD_PARAM;
2747 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2748 es.text = CORBA::string_dup(text.c_str());
2749 throw SALOME::SALOME_Exception(es);
2754 std::string commande = "rm -f " + std::string(MeshFile);
2755 codret = system(commande.c_str());
2758 SALOME::ExceptionStruct es;
2759 es.type = SALOME::BAD_PARAM;
2760 es.text = "The mesh file cannot be deleted.";
2761 throw SALOME::SALOME_Exception(es);
2767 // D.5. Les types de raffinement et de deraffinement
2768 // Les appels corba sont lourds, il vaut mieux les grouper
2769 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2770 ASSERT(ListTypes->length() == 3);
2771 int TypeAdap = (*ListTypes)[0];
2772 int TypeRaff = (*ListTypes)[1];
2773 int TypeDera = (*ListTypes)[2];
2774 // MESSAGE ( ". TypeAdap = " << TypeAdap << ", TypeRaff = " << TypeRaff << ", TypeDera = " << TypeDera );
2776 // E. Texte du fichier de configuration
2777 // E.1. Incontournables du texte
2778 myDriver->TexteAdap(ExtType);
2780 myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2781 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2782 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2784 // E.2. Ajout des informations liees aux zones eventuelles
2785 if ( TypeAdap == 0 )
2786 { DriverTexteZone(myHypo, myDriver) ; }
2788 // E.3. Ajout des informations liees aux champs eventuels
2789 if ( TypeAdap == 1 )
2790 { DriverTexteField(myIteration, myHypo, myDriver) ; }
2792 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2793 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2794 int numberOfGroups = listeGroupes->length();
2795 MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2796 if (numberOfGroups > 0)
2798 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2800 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2801 MESSAGE( "... GroupName = " << GroupName );
2802 myDriver->TexteGroup(GroupName);
2806 // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2807 DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2809 // E.6. Ajout des options avancees
2810 int Pyram = myCase->GetPyram();
2811 MESSAGE ( ". Pyram = " << Pyram );
2812 int NivMax = myHypo->GetNivMax();
2813 MESSAGE ( ". NivMax = " << NivMax );
2814 double DiamMin = myHypo->GetDiamMin() ;
2815 MESSAGE ( ". DiamMin = " << DiamMin );
2816 int AdapInit = myHypo->GetAdapInit();
2817 MESSAGE ( ". AdapInit = " << AdapInit );
2818 int ExtraOutput = myHypo->GetExtraOutput();
2819 MESSAGE ( ". ExtraOutput = " << ExtraOutput );
2820 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, ExtraOutput);
2822 // E.7. Ajout des informations sur le deroulement de l'execution
2823 int MessInfo = myIteration->GetInfoCompute();
2824 MESSAGE ( ". MessInfo = " << MessInfo );
2825 myDriver->TexteInfoCompute(MessInfo);
2829 //=============================================================================
2830 // Calcul d'une iteration : partie spécifique au suivi de frontière CAO
2831 //=============================================================================
2832 CORBA::Long HOMARD_Gen_i::ComputeCAO(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long Option1, CORBA::Long Option2)
2834 MESSAGE ( "ComputeCAO avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2839 // A.2. Le sous-répertoire de l'iteration en cours de traitement
2840 char* DirCompute = myIteration->GetDirName();
2841 // A.3. Le maillage résultat de l'iteration en cours de traitement
2842 char* MeshFile = myIteration->GetMeshFile();
2844 // B. Les données pour FrontTrack
2845 // B.1. Le maillage à modifier
2846 const std::string theInputMedFile = MeshFile;
2847 MESSAGE ( ". theInputMedFile = " << theInputMedFile );
2849 // B.2. Le maillage après modification : fichier identique
2850 const std::string theOutputMedFile = MeshFile ;
2851 MESSAGE ( ". theOutputMedFile = " << theInputMedFile );
2853 // B.3. La liste des fichiers contenant les numéros des noeuds à bouger
2854 std::vector< std::string > theInputNodeFiles ;
2855 MESSAGE ( ". DirCompute = " << DirCompute );
2860 struct dirent *dirp;
2861 dp = opendir(DirCompute);
2862 while ( (dirp = readdir(dp)) != NULL )
2864 std::string file_name(dirp->d_name);
2865 bilan = file_name.find("fr") ;
2866 if ( bilan != string::npos )
2868 std::stringstream filename_total ;
2869 filename_total << DirCompute << "/" << file_name ;
2870 theInputNodeFiles.push_back(filename_total.str()) ;
2875 HANDLE hFind = INVALID_HANDLE_VALUE;
2876 WIN32_FIND_DATA ffd;
2877 hFind = FindFirstFile(DirNameStart, &ffd);
2878 if (INVALID_HANDLE_VALUE != hFind) {
2879 while (FindNextFile(hFind, &ffd) != 0) {
2880 std::string file_name(ffd.cFileName);
2881 bilan = file_name.find("fr") ;
2882 if ( bilan != string::npos )
2884 std::stringstream filename_total ;
2885 filename_total << DirCompute << "/" << file_name ;
2886 theInputNodeFiles.push_back(filename_total.str()) ;
2893 for ( int i = 0; i < icpt; i++ )
2894 { MESSAGE ( ". theInputNodeFiles["<< i << "] = " << theInputNodeFiles[i] ); }
2896 // B.4. Le fichier de la CAO
2897 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2898 std::string BoundaryName = std::string((*ListBoundaryGroupType)[0]);
2899 MESSAGE ( ". BoundaryName = " << BoundaryName );
2900 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2901 const std::string theXaoFileName = myBoundary->GetDataFile();
2902 MESSAGE ( ". theXaoFileName = " << theXaoFileName );
2904 // B.5. Parallélisme
2905 bool theIsParallel = false;
2907 // C. Lancement des projections
2908 MESSAGE ( ". Lancement des projections" );
2909 FrontTrack* myFrontTrack = new FrontTrack();
2910 myFrontTrack->track(theInputMedFile, theOutputMedFile, theInputNodeFiles, theXaoFileName, theIsParallel);
2912 // D. Transfert des coordonnées modifiées dans le fichier historique de HOMARD
2913 // On lance une exécution spéciale de HOMARD en attendant de savoir le faire avec MEDCoupling
2914 MESSAGE ( ". Transfert des coordonnées" );
2915 codret = ComputeCAObis(myIteration, Option1, Option2) ;
2919 //=============================================================================
2920 //=============================================================================
2921 // Transfert des coordonnées en suivi de frontière CAO
2922 // Option1 >0 : appel depuis python
2923 // <0 : appel depuis GUI
2924 // Option2 : multiple de nombres premiers
2925 // 1 : aucune option
2926 // x2 : publication du maillage dans SMESH
2927 //=============================================================================
2928 CORBA::Long HOMARD_Gen_i::ComputeCAObis(HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long Option1, CORBA::Long Option2)
2930 MESSAGE ( "ComputeCAObis, avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2935 // A.1. Controle de la possibilite d'agir
2936 // A.1.1. Etat de l'iteration
2937 int etat = myIteration->GetState();
2938 MESSAGE ( "etat = "<<etat );
2939 // A.1.2. L'iteration doit être calculee
2942 SALOME::ExceptionStruct es;
2943 es.type = SALOME::BAD_PARAM;
2944 es.text = "This iteration is not computed.";
2945 throw SALOME::SALOME_Exception(es);
2948 // A.2. Numero de l'iteration
2949 // siterp1 : numero de l'iteration a traiter
2950 int NumeIter = myIteration->GetNumber();
2951 std::string siterp1 ;
2952 std::stringstream saux1 ;
2954 siterp1 = saux1.str() ;
2955 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2956 MESSAGE ( "siterp1 = "<<siterp1 );
2959 const char* nomCas = myIteration->GetCaseName();
2960 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
2961 ASSERT(!CORBA::is_nil(myCase));
2963 // A.4. Le sous-répertoire de l'iteration a traiter
2964 char* DirCompute = myIteration->GetDirName();
2965 MESSAGE( ". DirCompute = " << DirCompute );
2967 // C. Le fichier des messages
2968 std::string LogFile = DirCompute ;
2969 LogFile += "/Liste." + siterp1 + ".maj_coords.log" ;
2970 MESSAGE (". LogFile = " << LogFile);
2971 myIteration->SetFileInfo(LogFile.c_str());
2973 // D. On passe dans le répertoire de l'iteration a calculer
2974 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2977 // E. Les données de l'exécution HOMARD
2978 // E.1. L'objet du texte du fichier de configuration
2979 HomardDriver* myDriver = new HomardDriver("", siterp1);
2980 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2982 // E.2. Le maillage associe a l'iteration
2983 const char* NomMesh = myIteration->GetMeshName();
2984 MESSAGE ( ". NomMesh = " << NomMesh );
2985 const char* MeshFile = myIteration->GetMeshFile();
2986 MESSAGE ( ". MeshFile = " << MeshFile );
2988 // E.3. Les données du traitement HOMARD
2990 myDriver->TexteMajCoords( NumeIter ) ;
2992 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2993 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2995 // E.4. Ecriture du texte dans le fichier
2996 MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2998 { myDriver->CreeFichier(); }
3002 int codretexec = 1789 ;
3005 codretexec = myDriver->ExecuteHomard(Option1);
3006 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
3009 // G. Gestion des resultats
3012 // G.1. Le fichier des messages, dans tous les cas
3013 const char* NomIteration = myIteration->GetName();
3014 std::string Commentaire = "logmaj_coords" ;
3015 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
3016 // G.2 Message d'erreur
3017 if (codretexec != 0)
3019 std::string text = "\n\nSee the file " + LogFile + "\n" ;
3021 SALOME::ExceptionStruct es;
3022 es.type = SALOME::BAD_PARAM;
3023 es.text = CORBA::string_dup(text.c_str());
3024 throw SALOME::SALOME_Exception(es);
3026 // On force le succes pour pouvoir consulter le fichier log
3031 // H. Menage et retour dans le répertoire du cas
3032 if (codret == 0) { delete myDriver; }
3036 //=============================================================================
3037 // Creation d'un nom de sous-répertoire pour l'iteration au sein d'un répertoire parent
3038 // nomrep : nom du répertoire parent
3039 // num : le nom du sous-répertoire est sous la forme 'In', n est >= num
3040 //=============================================================================
3041 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
3043 MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
3044 // On verifie que le répertoire parent existe
3045 int codret = CHDIR(nomrep) ;
3048 SALOME::ExceptionStruct es;
3049 es.type = SALOME::BAD_PARAM;
3050 es.text = "The directory of the case does not exist.";
3051 throw SALOME::SALOME_Exception(es);
3054 std::string nomDirActuel = getenv("PWD") ;
3055 std::string DirName ;
3056 // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un répertoire inconnu
3057 bool a_chercher = true ;
3058 while ( a_chercher )
3060 // On passe dans le répertoire parent
3063 // On recherche un nom sous la forme Iabc, avec abc representant le numero
3065 if ( num < 100 ) { jaux = 2 ; }
3066 else if ( num < 1000 ) { jaux = 3 ; }
3067 else if ( num < 10000 ) { jaux = 4 ; }
3068 else if ( num < 100000 ) { jaux = 5 ; }
3070 std::ostringstream iaux ;
3071 iaux << std::setw(jaux) << std::setfill('0') << num ;
3072 std::ostringstream DirNameA ;
3073 DirNameA << "I" << iaux.str();
3074 // Si on ne pas peut entrer dans le répertoire, on doit verifier
3075 // que c'est bien un probleme d'absence
3076 if ( CHDIR(DirNameA.str().c_str()) != 0 )
3078 bool existe = false ;
3081 struct dirent *dirp;
3082 dp = opendir(nomrep);
3083 while ( (dirp = readdir(dp)) != NULL )
3085 std::string file_name(dirp->d_name);
3087 HANDLE hFind = INVALID_HANDLE_VALUE;
3088 WIN32_FIND_DATA ffd;
3089 hFind = FindFirstFile(nomrep, &ffd);
3090 if (INVALID_HANDLE_VALUE != hFind) {
3091 while (FindNextFile(hFind, &ffd) != 0) {
3092 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
3093 std::string file_name(ffd.cFileName);
3095 if ( file_name == DirNameA.str() ) { existe = true ; }
3104 DirName = DirNameA.str() ;
3105 a_chercher = false ;
3112 MESSAGE ( "==> DirName = " << DirName);
3113 MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
3114 CHDIR(nomDirActuel.c_str());
3115 return CORBA::string_dup( DirName.c_str() );
3117 //=============================================================================
3118 // Calcul d'une iteration : gestion du répertoire de calcul
3119 // Si le sous-répertoire existe :
3120 // etatMenage = 0 : on sort en erreur si le répertoire n'est pas vide
3121 // etatMenage = 1 : on fait le menage du répertoire
3122 // etatMenage = -1 : on ne fait rien
3123 //=============================================================================
3124 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
3126 MESSAGE ( "ComputeDirManagement : répertoires pour le calcul" );
3127 // B.2. Le répertoire du cas
3128 const char* nomDirCase = myCase->GetDirName();
3129 MESSAGE ( ". nomDirCase = " << nomDirCase );
3131 // B.3. Le sous-répertoire de l'iteration a calculer, puis le répertoire complet a creer
3132 // B.3.1. Le nom du sous-répertoire
3133 const char* nomDirIt = myIteration->GetDirNameLoc();
3135 // B.3.2. Le nom complet du sous-répertoire
3136 std::stringstream DirCompute ;
3137 DirCompute << nomDirCase << "/" << nomDirIt;
3138 MESSAGE (". DirCompute = " << DirCompute.str() );
3140 // B.3.3. Si le sous-répertoire n'existe pas, on le cree
3141 if (CHDIR(DirCompute.str().c_str()) != 0)
3144 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
3146 if (_mkdir(DirCompute.str().c_str()) != 0)
3149 // GERALD -- QMESSAGE BOX
3150 std::cerr << "Pb Creation du répertoire DirCompute = " << DirCompute.str() << std::endl;
3151 VERIFICATION("Pb a la creation du répertoire" == 0);
3156 // Le répertoire existe
3157 // On demande de faire le menage de son contenu :
3158 if (etatMenage == 1)
3160 MESSAGE (". Menage du répertoire DirCompute = " << DirCompute.str());
3161 std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
3162 int codret = system(commande.c_str());
3165 // GERALD -- QMESSAGE BOX
3166 std::cerr << ". Menage du répertoire de calcul" << DirCompute.str() << std::endl;
3167 VERIFICATION("Pb au menage du répertoire de calcul" == 0);
3170 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
3173 if (etatMenage == 0)
3177 struct dirent *dirp;
3178 dp = opendir(DirCompute.str().c_str());
3180 while ((dirp = readdir(dp)) != NULL && result )
3182 std::string file_name(dirp->d_name);
3183 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3187 HANDLE hFind = INVALID_HANDLE_VALUE;
3188 WIN32_FIND_DATA ffd;
3189 hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
3191 if (INVALID_HANDLE_VALUE != hFind) {
3192 while (FindNextFile(hFind, &ffd) != 0) {
3193 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
3194 std::string file_name(ffd.cFileName);
3195 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3200 if ( result == false)
3202 SALOME::ExceptionStruct es;
3203 es.type = SALOME::BAD_PARAM;
3204 std::string text = "Directory : " + DirCompute.str() + " is not empty";
3205 es.text = CORBA::string_dup(text.c_str());
3206 throw SALOME::SALOME_Exception(es);
3207 VERIFICATION("Directory is not empty" == 0);
3213 return CORBA::string_dup( DirCompute.str().c_str() );
3215 //=============================================================================
3216 // Calcul d'une iteration : gestion du répertoire de calcul de l'iteration parent
3217 //=============================================================================
3218 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
3220 MESSAGE ( "ComputeDirPaManagement : répertoires pour le calcul" );
3221 // Le répertoire du cas
3222 const char* nomDirCase = myCase->GetDirName();
3223 MESSAGE ( ". nomDirCase = " << nomDirCase );
3225 // Le sous-répertoire de l'iteration precedente
3227 const char* nomIterationParent = myIteration->GetIterParentName();
3228 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
3229 const char* nomDirItPa = myIterationParent->GetDirNameLoc();
3230 std::stringstream DirComputePa ;
3231 DirComputePa << nomDirCase << "/" << nomDirItPa;
3232 MESSAGE( ". nomDirItPa = " << nomDirItPa);
3233 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
3235 return CORBA::string_dup( DirComputePa.str().c_str() );
3237 //=============================================================================
3238 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
3239 //=============================================================================
3240 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3242 MESSAGE ( "... DriverTexteZone" );
3243 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3244 int numberOfZonesx2 = ListZone->length();
3247 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3249 std::string ZoneName = std::string((*ListZone)[iaux]);
3250 MESSAGE ( "... ZoneName = " << ZoneName);
3251 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
3252 ASSERT(!CORBA::is_nil(myZone));
3254 int ZoneType = myZone->GetType();
3255 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
3256 int TypeUse = atoi( TypeUsestr.c_str() );
3257 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
3258 NumZone = iaux/2 + 1 ;
3259 HOMARD::double_array* zone = myZone->GetCoords();
3260 if ( ZoneType == 2 || ( ZoneType>=11 && ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
3261 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
3262 else if ( ZoneType == 4 ) // Cas d une sphere
3263 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
3264 else if ( ZoneType == 5 || ( ZoneType>=31 && ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
3265 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
3266 else if ( ZoneType == 7 || ( ZoneType>=61 && ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
3267 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
3268 else { VERIFICATION("ZoneType est incorrect." == 0) ; }
3273 //=============================================================================
3274 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
3275 //=============================================================================
3276 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3278 MESSAGE ( "... DriverTexteField" );
3279 // Le fichier du champ
3280 char* FieldFile = myIteration->GetFieldFile();
3281 MESSAGE ( ". FieldFile = " << FieldFile );
3282 if (strlen(FieldFile) == 0)
3284 // GERALD -- QMESSAGE BOX
3285 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
3286 VERIFICATION("The file for the field is not given." == 0);
3288 // Les caracteristiques d'instants du champ de pilotage
3289 int TimeStep = myIteration->GetTimeStep();
3290 MESSAGE( ". TimeStep = " << TimeStep );
3291 int Rank = myIteration->GetRank();
3292 MESSAGE( ". Rank = " << Rank );
3293 // Les informations sur les champs
3294 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
3296 const char* FieldName = aInfosHypo->FieldName;
3298 int TypeThR = aInfosHypo->TypeThR;
3299 double ThreshR = aInfosHypo->ThreshR;
3300 int TypeThC = aInfosHypo->TypeThC;
3301 double ThreshC = aInfosHypo->ThreshC;
3302 // Saut entre mailles ou non ?
3303 int UsField = aInfosHypo->UsField;
3304 MESSAGE( ". UsField = " << UsField );
3305 // L'usage des composantes
3306 int UsCmpI = aInfosHypo->UsCmpI;
3307 MESSAGE( ". UsCmpI = " << UsCmpI );
3309 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
3312 HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
3313 int numberOfCompos = mescompo->length();
3314 MESSAGE( ". numberOfCompos = " << numberOfCompos );
3315 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
3317 std::string nomCompo = std::string((*mescompo)[NumeComp]);
3318 MESSAGE( "... nomCompo = " << nomCompo );
3319 myDriver->TexteCompo(NumeComp, nomCompo);
3323 //=============================================================================
3324 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
3325 // On ecrit dans l'ordre :
3326 // 1. la definition des frontieres
3327 // 2. les liens avec les groupes
3328 // 3. un entier resumant le type de comportement pour les frontieres
3329 //=============================================================================
3330 int HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
3332 MESSAGE ( "... DriverTexteBoundary" );
3333 // 1. Recuperation des frontieres
3334 std::list<std::string> ListeBoundaryTraitees ;
3335 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3336 int numberOfitems = ListBoundaryGroupType->length();
3337 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
3338 int BoundaryOption = 1 ;
3339 // 2. Parcours des frontieres pour ecrire leur description
3340 int NumBoundaryAnalytical = 0 ;
3341 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3343 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3344 MESSAGE ( "... BoundaryName = " << BoundaryName);
3345 // 2.1. La frontiere a-t-elle deja ete ecrite ?
3346 // Cela arrive quand elle est liee a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
3348 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3349 while (it != ListeBoundaryTraitees.end())
3351 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3352 if ( BoundaryName == *it ) { A_faire = 0 ; }
3355 // 2.2. Ecriture de la frontiere
3358 // 2.2.1. Caracteristiques de la frontiere
3359 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3360 ASSERT(!CORBA::is_nil(myBoundary));
3361 int BoundaryType = myBoundary->GetType();
3362 MESSAGE ( "... BoundaryType = " << BoundaryType );
3363 // 2.2.2. Ecriture selon le type
3364 // 2.2.2.1. Cas d une frontiere CAO
3365 if (BoundaryType == -1)
3367 // const char* CAOFile = myBoundary->GetDataFile() ;
3368 // MESSAGE ( ". CAOFile = " << CAOFile );
3369 if ( BoundaryOption % 5 != 0 ) { BoundaryOption = BoundaryOption*5 ; }
3371 // 2.2.2.2. Cas d une frontiere discrete
3372 else if (BoundaryType == 0)
3374 const char* MeshName = myBoundary->GetMeshName() ;
3375 MESSAGE ( ". MeshName = " << MeshName );
3376 const char* MeshFile = myBoundary->GetDataFile() ;
3377 MESSAGE ( ". MeshFile = " << MeshFile );
3378 myDriver->TexteBoundaryDi( MeshName, MeshFile);
3379 if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
3381 // 2.2.2.3. Cas d une frontiere analytique
3384 NumBoundaryAnalytical++ ;
3385 HOMARD::double_array* coor = myBoundary->GetCoords();
3386 if (BoundaryType == 1) // Cas d un cylindre
3388 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3389 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3391 else if (BoundaryType == 2) // Cas d une sphere
3393 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
3394 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3396 else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
3398 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3399 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3401 else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
3403 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3404 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3406 else if (BoundaryType == 5) // Cas d un tore
3408 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3409 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3412 // 2.2.3. Memorisation du traitement
3413 ListeBoundaryTraitees.push_back( BoundaryName );
3416 // 3. Parcours des frontieres pour ecrire les liens avec les groupes
3417 NumBoundaryAnalytical = 0 ;
3418 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3420 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3421 MESSAGE ( "... BoundaryName = " << BoundaryName);
3422 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3423 ASSERT(!CORBA::is_nil(myBoundary));
3424 int BoundaryType = myBoundary->GetType();
3425 MESSAGE ( "... BoundaryType = " << BoundaryType );
3426 // 3.1. Recuperation du nom du groupe
3427 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
3428 MESSAGE ( "... GroupName = " << GroupName);
3429 // 3.2. Cas d une frontiere CAO
3430 if ( BoundaryType == -1 )
3432 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryCAOGr ( GroupName ) ; }
3434 // 3.3. Cas d une frontiere discrete
3435 else if ( BoundaryType == 0 )
3437 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
3439 // 3.4. Cas d une frontiere analytique
3442 NumBoundaryAnalytical++ ;
3443 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
3446 // 4. Ecriture de l'option finale
3447 myDriver->TexteBoundaryOption(BoundaryOption);
3449 return BoundaryOption ;
3451 //=============================================================================
3452 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3453 //=============================================================================
3454 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3456 MESSAGE ( "... DriverTexteFieldInterp" );
3457 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3458 MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3459 if (TypeFieldInterp != 0)
3461 // Le fichier des champs
3462 char* FieldFile = myIteration->GetFieldFile();
3463 MESSAGE ( ". FieldFile = " << FieldFile );
3464 if (strlen(FieldFile) == 0)
3466 // GERALD -- QMESSAGE BOX
3467 VERIFICATION("The file for the field is not given." == 0);
3470 const char* MeshFile = myIteration->GetMeshFile();
3471 myDriver->TexteFieldInterp(FieldFile, MeshFile);
3474 // Interpolation de tous les champs
3475 if ( TypeFieldInterp == 1 )
3477 myDriver->TexteFieldInterpAll();
3479 // Interpolation de certains champs
3480 else if (TypeFieldInterp == 2)
3482 // Les champs et leurs instants pour l'iteration
3483 HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3484 int numberOfFieldsx3 = ListFieldTSR->length();
3485 MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3486 // Les champs pour l'hypothese
3487 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3488 int numberOfFieldsx2 = ListField->length();
3489 MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3490 // On parcourt tous les champs de l'hypothese
3492 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3495 std::string FieldName = std::string((*ListField)[iaux]) ;
3496 // Le type d'interpolation
3497 std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3498 MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3499 // On cherche à savoir si des instants ont été précisés pour cette itération
3501 for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3504 std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3505 MESSAGE( "..... FieldName2 = " << FieldName2 );
3506 // Quand c'est le bon champ, on ecrit le pas de temps
3507 if ( FieldName == FieldName2 )
3511 std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3512 // Le numero d'ordre
3513 std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3514 MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3516 int TimeStep = atoi( TimeStepstr.c_str() );
3517 int Rank = atoi( Rankstr.c_str() );
3518 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3522 // Si aucun instant n'a été défini
3526 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3534 //===========================================================================
3535 //===========================================================================
3538 //===========================================================================
3539 //===========================================================================
3541 //===========================================================================
3542 //===========================================================================
3543 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
3544 SALOMEDS::SObject_ptr theSObject,
3545 CORBA::Object_ptr theObject,
3546 const char* theName)
3548 MESSAGE("PublishInStudy pour " << theName);
3549 SALOMEDS::SObject_var aResultSO;
3550 if (CORBA::is_nil(theStudy))
3552 SALOME::ExceptionStruct es;
3553 es.type = SALOME::BAD_PARAM;
3554 es.text = "Invalid study context";
3555 throw SALOME::SALOME_Exception(es);
3559 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3560 // Rq : Iteration est publiee ailleurs
3561 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3562 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
3563 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3564 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3565 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3567 addInStudy(theStudy);
3569 // Controle de la non publication d'un objet de meme nom
3570 if ( (!aBoundary->_is_nil()) || (!aHypo->_is_nil()) || (!aYACS->_is_nil()) || (!aZone->_is_nil()) )
3572 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
3573 if (listSO->length() >= 1)
3575 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3576 aResultSO = listSO[0];
3577 return aResultSO._retn();
3581 // Caracteristiques de l'etude
3582 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
3583 aStudyBuilder->NewCommand();
3584 if(!aBoundary->_is_nil())
3585 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
3586 else if(!aCase->_is_nil())
3587 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
3588 else if(!aHypo->_is_nil())
3589 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
3590 else if(!aYACS->_is_nil())
3591 aResultSO = PublishYACSInStudy(theStudy, aStudyBuilder, aYACS, theName);
3592 else if(!aZone->_is_nil())
3593 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
3595 aStudyBuilder->CommitCommand();
3597 return aResultSO._retn();
3599 //=============================================================================
3600 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3601 SALOMEDS::StudyBuilder_var aStudyBuilder,
3602 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3604 MESSAGE("PublishBoundaryStudy pour "<<theName);
3605 SALOMEDS::SObject_var aResultSO;
3607 // Caracteristique de la Boundary
3608 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3610 // On recupere le module pere dans l etude
3611 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3612 if (theFatherHomard->_is_nil())
3614 MESSAGE("theFatherHomard->_is_nil()");
3615 return aResultSO._retn();
3618 // On ajoute la categorie des boundarys dans l etude si necessaire
3619 if ( _tag_boun == 0 )
3622 _tag_boun = _tag_gene ;
3624 MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3625 SALOMEDS::SObject_var aSObject;
3626 if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3628 MESSAGE("Ajout de la categorie des boundarys");
3629 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3630 PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3632 else { MESSAGE("La categorie des boundarys existe deja."); }
3634 CORBA::Long BoundaryType = myBoundary->GetType();
3635 // MESSAGE("BoundaryType : "<<BoundaryType);
3638 switch (BoundaryType)
3641 { value = "BoundaryCAOHomard" ;
3642 icone = "geometry.png" ;
3646 { value = "BoundaryDiHomard" ;
3647 icone = "mesh_tree_mesh.png" ;
3651 { value = "BoundaryAnHomard" ;
3652 icone = "cylinderpointvector_2.png" ;
3656 { value = "BoundaryAnHomard" ;
3657 icone = "spherepoint_2.png" ;
3661 { value = "BoundaryAnHomard" ;
3662 icone = "conepointvector.png" ;
3666 { value = "BoundaryAnHomard" ;
3667 icone = "conedxyz.png" ;
3671 { value = "BoundaryAnHomard" ;
3672 icone = "toruspointvector.png" ;
3676 aResultSO = aStudyBuilder->NewObject(aSObject);
3677 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3678 return aResultSO._retn();
3680 //=============================================================================
3681 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
3682 SALOMEDS::StudyBuilder_var aStudyBuilder,
3683 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3685 MESSAGE("PublishCaseInStudy pour "<<theName);
3686 SALOMEDS::SObject_var aResultSO;
3688 if (CORBA::is_nil(theObject)) {
3689 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3690 return aResultSO._retn();
3692 if (theStudy->_is_nil()) {
3693 MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
3694 return aResultSO._retn();
3697 // On recupere le module pere dans l etude
3698 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3699 if (theFatherHomard->_is_nil())
3701 MESSAGE("theFatherHomard->_is_nil()");
3702 return aResultSO._retn();
3706 MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3707 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3708 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3709 _orb->object_to_string(theObject) ) ;
3711 return aResultSO._retn();
3713 //=============================================================================
3714 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3715 SALOMEDS::StudyBuilder_var aStudyBuilder,
3716 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3718 MESSAGE("PublishHypotheseInStudy pour "<<theName);
3719 SALOMEDS::SObject_var aResultSO;
3721 // On recupere le module pere dans l etude
3722 // On ajoute la categorie des hypotheses dans l etude si necessaire
3723 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3724 if (theFatherHomard->_is_nil())
3726 MESSAGE("theFatherHomard->_is_nil()");
3727 return aResultSO._retn();
3730 // On ajoute la categorie des hypotheses dans l etude si necessaire
3731 SALOMEDS::SObject_var aSObject;
3732 if ( _tag_hypo == 0 )
3735 _tag_hypo = _tag_gene ;
3737 MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3738 if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3740 MESSAGE("Ajout de la categorie des hypotheses");
3741 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3742 PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3744 else { MESSAGE("La categorie des hypotheses existe deja."); }
3746 // Creation du resultat dans l'etude
3747 aResultSO = aStudyBuilder->NewObject(aSObject);
3748 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3750 return aResultSO._retn();
3752 //=============================================================================
3753 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::Study_ptr theStudy,
3754 SALOMEDS::StudyBuilder_var aStudyBuilder,
3755 HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3757 MESSAGE("PublishYACSInStudy pour "<<theName);
3758 SALOMEDS::SObject_var aResultSO;
3760 // On recupere le module pere dans l etude
3761 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3762 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3763 if (theFatherHomard->_is_nil())
3765 MESSAGE("theFatherHomard->_is_nil()");
3766 return aResultSO._retn();
3768 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3769 if ( _tag_yacs == 0 )
3772 _tag_yacs = _tag_gene ;
3774 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3775 SALOMEDS::SObject_var aSObject;
3776 if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3778 MESSAGE("Ajout de la categorie des schemas YACS");
3779 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3780 PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3782 else { MESSAGE("La categorie des schemas YACS existe deja."); }
3784 // Creation du resultat dans l'etude
3785 aResultSO = aStudyBuilder->NewObject(aSObject);
3786 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3788 return aResultSO._retn();
3791 //=============================================================================
3792 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
3793 SALOMEDS::StudyBuilder_var aStudyBuilder,
3794 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3796 MESSAGE("PublishZoneStudy pour "<<theName);
3797 SALOMEDS::SObject_var aResultSO;
3798 if (CORBA::is_nil(theObject))
3800 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3801 return aResultSO._retn();
3803 if (theStudy->_is_nil())
3805 MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3806 return aResultSO._retn();
3808 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3809 if (theFatherHomard->_is_nil())
3811 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3812 return aResultSO._retn();
3815 // Caracteristique de la zone
3816 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3817 CORBA::Long ZoneType = myZone->GetType();
3819 // On ajoute la categorie des zones dans l etude si necessaire
3820 if ( _tag_zone == 0 )
3823 _tag_zone = _tag_gene ;
3825 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3826 SALOMEDS::SObject_var aSObject;
3827 if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3829 MESSAGE("Ajout de la categorie des zones");
3830 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3831 PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3833 else { MESSAGE("La categorie des zones existe deja."); }
3835 aResultSO = aStudyBuilder->NewObject(aSObject);
3844 { icone = "boxdxy_2.png" ;
3848 { icone = "boxdxyz_2.png" ;
3856 { icone = "disk_2.png" ;
3860 { icone = "spherepoint_2.png" ;
3864 { icone = "cylinderpointvector_2.png" ;
3872 { icone = "diskwithhole_2.png" ;
3876 { icone = "pipe_2.png" ;
3880 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3882 return aResultSO._retn();
3884 //===========================================================================
3885 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3886 SALOMEDS::SObject_var aResultSO,
3887 const char* name, const char* comment, const char* icone, const char* ior)
3889 MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3890 // MESSAGE("icone = "<<icone);
3891 // MESSAGE("ior = "<<ior);
3892 SALOMEDS::GenericAttribute_var anAttr ;
3896 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3897 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3898 aNameAttrib->SetValue(name);
3901 // Ajout du commentaire
3902 if ( comment != NULL )
3904 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3905 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3906 aCommentAttrib->SetValue(comment);
3910 if ( icone != NULL )
3912 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3913 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3914 aPixmap->SetPixMap(icone);
3920 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3921 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3922 anIOR->SetValue(ior);
3926 //=====================================================================================
3927 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3929 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3931 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3932 ASSERT(!CORBA::is_nil(myCase));
3933 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3934 ASSERT(!CORBA::is_nil(aCaseSO));
3936 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3937 ASSERT(!CORBA::is_nil(myBoundary));
3938 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3939 ASSERT(!CORBA::is_nil(aBoundarySO));
3941 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3943 aStudyBuilder->NewCommand();
3945 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3946 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3947 // aStudyBuilder->RemoveReference(aSubSO);
3949 aStudyBuilder->CommitCommand();
3952 //=====================================================================================
3953 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3955 MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3957 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3958 ASSERT(!CORBA::is_nil(myYACS));
3959 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3960 ASSERT(!CORBA::is_nil(aYACSSO));
3962 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3963 ASSERT(!CORBA::is_nil(myCase));
3964 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3965 ASSERT(!CORBA::is_nil(aCaseSO));
3967 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3969 aStudyBuilder->NewCommand();
3971 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3972 aStudyBuilder->Addreference(aSubSO, aCaseSO);
3974 aStudyBuilder->CommitCommand();
3977 //=============================================================================
3978 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3979 // Option = 0 : fichier issu d'une importation
3980 // Option = 1 : fichier issu d'une execution HOMARD
3982 MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3983 if (CORBA::is_nil(myCurrentStudy))
3985 SALOME::ExceptionStruct es;
3986 es.type = SALOME::BAD_PARAM;
3987 es.text = "Invalid study context";
3988 throw SALOME::SALOME_Exception(es);
3992 // Le module SMESH est-il actif ?
3993 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3995 if (!CORBA::is_nil(aSmeshSO))
3997 // On verifie que le fichier n est pas deja publie
3998 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3999 for (; aIter->More(); aIter->Next())
4001 SALOMEDS::SObject_var aSO = aIter->Value();
4002 SALOMEDS::GenericAttribute_var aGAttr;
4003 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
4005 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
4006 CORBA::String_var value=anAttr->Value();
4007 if (strcmp((const char*)value,NomFich) == 0)
4009 MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
4010 // Pour un fichier importe, on ne republie pas
4011 if ( Option == 0 ) { return; }
4012 // Pour un fichier calcule, on commence par faire la depublication
4015 MESSAGE ( "PublishResultInSmesh : depublication" );
4016 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
4017 CORBA::String_var value2=anAttr2->Value();
4018 std::string MeshName = string(value2) ;
4019 MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
4020 DeleteResultInSmesh(NomFich, MeshName) ;
4027 // On enregistre le fichier
4028 MESSAGE( "Enregistrement du fichier");
4029 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
4030 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
4031 ASSERT(!CORBA::is_nil(aSmeshEngine));
4032 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
4033 SMESH::DriverMED_ReadStatus theStatus;
4034 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
4036 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
4037 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
4038 for (int i = 0; i < mesMaillages->length(); i++)
4040 MESSAGE( ". Mise a jour des attributs du maillage");
4041 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
4042 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
4043 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
4044 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
4045 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
4046 anAttr->SetValue(NomFich);
4047 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
4048 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
4050 if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
4051 else { icone = "mesh_tree_mesh.png" ; }
4052 anAttr2->SetPixMap( icone );
4056 //=============================================================================
4057 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
4059 MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
4060 if (CORBA::is_nil(myCurrentStudy))
4062 SALOME::ExceptionStruct es;
4063 es.type = SALOME::BAD_PARAM;
4064 es.text = "Invalid study context";
4065 throw SALOME::SALOME_Exception(es);
4069 // Le module SMESH est-il actif ?
4070 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
4072 if (CORBA::is_nil(aSmeshSO))
4076 // On verifie que le fichier est deja publie
4077 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
4078 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
4079 for (; aIter->More(); aIter->Next())
4081 SALOMEDS::SObject_var aSO = aIter->Value();
4082 SALOMEDS::GenericAttribute_var aGAttr;
4083 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
4085 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
4086 CORBA::String_var value=anAttr->Value();
4087 if (strcmp((const char*)value,NomFich.c_str()) == 0)
4089 if (aSO->FindAttribute(aGAttr,"AttributeName"))
4091 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
4092 CORBA::String_var value2=anAttr2->Value();
4093 if (strcmp((const char*)value2,MeshName.c_str()) == 0)
4095 myBuilder->RemoveObjectWithChildren( aSO ) ;
4103 //=============================================================================
4104 void HOMARD_Gen_i::PublishMeshIterInSmesh(const char* NomIter)
4106 MESSAGE( "PublishMeshIterInSmesh " << NomIter);
4107 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
4109 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->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);
4118 const char* MeshFile = myIteration->GetMeshFile() ;
4119 const char* MeshName = myIteration->GetMeshName() ;
4120 CORBA::Long Option = -1 ;
4121 int etat = myIteration->GetState();
4122 // Iteration initiale
4123 if ( etat <= 0 ) { Option = 0 ; }
4124 // ou iteration calculee
4125 else if ( etat == 2 ) { Option = 1 ; }
4126 // Publication effective apres menage eventuel
4129 DeleteResultInSmesh(MeshFile, MeshName) ;
4130 PublishResultInSmesh(MeshFile, Option) ;
4134 //=============================================================================
4135 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
4137 // MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
4138 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
4140 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
4141 if (CORBA::is_nil(myIteration))
4143 SALOME::ExceptionStruct es;
4144 es.type = SALOME::BAD_PARAM;
4145 es.text = "Invalid iterationStudy Object";
4146 throw SALOME::SALOME_Exception(es);
4150 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
4152 aStudyBuilder->NewCommand();
4154 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
4155 // Pour les fichiers med, on affiche une icone de maillage
4156 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
4157 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
4159 std::string ior = " " ;
4160 if ( Commentaire[0] == 'M' )
4161 { icone = "med.png" ; }
4163 { icone = "texte_2.png" ; }
4164 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
4166 aStudyBuilder->CommitCommand();
4169 //=============================================================================
4170 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
4172 // MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
4173 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4175 SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
4176 if (CORBA::is_nil(myYACS))
4178 SALOME::ExceptionStruct es;
4179 es.type = SALOME::BAD_PARAM;
4180 es.text = "Invalid YACSStudy Object";
4181 throw SALOME::SALOME_Exception(es);
4185 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
4187 aStudyBuilder->NewCommand();
4189 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
4190 std::string icone = "texte_2.png" ;
4191 std::string ior = " " ;
4192 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
4194 aStudyBuilder->CommitCommand();
4197 //=============================================================================
4198 //=============================================================================
4200 //=============================================================================
4201 //=============================================================================
4202 //=============================================================================
4203 // Creation d'un schema YACS
4204 // nomCas : nom du cas a traiter
4205 // FileName : nom du fichier contenant le script de lancement du calcul
4206 // DirName : le répertoire de lancement des calculs du schéma
4207 //=============================================================================
4208 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
4210 INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
4211 INFOS ( ". nomCas : " << nomCas);
4212 INFOS ( ". ScriptFile : " << ScriptFile);
4213 INFOS ( ". DirName : " << DirName);
4214 INFOS ( ". MeshFile : " << MeshFile);
4216 // A. Controle du nom :
4217 if ((myContextMap[GetCurrentStudyID()]._mesYACSs).find(nomYACS) != (myContextMap[GetCurrentStudyID()]._mesYACSs).end())
4219 SALOME::ExceptionStruct es;
4220 es.type = SALOME::BAD_PARAM;
4221 es.text = "This schema YACS has already been defined.";
4222 throw SALOME::SALOME_Exception(es);
4226 // B. Creation de l'objet
4227 HOMARD::HOMARD_YACS_var myYACS = newYACS();
4228 if (CORBA::is_nil(myYACS))
4230 SALOME::ExceptionStruct es;
4231 es.type = SALOME::BAD_PARAM;
4232 es.text = "Unable to create the schema YACS";
4233 throw SALOME::SALOME_Exception(es);
4236 myYACS->SetName( nomYACS ) ;
4238 // C. Enregistrement
4239 myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS] = myYACS;
4241 SALOMEDS::SObject_var aSO;
4242 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myYACS, nomYACS);
4244 PublishCaseUnderYACS(nomYACS, nomCas);
4246 // D. Caracterisation
4248 myYACS->SetDirName( DirName ) ;
4249 myYACS->SetMeshFile( MeshFile ) ;
4250 myYACS->SetScriptFile( ScriptFile ) ;
4251 myYACS->SetCaseName( nomCas ) ;
4254 // D.2.1. Type constant
4255 myYACS->SetType( 1 ) ;
4256 // D.2.2. Convergence
4257 defaut_i = GetYACSMaxIter() ;
4258 myYACS->SetMaxIter( defaut_i ) ;
4259 defaut_i = GetYACSMaxNode() ;
4260 myYACS->SetMaxNode( defaut_i ) ;
4261 defaut_i = GetYACSMaxElem() ;
4262 myYACS->SetMaxElem( defaut_i ) ;
4263 // D.3. Fichier de sauvegarde dans le répertoire du cas
4264 HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
4265 std::string dirnamecase = caseyacs->GetDirName() ;
4266 std::string XMLFile ;
4267 XMLFile = dirnamecase + "/schema.xml" ;
4268 myYACS->SetXMLFile( XMLFile.c_str() ) ;
4270 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
4272 //=============================================================================
4273 // Ecriture d'un schema YACS
4274 //=============================================================================
4275 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
4277 INFOS ( "YACSWrite : Ecriture de " << nomYACS );
4278 // Le répertoire du cas
4279 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4280 ASSERT(!CORBA::is_nil(myYACS));
4281 // Le nom du fichier du schema
4282 std::string XMLFile ;
4283 XMLFile = myYACS->GetXMLFile() ;
4285 int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
4289 //=============================================================================
4290 // Ecriture d'un schema YACS sur un fichier donne
4291 //=============================================================================
4292 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
4294 INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
4301 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4302 ASSERT(!CORBA::is_nil(myYACS));
4303 // B.2. Les caracteristiques
4304 std::string DirName = myYACS->GetDirName() ;
4305 std::string MeshFile = myYACS->GetMeshFile() ;
4306 std::string ScriptFile = myYACS->GetScriptFile() ;
4307 // B.3. Les caracteristiques de convergence
4308 int MaxIter = myYACS->GetMaxIter() ;
4309 int MaxNode = myYACS->GetMaxNode() ;
4310 int MaxElem = myYACS->GetMaxElem() ;
4314 const char* nomCas = myYACS->GetCaseName();
4315 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
4316 ASSERT(!CORBA::is_nil(myCase));
4317 // C.2. Les instructions python associees au cas
4318 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4319 std::string pythonCas = dumpCorbaCase.in();
4320 MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
4322 // D. Les iterations
4323 // D.1. L'iteration initiale
4324 HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
4325 std::string Iter0Name = myCase->GetIter0Name() ;
4326 MESSAGE (". Iter0Name = " << Iter0Name);
4327 std::string MeshName = Iter0->GetMeshName();
4328 MESSAGE (". MeshName = " << MeshName);
4329 // D.2. L'iteration numero 1
4330 HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
4331 int numberOfIter = maListe->length();
4332 if ( numberOfIter > 1 )
4334 MESSAGE (". numberOfIter = " << numberOfIter);
4335 SALOME::ExceptionStruct es ;
4336 es.type = SALOME::BAD_PARAM;
4337 std::string text = "Une seule iteration est permise." ;
4338 es.text = CORBA::string_dup(text.c_str());
4339 throw SALOME::SALOME_Exception(es);
4342 std::string Iter1Name = std::string((*maListe)[0]);
4343 MESSAGE ("... Iter1Name = " << Iter1Name);
4344 HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
4345 // D.3. Les instructions python associees a l'iteration
4346 CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
4347 std::string pythonIter = dumpCorbaIter.in();
4348 MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
4350 // E. L'hypothese pour passer de l'iteration initiale a la suivante
4351 // E.1. La structure
4352 std::string nomHypo = Iter1->GetHypoName();
4353 MESSAGE (". nomHypo = " << nomHypo);
4354 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
4355 ASSERT(!CORBA::is_nil(myHypo));
4356 // E.2. Les caracteristiques de l'adaptation
4357 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
4358 ASSERT(ListTypes->length() == 3);
4359 int TypeAdap = (*ListTypes)[0];
4360 // int TypeRaff = (*ListTypes)[1];
4361 // int TypeDera = (*ListTypes)[2];
4362 // E.3. Les instructions python associees a l'hypothese
4363 CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
4364 std::string pythonHypo = dumpCorbaHypo.in();
4365 MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
4367 // F. Le fichier du schema de reference
4368 // HOMARD_ROOT_DIR : répertoire ou se trouve le module HOMARD
4369 std::string XMLFile_base ;
4370 if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
4373 SALOME::ExceptionStruct es ;
4374 es.type = SALOME::BAD_PARAM;
4375 std::string text = "HOMARD_ROOT_DIR est inconnu." ;
4376 es.text = CORBA::string_dup(text.c_str());
4377 throw SALOME::SALOME_Exception(es);
4380 XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
4382 MESSAGE("XMLFile_base ="<<XMLFile_base);
4384 // G. Lecture du schema de reference et insertion des données propres au fil de la rencontre des mots-cles
4385 YACSDriver* myDriver = new YACSDriver(XMLFile, DirName);
4386 std::ifstream fichier( XMLFile_base.c_str() );
4387 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
4389 // G.1. Lecture du schema de reference et insertion des données propres au fil de la rencontre des mots-cles
4390 std::string ligne; // variable contenant chaque ligne lue
4391 std::string mot_cle;
4392 while ( std::getline( fichier, ligne ) )
4394 // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
4395 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
4396 ligne_bis >> mot_cle ;
4397 // G.1.2. Le maillage initial
4398 if ( mot_cle == "DataInit_MeshFile" )
4399 { myDriver->Texte_DataInit_MeshFile(MeshFile); }
4400 // G.1.3. Le script de lancement
4401 else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
4402 { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
4403 // G.1.4. Les options du cas
4404 else if ( mot_cle == "Iter_1_Case_Options" )
4405 { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
4406 // G.1.5. Execution de HOMARD : le répertoire du cas
4407 else if ( mot_cle == "HOMARD_Exec_DirName" )
4408 { myDriver->Texte_HOMARD_Exec_DirName(); }
4409 // G.1.6. Execution de HOMARD : le nom du maillage
4410 else if ( mot_cle == "HOMARD_Exec_MeshName" )
4412 myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
4413 std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
4414 myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
4416 // G.1.7. Execution de HOMARD : les options de l'hypothese
4417 else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
4418 { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ; }
4419 // G.1.8. Execution de HOMARD : les options de l'iteration
4420 else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
4421 { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ; }
4422 // G.1.9. a. Creation eventuelles des zones et frontieres
4424 else if ( mot_cle == "Iter_1" )
4426 std::string texte_control = "" ;
4427 if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
4428 texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
4429 texte_control += myDriver->Texte_Iter_1_control() ;
4430 myDriver->TexteAdd(texte_control);
4432 // G.1.10. Les tests de convergence
4433 else if ( mot_cle == "Analyse_Test_Convergence" )
4434 { myDriver->TexteAnalyse_Test_Convergence(MaxIter, MaxNode, MaxElem); }
4435 // G.1.11. Les parametres
4436 else if ( mot_cle == "PARAMETRES" )
4437 { myDriver->TexteAddParametres(); }
4438 // G.1.n. La ligne est recopiee telle quelle
4439 else { myDriver->TexteAdd(ligne); }
4441 // G.2. Ecriture du texte dans le fichier
4443 { myDriver->CreeFichier(); }
4447 SALOME::ExceptionStruct es;
4448 es.type = SALOME::BAD_PARAM;
4449 std::string text = "The reference file for the YACS schema cannot be read." ;
4450 es.text = CORBA::string_dup(text.c_str());
4451 throw SALOME::SALOME_Exception(es);
4456 // H. Publication du fichier dans l'arbre
4458 std::string Commentaire = "xml" ;
4459 PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
4463 //=============================================================================
4464 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
4465 //=============================================================================
4466 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
4468 MESSAGE ( "YACSDriverTexteZone" );
4469 // A. Les zones associees a cette hypothese
4470 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
4471 int numberOfZonesx2 = ListZone->length();
4473 // B. Parcours des zones
4474 std::string texte_control ;
4475 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
4477 // 1. Reperage de la zone
4478 std::string ZoneName = std::string((*ListZone)[iaux]);
4479 MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
4480 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
4481 ASSERT(!CORBA::is_nil(myZone));
4482 // 2. Les instructions python associees a la zone
4483 // La premiere ligne est un commentaire a eliminer
4484 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4485 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4486 std::string pythonStructure_0 = dumpCorbaZone.in();
4487 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4488 std::istringstream tout (pythonStructure_0) ;
4490 std::string pythonStructure ;
4491 while ( std::getline( tout, ligne ) )
4492 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4493 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4494 // 3. Decodage du nom du service
4495 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4496 MESSAGE ( "... methode = " << methode);
4497 // 4. Mise en place des instructions
4498 int ZoneType = myZone->GetType();
4499 MESSAGE ( "... ZoneType = " << ZoneType);
4500 std::string texte_control_0 ;
4501 texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
4502 texte_control += texte_control_0 ;
4507 return texte_control ;
4509 //=============================================================================
4510 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4511 //=============================================================================
4512 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4514 MESSAGE ( "YACSDriverTexteBoundary" );
4515 // A. Les frontieres associees au cas
4516 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4517 int numberOfitems = ListBoundaryGroupType->length();
4519 // B. Parcours des frontieres
4520 std::string texte_control ;
4521 std::list<std::string> ListeBoundaryTraitees ;
4522 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4524 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4525 MESSAGE ( "... BoundaryName = " << BoundaryName);
4526 // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4527 // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4529 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4530 while (it != ListeBoundaryTraitees.end())
4532 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4533 if ( BoundaryName == *it ) { A_faire = 0 ; }
4538 // 1. Caracteristiques de la frontiere
4539 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
4540 ASSERT(!CORBA::is_nil(myBoundary));
4541 // 2. Les instructions python associees a la frontiere
4542 // La premiere ligne est un commentaire a eliminer
4543 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4544 CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4545 std::string pythonStructure_0 = dumpCorbaBoundary.in();
4546 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4547 std::istringstream tout (pythonStructure_0) ;
4549 std::string pythonStructure ;
4550 while ( std::getline( tout, ligne ) )
4551 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4552 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4553 // 3. Decodage du nom du service
4554 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4555 MESSAGE ( "... methode = " << methode);
4556 // 4. Mise en place des instructions
4557 int BoundaryType = myBoundary->GetType();
4558 MESSAGE ( "... BoundaryType = " << BoundaryType);
4559 const char* MeshName ;
4560 const char* DataFile ;
4561 if (BoundaryType == -1)
4563 DataFile = myBoundary->GetDataFile() ;
4564 MESSAGE ( ". CAOFile = " << DataFile );
4566 else if (BoundaryType == 0)
4568 MeshName = myBoundary->GetMeshName() ;
4569 MESSAGE ( ". MeshName = " << MeshName );
4570 DataFile = myBoundary->GetDataFile() ;
4571 MESSAGE ( ". MeshFile = " << DataFile );
4573 std::string texte_control_0 ;
4574 texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName, MeshName, DataFile );
4575 texte_control += texte_control_0 ;
4576 // 5. Memorisation du traitement
4577 ListeBoundaryTraitees.push_back( BoundaryName );
4581 return texte_control ;
4584 //=============================================================================
4585 //=============================================================================
4586 // Next functions are inherited from SALOMEDS::Driver interface
4587 //=============================================================================
4588 //=============================================================================
4589 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4591 CORBA::Boolean isMultiFile)
4593 MESSAGE ("Save for theURL = "<< theURL);
4594 SALOMEDS::TMPFile_var aStreamFile;
4596 // get temporary directory name
4597 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4599 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4600 StudyContext& context = myContextMap[ aStudy->StudyId() ];
4602 // HOMARD data file name
4603 std::string aFileName = "";
4605 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4606 aFileName += "_HOMARD.dat";
4608 // initialize sequence of file names
4609 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
4610 aFileSeq->length(1);
4611 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
4613 // get full path to the data file
4614 aFileName = tmpDir + aFileName;
4618 std::ofstream f(aFileName.c_str());
4620 // clear temporary id map
4621 context._idmap.clear();
4626 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4627 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4628 HOMARD::HOMARD_Cas_var aCas = it_case->second;
4629 PortableServer::ServantBase_var aServant = GetServant(aCas);
4630 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4632 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4633 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4637 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4638 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4639 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4640 PortableServer::ServantBase_var aServant = GetServant(aZone);
4641 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4643 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4644 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4647 // -> save hypotheses
4648 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4649 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4650 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4651 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4652 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4654 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4655 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4658 // -> save iterations
4659 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4660 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4661 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4662 PortableServer::ServantBase_var aServant = GetServant(aIter);
4663 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4665 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4666 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4669 // -> save boundaries
4670 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4671 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4672 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4673 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4674 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4675 if (aBoundaryServant) {
4676 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4677 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4681 MESSAGE ("close file");
4684 // put temporary files to the stream
4685 MESSAGE ("put temporary files to the stream");
4686 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
4688 // remove temporary files
4689 MESSAGE ("remove temporary files");
4690 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4692 // return data stream
4693 MESSAGE ("return data stream");
4694 return aStreamFile._retn();
4697 //===========================================================================
4698 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4700 CORBA::Boolean isMultiFile)
4702 // No specific ASCII persistence
4703 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4704 return aStreamFile._retn();
4707 //===========================================================================
4708 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4709 const SALOMEDS::TMPFile& theStream,
4711 CORBA::Boolean isMultiFile)
4713 MESSAGE ("Load pour theURL = "<< theURL);
4714 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4716 // set current study
4717 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
4718 SetCurrentStudy(aStudy);
4720 // get temporary directory name
4721 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4723 // Convert the stream into sequence of files to process
4724 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4727 // HOMARD data file name
4728 std::string aFileName = "";
4730 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4731 aFileName = tmpDir + aFileName + "_HOMARD.dat";
4733 StudyContext& context = myContextMap[ aStudy->StudyId() ];
4737 std::ifstream f(aFileName.c_str());
4740 context._mesCas.clear();
4741 context._mesHypotheses.clear();
4742 context._mesIterations.clear();
4743 context._mesZones.clear();
4744 context._mesBoundarys.clear();
4745 context._idmap.clear();
4751 std::getline(f, line);
4752 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4753 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4754 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4755 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4756 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4757 std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4758 if (line.substr(0, bounSignature.size()) == bounSignature) {
4759 // re-create boundary
4760 MESSAGE ("Recreation de la frontiere" );
4761 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4762 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4763 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4764 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4765 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4766 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4769 else if (line.substr(0, caseSignature.size()) == caseSignature) {
4771 MESSAGE ("Recreation du cas" );
4772 HOMARD::HOMARD_Cas_var aCase = newCase();
4773 PortableServer::ServantBase_var aServant = GetServant(aCase);
4774 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4775 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4776 context._mesCas[aCase->GetName()] = aCase;
4777 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4780 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4781 // re-create hypothesis
4782 MESSAGE ("Recreation de l hypothese" );
4783 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4784 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4785 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4786 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4787 context._mesHypotheses[aHypo->GetName()] = aHypo;
4788 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4791 else if (line.substr(0, iterSignature.size()) == iterSignature) {
4792 // re-create iteration
4793 MESSAGE ("Recreation de l'iteration" );
4794 HOMARD::HOMARD_Iteration_var aIter = newIteration();
4795 PortableServer::ServantBase_var aServant = GetServant(aIter);
4796 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4797 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4798 context._mesIterations[aIter->GetName()] = aIter;
4799 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4802 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4803 MESSAGE ("Recreation de la zone" );
4805 HOMARD::HOMARD_Zone_var aZone = newZone();
4806 PortableServer::ServantBase_var aServant = GetServant(aZone);
4807 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4808 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4809 context._mesZones[aZone->GetName()] = aZone;
4810 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4813 else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4814 MESSAGE ("Recreation du schema YACS" );
4816 HOMARD::HOMARD_YACS_var aYACS = newYACS();
4817 PortableServer::ServantBase_var aServant = GetServant(aYACS);
4818 HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4819 if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4820 context._mesYACSs[aYACS->GetName()] = aYACS;
4821 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4830 // Remove temporary files created from the stream
4832 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4837 //===========================================================================
4838 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4839 const SALOMEDS::TMPFile& theStream,
4841 CORBA::Boolean isMultiFile)
4843 // No specific ASCII persistence
4844 return Load(theComponent, theStream, theURL, isMultiFile);
4847 //===========================================================================
4848 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4850 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
4851 // clearing study context should be done here:
4852 // - destroy all servants and related CORBA objects
4854 // - remove context from myContextMap
4855 myContextMap.erase(theComponent->GetStudy()->StudyId());
4856 // - nullify myCurrentStudy
4857 myCurrentStudy = SALOMEDS::Study::_nil();
4861 //===========================================================================
4862 char* HOMARD_Gen_i::ComponentDataType()
4864 return CORBA::string_dup("HOMARD");
4867 //===========================================================================
4868 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4869 const char* IORString,
4870 CORBA::Boolean isMultiFile,
4871 CORBA::Boolean isASCII)
4873 CORBA::String_var aString("");
4874 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4875 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4876 CORBA::Object_var anObj = _orb->string_to_object(IORString);
4877 if (!CORBA::is_nil(anObj)) {
4878 PortableServer::ServantBase_var aServant = GetServant(anObj);
4879 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4881 std::map<int, PortableServer::ServantBase*>::const_iterator it;
4882 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4883 if (it->second == aStorable) {
4884 std::stringstream os;
4886 aString = CORBA::string_dup(os.str().c_str());
4892 return aString._retn();
4895 //===========================================================================
4896 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4897 const char* aLocalPersistentID,
4898 CORBA::Boolean isMultiFile,
4899 CORBA::Boolean isASCII)
4901 CORBA::String_var aString("");
4902 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4903 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4904 int id = atoi(aLocalPersistentID);
4905 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4906 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4907 if (!CORBA::is_nil(object)) {
4908 aString = _orb->object_to_string(object);
4912 return aString._retn();
4915 //===========================================================================
4916 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4918 if(CORBA::is_nil(myCurrentStudy))
4921 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4922 if(!aCas->_is_nil())
4925 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4926 if(!aHypo->_is_nil())
4929 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4930 if(!aZone->_is_nil())
4933 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4934 if(!aBoundary->_is_nil())
4937 /* Iteration is not published directly
4938 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4939 if(!aIter->_is_nil())
4945 //===========================================================================
4946 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4948 // No Copy/Paste support
4952 //===========================================================================
4953 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4954 CORBA::Long& theObjectID)
4956 // No Copy/Paste support
4957 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4958 return aStreamFile._retn();
4961 //===========================================================================
4962 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
4963 CORBA::Long theObjectID)
4965 // No Copy/Paste support
4969 //===========================================================================
4970 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4971 CORBA::Long theObjectID,
4972 SALOMEDS::SObject_ptr theSObject)
4974 // No Copy/Paste support
4975 SALOMEDS::SObject_var aResultSO;
4976 return aResultSO._retn();
4979 //===========================================================================
4980 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4982 PortableServer::Servant aServant = 0;
4983 if (!CORBA::is_nil(theObject)) {
4985 aServant = _poa->reference_to_servant(theObject);
4993 //==========================================================================
4994 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4995 CORBA::Boolean isPublished,
4996 CORBA::Boolean isMultiFile,
4997 CORBA::Boolean& isValidScript)
4999 MESSAGE ("Entree dans DumpPython");
5001 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
5002 if(CORBA::is_nil(aStudy))
5003 return new Engines::TMPFile(0);
5005 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
5006 if(CORBA::is_nil(aSO))
5007 return new Engines::TMPFile(0);
5009 std::string aScript = "\"\"\"\n";
5010 aScript += "Python script for HOMARD\n";
5011 aScript += "Copyright 1996, 2011, 2015 EDF\n";
5012 aScript += "\"\"\"\n";
5013 aScript += "__revision__ = \"V1.2\"\n";
5014 aScript += "import HOMARD\n";
5016 aScript += "import salome\n";
5017 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
5019 aScript += "def RebuildData(theStudy):\n";
5020 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
5023 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
5024 MESSAGE (". Au depart \n"<<aScript);
5027 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
5029 MESSAGE (". Ecritures des frontieres");
5030 aScript += "#\n# Creation of the boundaries";
5031 aScript += "\n# ==========================";
5033 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
5034 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
5035 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
5037 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
5038 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
5039 std::string dumpBoundary = dumpCorbaBoundary.in();
5040 MESSAGE (dumpBoundary<<"\n");
5041 aScript += dumpBoundary;
5045 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
5047 MESSAGE (". Ecritures des zones");
5048 aScript += "#\n# Creation of the zones";
5049 aScript += "\n# =====================";
5051 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
5052 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
5053 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
5055 HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
5056 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
5057 std::string dumpZone = dumpCorbaZone.in();
5058 MESSAGE (dumpZone<<"\n");
5059 aScript += dumpZone;
5063 if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
5065 MESSAGE (". Ecritures des hypotheses");
5066 aScript += "#\n# Creation of the hypotheses";
5067 aScript += "\n# ==========================";
5069 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
5070 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
5071 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
5073 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
5074 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
5075 std::string dumpHypo = dumpCorbaHypo.in();
5076 MESSAGE (dumpHypo<<"\n");
5077 aScript += dumpHypo;
5081 if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
5083 MESSAGE (". Ecritures des cas");
5084 aScript += "#\n# Creation of the cases";
5085 aScript += "\n# =====================";
5087 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
5088 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
5089 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
5091 std::string nomCas = (*it_cas).first;
5092 std::string dumpCas = std::string("\n# Creation of the case ") ;
5093 dumpCas += nomCas + std::string("\n");
5094 dumpCas += std::string("\t") + nomCas;
5095 dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
5097 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
5098 CORBA::String_var cIter0= myCase->GetIter0Name();
5099 std::string iter0 = cIter0.in();
5101 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
5102 CORBA::String_var cMesh0= myIteration->GetMeshFile();
5103 std::string mesh0 = cMesh0.in();
5104 CORBA::String_var cMeshName0= myIteration->GetMeshName();
5105 std::string meshName0 = cMeshName0.in();
5106 dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
5107 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
5108 std::string dumpCas2= dumpCorbaCase.in();
5110 MESSAGE (dumpCas<<dumpCas2<<"\n");
5111 aScript += dumpCas + dumpCas2;
5115 if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
5117 MESSAGE (". Ecritures des iterations");
5118 aScript += "#\n# Creation of the iterations" ;
5119 aScript += "\n# ==========================";
5121 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
5122 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
5123 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
5125 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
5126 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
5127 std::string dumpIter = dumpCorbaIter.in();
5128 MESSAGE (dumpIter<<"\n");
5129 aScript += dumpIter;
5133 if (myContextMap[GetCurrentStudyID()]._mesYACSs.size() > 0)
5135 MESSAGE (". Ecritures des schemas YACS");
5136 aScript += "#\n# Creation of the schemas YACS";
5137 aScript += "\n# ============================";
5139 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
5140 for ( it_yacs = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
5141 it_yacs != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); ++it_yacs)
5143 HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
5144 CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
5145 std::string dumpYACS = dumpCorbaYACS.in();
5146 MESSAGE (dumpYACS<<"\n");
5147 aScript += dumpYACS;
5150 MESSAGE (". Ecritures finales");
5152 aScript += "\n\tpass";
5155 if( !isMultiFile ) // remove unnecessary tabulation
5156 aScript = RemoveTabulation( aScript );
5158 // MESSAGE ("A ecrire \n"<<aScript);
5159 const size_t aLen = strlen(aScript.c_str());
5160 char* aBuffer = new char[aLen+1];
5161 strcpy(aBuffer, aScript.c_str());
5163 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
5164 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
5166 MESSAGE ("Sortie de DumpPython");
5167 return aStreamFile._retn();
5171 //=============================================================================
5172 //=============================================================================
5174 //=============================================================================
5175 //=============================================================================
5176 void HOMARD_Gen_i::IsValidStudy( )
5178 // MESSAGE( "IsValidStudy" );
5179 if (CORBA::is_nil(myCurrentStudy))
5181 SALOME::ExceptionStruct es;
5182 es.type = SALOME::BAD_PARAM;
5183 es.text = "Invalid study context";
5184 throw SALOME::SALOME_Exception(es);
5189 //=============================================================================
5190 char* HOMARD_Gen_i::VerifieDir(const char* nomDir)
5192 std::string casename = std::string("") ;
5193 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
5194 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
5195 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
5197 if (std::string(nomDir) == std::string(it->second->GetDirName()))
5199 casename = std::string(it->second->GetName()) ;
5203 return CORBA::string_dup( casename.c_str() );
5205 /*//=============================================================================
5206 void SALOMEException( std::string message )
5208 SALOME::ExceptionStruct es;
5209 es.type = SALOME::BAD_PARAM;
5211 throw SALOME::SALOME_Exception(es);
5214 //=============================================================================
5215 char* HOMARD_Gen_i::getVersion()
5217 #if HOMARD_DEVELOPMENT
5218 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
5220 return CORBA::string_dup(HOMARD_VERSION_STR);
5223 //===============================================================================
5224 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un caractere
5225 // ligne : la ligne a manipuler
5226 // caractere : le caractere a reperer
5227 // option : 0 : la chaine avant la premiere apparition du caractere
5228 // 1 : la chaine apres la premiere apparition du caractere
5229 // 2 : la chaine avant la derniere apparition du caractere
5230 // 3 : la chaine apres la derniere apparition du caractere
5231 // Si le caractere est absent, on retourne la chaine totale
5232 //===============================================================================
5233 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string caractere, int option )
5235 // MESSAGE("GetStringInTexte, recherche de '"<<caractere<<"' dans '"<<ligne<<"'"<<", option = "<<option);
5237 std::string chaine = ligne ;
5239 if ( option < 2 ) { position = ligne.find_first_of( caractere ) ; }
5240 else { position = ligne.find_last_of( caractere ) ; }
5241 // MESSAGE("position = "<<position);
5242 // MESSAGE("a = "<<ligne.substr( 0, position ).c_str());
5243 // MESSAGE("b = "<<ligne.substr( position+1 ).c_str());
5245 if ( position != std::string::npos )
5247 if ( ( option == 0 ) || ( option == 2 ) ) { chaine = ligne.substr( 0, position ) ; }
5248 else { chaine = ligne.substr( position+1 ) ; }
5253 //=============================================================================
5254 //=============================================================================
5255 // Gestion des preferences
5256 //=============================================================================
5257 //=============================================================================
5258 // Decodage du fichier d'arcihvage des preferences
5260 void HOMARD_Gen_i::SetPreferences( )
5262 MESSAGE ( "SetPreferences" );
5264 std::string ligne, mot_cle, salome_version ;
5267 // A. Les valeurs par defaut ; elles doivent etre coherentes
5268 std::string LanguageShort = "en" ;
5269 int PublisMeshIN = 0 ;
5270 int PublisMeshOUT = 0 ;
5271 int YACSMaxIter = 0 ;
5272 int YACSMaxNode = 0 ;
5273 int YACSMaxElem = 0 ;
5274 std::string YACSTypeTestchaine = "None" ;
5276 // B. La version de salome
5277 // Cela se presente sous la forme :
5278 // [SALOME KERNEL] : 7.3.0
5280 File = getenv("KERNEL_ROOT_DIR") ;
5281 File += "/bin/salome/VERSION" ;
5282 MESSAGE ( "File = "<<File ) ;
5283 std::ifstream fichier0( File.c_str() ) ;
5284 if ( fichier0 ) // ce test échoue si le fichier n'est pas ouvert
5286 std::string ligne; // variable contenant chaque ligne lue
5287 while ( std::getline( fichier0, ligne ) )
5289 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5290 ligne_bis >> mot_cle ;
5291 if ( mot_cle == "[SALOME" )
5293 salome_version = GetStringInTexte ( ligne, " ", 3 ) ;
5294 // MESSAGE ( "salome_version = "<<salome_version<<"|||");
5299 else { ok = false ; }
5301 // B. Decodage du fichier de preferences
5304 std::string PrefFile ;
5305 PrefFile = getenv("HOME") ;
5306 PrefFile += "/.config/salome/SalomeApprc." + salome_version ;
5307 MESSAGE ( "PrefFile = "<<PrefFile ) ;
5309 std::ifstream fichier( PrefFile.c_str() );
5310 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
5312 bool section_langue = false ;
5313 bool section_homard = false ;
5314 while ( std::getline( fichier, ligne ) )
5316 std::string chaine ;
5317 // 1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
5318 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5319 ligne_bis >> mot_cle ;
5322 // 2.1. Debut d'une section
5323 // MESSAGE(mot_cle);
5324 if ( mot_cle == "<section" )
5325 { /*MESSAGE ( "Debut de la section : "<< ligne);*/
5326 ligne_bis >> mot_cle ;
5327 chaine = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5328 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5329 if ( chaine == "language" ) { section_langue = true ; }
5330 if ( chaine == "HOMARD" ) { section_homard = true ; }
5331 // MESSAGE ( "section_langue = "<<section_langue<<", section_homard = "<<section_homard);
5333 // 2.2. Fin d'une section
5334 else if ( mot_cle == "</section>" )
5335 { /*MESSAGE ( "Fin de la section : "<< ligne<<", section_langue = "<<section_langue<<", section_homard = "<<section_homard);*/
5336 section_langue = false ;
5337 section_homard = false ; }
5341 else if ( section_langue || section_homard )
5342 { MESSAGE ( "a decoder : "<< ligne);
5343 // La valeur : entre les deux premieres quotes
5344 chaine = GetStringInTexte ( ligne, "\"", 1 ) ;
5345 // MESSAGE("chaine 1 = |"<<chaine<<"|");
5346 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5347 // MESSAGE("chaine = |"<<chaine<<"|");
5348 // Le mot_cle : entre les deux dernieres quotes
5349 std::string chaine2 = GetStringInTexte ( ligne, "\"", 2 ) ;
5350 // MESSAGE("chaine2 1 = |"<<chaine2<<"|");
5351 chaine2 = GetStringInTexte ( chaine2, "\"", 3 ) ;
5352 // MESSAGE("chaine2 = |"<<chaine2<<"|");
5354 if ( section_langue )
5355 { if ( chaine2 == "language" ) { LanguageShort = chaine ; } }
5357 if ( section_homard )
5359 std::istringstream chainebis( chaine ) ;
5360 // 3.2.1. Les publications
5361 if ( chaine2 == "publish_mesh_in" ) { chainebis >> PublisMeshIN ; }
5362 if ( chaine2 == "publish_mesh_out" ) { chainebis >> PublisMeshOUT ; }
5363 // 3.2.2. Les maximum pour YACS
5364 if ( chaine2 == "yacs_max_iter" ) { chainebis >> YACSMaxIter ; }
5365 if ( chaine2 == "yacs_max_node" ) { chainebis >> YACSMaxNode ; }
5366 if ( chaine2 == "yacs_max_elem" ) { chainebis >> YACSMaxElem ; }
5367 if ( chaine2 == "yacs_type_test" ) { YACSTypeTestchaine = chaine ; }
5374 // C. Enregistrements
5375 MESSAGE ("Enregistrement de LanguageShort = " << LanguageShort );
5376 SetLanguageShort( LanguageShort.c_str() ) ;
5378 MESSAGE ("Enregistrement de PublisMeshIN = " << PublisMeshIN<<", PublisMeshOUT = "<< PublisMeshOUT);
5379 SetPublisMesh(PublisMeshIN, PublisMeshOUT) ;
5381 MESSAGE ("Enregistrement de YACSMaxIter = " << YACSMaxIter<<", YACSMaxNode = "<< YACSMaxNode<<", YACSMaxElem = "<< YACSMaxElem);
5382 SetYACSMaximum(YACSMaxIter, YACSMaxNode, YACSMaxElem) ;
5384 MESSAGE ("Enregistrement de TypeTest = " << YACSTypeTestchaine.c_str() );
5386 if ( ( YACSTypeTestchaine == "VTest > VRef" ) || ( YACSTypeTestchaine == "VTest > VRef" ) ) { YACSTypeTest = 1 ; }
5387 else if ( ( YACSTypeTestchaine == "VTest < VRef" ) || ( YACSTypeTestchaine == "VTest < VRef" ) ) { YACSTypeTest = 2 ; }
5388 else { YACSTypeTest = 0 ; }
5389 MESSAGE ("==> TypeTest = " << YACSTypeTest );
5390 SetYACSConvergenceType( YACSTypeTest ) ;
5394 //===============================================================================
5396 //===============================================================================
5397 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
5399 // MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
5400 _LangueShort = LanguageShort ;
5401 if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
5402 else { _Langue = "English" ; }
5405 char* HOMARD_Gen_i::GetLanguageShort()
5407 // MESSAGE ("GetLanguageShort");
5408 return CORBA::string_dup( _LangueShort.c_str() );
5410 //===============================================================================
5411 // Options de publications
5412 //===============================================================================
5413 void HOMARD_Gen_i::SetPublisMesh(CORBA::Long PublisMeshIN, CORBA::Long PublisMeshOUT)
5415 _PublisMeshIN = PublisMeshIN ;
5416 _PublisMeshOUT = PublisMeshOUT ;
5419 CORBA::Long HOMARD_Gen_i::GetPublisMeshIN()
5421 return _PublisMeshIN ;
5423 CORBA::Long HOMARD_Gen_i::GetPublisMeshOUT()
5425 return _PublisMeshOUT ;
5427 //===============================================================================
5428 // YACS - test de convergence
5429 //===============================================================================
5430 void HOMARD_Gen_i::SetYACSMaximum(CORBA::Long YACSMaxIter, CORBA::Long YACSMaxNode, CORBA::Long YACSMaxElem)
5432 _YACSMaxIter = YACSMaxIter ;
5433 _YACSMaxNode = YACSMaxNode ;
5434 _YACSMaxElem = YACSMaxElem ;
5437 CORBA::Long HOMARD_Gen_i::GetYACSMaxIter()
5439 return _YACSMaxIter ;
5441 CORBA::Long HOMARD_Gen_i::GetYACSMaxNode()
5443 return _YACSMaxNode ;
5445 CORBA::Long HOMARD_Gen_i::GetYACSMaxElem()
5447 return _YACSMaxElem ;
5449 void HOMARD_Gen_i::SetYACSConvergenceType(CORBA::Long YACSTypeTest)
5451 _YACSTypeTest = YACSTypeTest ;
5454 CORBA::Long HOMARD_Gen_i::GetYACSConvergenceType()
5456 return _YACSTypeTest ;
5459 //=============================================================================
5463 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
5464 PortableServer::POA_ptr poa,
5465 PortableServer::ObjectId* contId,
5466 const char* instanceName,
5467 const char* interfaceName)
5469 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
5470 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
5471 return myHOMARD_Gen->getId();