1 // Copyright (C) 2011-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "HOMARD_Gen_i.hxx"
21 #include "HOMARD_Cas_i.hxx"
22 #include "HOMARD_Hypothesis_i.hxx"
23 #include "HOMARD_Iteration_i.hxx"
24 #include "HOMARD_Boundary_i.hxx"
25 #include "HOMARD_Zone_i.hxx"
26 #include "HOMARD_YACS_i.hxx"
27 #include "HomardDriver.hxx"
28 #include "HOMARD_DriverTools.hxx"
29 #include "HomardMedCommun.h"
30 #include "YACSDriver.hxx"
33 #include "HOMARD_version.h"
35 #include "utilities.h"
36 #include "Utils_SINGLETON.hxx"
37 #include "Utils_CorbaException.hxx"
38 #include "SALOMEDS_Tool.hxx"
39 #include "SALOME_LifeCycleCORBA.hxx"
40 #include "SALOMEconfig.h"
41 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
42 #include CORBA_CLIENT_HEADER(SMESH_Gen)
65 //=============================================================================
67 //=============================================================================
68 std::string RemoveTabulation( std::string theScript )
70 std::string::size_type aPos = 0;
71 while( aPos < theScript.length() )
73 aPos = theScript.find( "\n\t", aPos );
74 if( aPos == std::string::npos )
76 theScript.replace( aPos, 2, "\n" );
81 //=============================================================================
83 * standard constructor
85 //=============================================================================
86 HOMARD_Gen_i::HOMARD_Gen_i( CORBA::ORB_ptr orb,
87 PortableServer::POA_ptr poa,
88 PortableServer::ObjectId * contId,
89 const char *instanceName,
90 const char *interfaceName) :
91 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
93 MESSAGE("constructor");
95 _id = _poa->activate_object(_thisObj);
97 myHomard = new ::HOMARD_Gen();
98 _NS = SINGLETON_<SALOME_NamingService>::Instance();
99 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
110 //=================================
112 * standard destructor
114 //================================
115 HOMARD_Gen_i::~HOMARD_Gen_i()
118 //=============================================================================
119 //=============================================================================
120 // Utilitaires pour l'étude
121 //=============================================================================
122 //=============================================================================
123 void HOMARD_Gen_i::addInStudy(SALOMEDS::Study_ptr theStudy)
125 ASSERT(!CORBA::is_nil(theStudy));
126 MESSAGE("addInStudy: ajout eventuel du composant HOMARD dans current study ID = " << GetCurrentStudyID()) ;
127 SALOMEDS::StudyBuilder_var myBuilder = theStudy->NewBuilder();
129 // Create SComponent labelled 'homard' if it doesn't already exit
130 SALOMEDS::SComponent_var homardFather = theStudy->FindComponent(ComponentDataType());
131 if (CORBA::is_nil(homardFather))
133 myBuilder->NewCommand();
134 MESSAGE("Add Component HOMARD");
136 bool aLocked = theStudy->GetProperties()->IsLocked();
137 if (aLocked) theStudy->GetProperties()->SetLocked(false);
139 homardFather = myBuilder->NewComponent(ComponentDataType());
140 SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
141 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
142 CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
143 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
144 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
145 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
146 if (!Comp->_is_nil())
148 aName->SetValue(ComponentDataType());
151 anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributePixMap");
152 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
153 aPixmap->SetPixMap("HOMARD_2.png");
154 myBuilder->DefineComponentInstance(homardFather, HOMARD_Gen::_this());
156 if (aLocked) theStudy->GetProperties()->SetLocked(true);
157 myBuilder->CommitCommand();
160 //=============================================================================
161 void HOMARD_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy)
163 MESSAGE("SetCurrentStudy: current study Id = " << GetCurrentStudyID());
164 myCurrentStudy = SALOMEDS::Study::_duplicate(theStudy);
165 this->addInStudy(myCurrentStudy);
167 //=============================================================================
168 SALOMEDS::Study_ptr HOMARD_Gen_i::GetCurrentStudy()
169 //=============================================================================
171 MESSAGE("GetCurrentStudy: study Id = " << GetCurrentStudyID());
172 return SALOMEDS::Study::_duplicate(myCurrentStudy);
174 //=============================================================================
175 CORBA::Long HOMARD_Gen_i::GetCurrentStudyID()
176 //=============================================================================
178 return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId();
180 //=============================================================================
181 //=============================================================================
183 //=============================================================================
184 //=============================================================================
185 // Utilitaires pour l'iteration
186 //=============================================================================
187 //=============================================================================
188 void HOMARD_Gen_i::SetEtatIter(const char* nomIter, const CORBA::Long Etat)
189 //=====================================================================================
191 MESSAGE( "SetEtatIter : affectation de l'etat " << Etat << " a l'iteration " << nomIter );
192 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
193 if (CORBA::is_nil(myIteration))
195 SALOME::ExceptionStruct es;
196 es.type = SALOME::BAD_PARAM;
197 es.text = "Invalid iteration";
198 throw SALOME::SALOME_Exception(es);
202 myIteration->SetState(Etat);
204 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
205 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
209 icone = "iter0.png" ;
210 else if ( Etat == 2 )
211 icone = "iter_calculee.png" ;
213 icone = "iter_non_calculee.png" ;
214 PublishInStudyAttr(aStudyBuilder, aIterSO, NULL , NULL, icone.c_str(), NULL) ;
216 aStudyBuilder->CommitCommand();
219 //=============================================================================
220 //=============================================================================
222 //=============================================================================
223 //=============================================================================
224 // Destruction des structures identifiees par leurs noms
225 //=============================================================================
226 //=============================================================================
227 CORBA::Long HOMARD_Gen_i::DeleteBoundary(const char* BoundaryName)
229 MESSAGE ( "DeleteBoundary : BoundaryName = " << BoundaryName );
230 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
231 if (CORBA::is_nil(myBoundary))
233 SALOME::ExceptionStruct es;
234 es.type = SALOME::BAD_PARAM;
235 es.text = "Invalid boundary";
236 throw SALOME::SALOME_Exception(es);
240 // On verifie que la frontiere n'est plus utilisee
241 HOMARD::listeCases* maListe = GetAllCasesName();
242 int numberOfCases = maListe->length();
243 MESSAGE ( ".. Nombre de cas = " << numberOfCases );
244 std::string CaseName ;
245 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType ;
247 HOMARD::HOMARD_Cas_var myCase ;
248 for (int NumeCas = 0; NumeCas< numberOfCases; NumeCas++)
250 CaseName = std::string((*maListe)[NumeCas]);
251 MESSAGE ( "... Examen du cas = " << CaseName.c_str() );
252 myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
253 ASSERT(!CORBA::is_nil(myCase));
254 ListBoundaryGroupType = myCase->GetBoundaryGroup();
255 numberOfitems = ListBoundaryGroupType->length();
256 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
257 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
259 if ( std::string((*ListBoundaryGroupType)[NumBoundary]) == BoundaryName )
261 SALOME::ExceptionStruct es;
262 es.type = SALOME::BAD_PARAM;
263 es.text = "This boundary is used in a case and cannot be deleted.";
264 throw SALOME::SALOME_Exception(es);
270 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
271 myContextMap[GetCurrentStudyID()]._mesBoundarys.erase(BoundaryName);
272 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(BoundaryName, ComponentDataType());
273 SALOMEDS::SObject_var aSO =listSO[0];
274 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
275 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
279 //=============================================================================
280 CORBA::Long HOMARD_Gen_i::DeleteCase(const char* nomCas, CORBA::Long Option)
282 // Pour detruire un cas
283 MESSAGE ( "DeleteCase : nomCas = " << nomCas << ", avec option = " << Option );
284 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
285 if (CORBA::is_nil(myCase))
287 SALOME::ExceptionStruct es;
288 es.type = SALOME::BAD_PARAM;
289 es.text = "Invalid case context";
290 throw SALOME::SALOME_Exception(es);
293 // On commence par detruire toutes les iterations en partant de l'initiale et y compris elle
294 CORBA::String_var nomIter = myCase->GetIter0Name();
295 CORBA::Long Option1 = 0 ;
296 if ( DeleteIterationOption(nomIter, Option1, Option) != 0 )
301 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
302 myContextMap[GetCurrentStudyID()]._mesCas.erase(nomCas);
303 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomCas, ComponentDataType());
304 SALOMEDS::SObject_var aSO =listSO[0];
305 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
306 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
310 //=============================================================================
311 CORBA::Long HOMARD_Gen_i::DeleteHypo(const char* nomHypo)
313 MESSAGE ( "DeleteHypo : nomHypo = " << nomHypo );
314 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
315 if (CORBA::is_nil(myHypo))
317 SALOME::ExceptionStruct es;
318 es.type = SALOME::BAD_PARAM;
319 es.text = "Invalid hypothesis";
320 throw SALOME::SALOME_Exception(es);
324 // On verifie que l'hypothese n'est plus utilisee
325 HOMARD::listeIters* maListeIter = myHypo->GetIterations();
326 int numberOfIter = maListeIter->length();
327 if ( numberOfIter > 0 )
329 SALOME::ExceptionStruct es;
330 es.type = SALOME::BAD_PARAM;
331 es.text = "This hypothesis is used in an iteration and cannot be deleted.";
332 throw SALOME::SALOME_Exception(es);
336 // suppression du lien avec les zones eventuelles
337 HOMARD::listeZonesHypo* maListe = myHypo->GetZones();
338 int numberOfZones = maListe->length();
339 MESSAGE ( ".. Nombre de zones = " << numberOfZones );
340 for (int NumeZone = 0; NumeZone< numberOfZones; NumeZone++)
342 std::string ZoneName = std::string((*maListe)[NumeZone]);
343 MESSAGE ( ".. suppression du lien avec la zone = " << ZoneName.c_str() );
344 DissociateHypoZone(nomHypo, ZoneName.c_str()) ;
348 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
349 myContextMap[GetCurrentStudyID()]._mesHypotheses.erase(nomHypo);
350 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomHypo, ComponentDataType());
351 SALOMEDS::SObject_var aSO =listSO[0];
352 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
353 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
357 //=============================================================================
358 CORBA::Long HOMARD_Gen_i::DeleteIteration(const char* nomIter, CORBA::Long Option)
360 // Option = 0 : On ne supprime pas le fichier du maillage associe
361 // Option = 1 : On supprime le fichier du maillage associe
362 // Pour detruire une iteration courante
363 MESSAGE ( "DeleteIteration : nomIter = " << nomIter << ", avec option = " << Option );
364 CORBA::Long Option1 = 1 ;
365 return DeleteIterationOption(nomIter, Option1, Option);
367 //=============================================================================
368 CORBA::Long HOMARD_Gen_i::DeleteIterationOption(const char* nomIter, CORBA::Long Option1, CORBA::Long Option2)
370 // Option1 = 0 : On autorise la destruction de l'iteration 0
371 // Option1 = 1 : On interdit la destruction de l'iteration 0
373 // Option2 = 0 : On ne supprime pas le fichier du maillage associe
374 // Option2 = 1 : On supprime le fichier du maillage associe
375 MESSAGE ( "DeleteIterationOption : nomIter = " << nomIter << ", avec options = " << Option1<< ", " << Option2 );
376 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
377 if (CORBA::is_nil(myIteration))
379 SALOME::ExceptionStruct es;
380 es.type = SALOME::BAD_PARAM;
381 es.text = "Invalid iteration";
382 throw SALOME::SALOME_Exception(es);
386 int numero = myIteration->GetNumber();
387 MESSAGE ( "DeleteIterationOption : numero = " << numero );
388 if ( numero == 0 && Option1 == 1 )
390 SALOME::ExceptionStruct es;
391 es.type = SALOME::BAD_PARAM;
392 es.text = "This iteration cannot be deleted.";
393 throw SALOME::SALOME_Exception(es);
397 // On detruit recursivement toutes les filles
398 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
399 int numberOfIter = maListe->length();
400 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
402 std::string nomIterFille = std::string((*maListe)[NumeIter]);
403 MESSAGE ( ".. appel recursif de DeleteIterationOption pour nomIter = " << nomIterFille.c_str() );
404 DeleteIterationOption(nomIterFille.c_str(), Option1, Option2);
407 // On arrive ici pour une iteration sans fille
408 MESSAGE ( "Destruction effective de " << nomIter );
409 // On commence par invalider l'iteration pour faire le menage des dependances
410 // et eventuellement du maillage associe
412 if ( numero == 0 ) { option = 0 ; }
413 else { option = Option2 ; }
414 InvalideIterOption(nomIter, option) ;
416 // Retrait dans la descendance de l'iteration parent
419 std::string nomIterationParent = myIteration->GetIterParentName();
420 MESSAGE ( "Retrait dans la descendance de nomIterationParent " << nomIterationParent );
421 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
422 if (CORBA::is_nil(myIterationParent))
424 SALOME::ExceptionStruct es;
425 es.type = SALOME::BAD_PARAM;
426 es.text = "Invalid iteration";
427 throw SALOME::SALOME_Exception(es);
430 myIterationParent->UnLinkNextIteration(nomIter);
433 // suppression du lien avec l'hypothese
436 std::string nomHypo = myIteration->GetHypoName();
437 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
438 ASSERT(!CORBA::is_nil(myHypo));
439 myHypo->UnLinkIteration(nomIter);
442 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
443 myContextMap[GetCurrentStudyID()]._mesIterations.erase(nomIter);
444 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomIter, ComponentDataType());
445 SALOMEDS::SObject_var aSO =listSO[0];
446 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
447 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
448 // on peut aussi faire RemoveObject
449 // MESSAGE ( "Au final" );
450 // HOMARD::listeIterations* Liste = GetAllIterationsName() ;
451 // numberOfIter = Liste->length();
452 // for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
454 // std::string nomIterFille = std::string((*Liste)[NumeIter]);
455 // MESSAGE ( ".. nomIter = " << nomIterFille.c_str() );
460 //=============================================================================
461 CORBA::Long HOMARD_Gen_i::DeleteYACS(const char* nomYACS, CORBA::Long Option)
463 // Option = 0 : On ne supprime pas le fichier du schema associe
464 // Option = 1 : On supprime le fichier du schema associe
465 MESSAGE ( "DeleteYACS : nomYACS = " << nomYACS << ", avec option = " << Option );
466 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
467 if (CORBA::is_nil(myYACS))
469 SALOME::ExceptionStruct es;
470 es.type = SALOME::BAD_PARAM;
471 es.text = "Invalid schema YACS";
472 throw SALOME::SALOME_Exception(es);
475 // Suppression eventuelle du fichier XML
478 std::string nomFichier = myYACS->GetXMLFile();
479 std::string commande = "rm -rf " + nomFichier ;
480 MESSAGE ( "commande = " << commande );
481 if ((system(commande.c_str())) != 0)
483 SALOME::ExceptionStruct es;
484 es.type = SALOME::BAD_PARAM;
485 es.text = "The xml file for the schema YACS cannot be removed." ;
486 throw SALOME::SALOME_Exception(es);
490 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
491 myContextMap[GetCurrentStudyID()]._mesYACSs.erase(nomYACS);
492 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomYACS, ComponentDataType());
493 SALOMEDS::SObject_var aSO =listSO[0];
494 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
495 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
499 //=============================================================================
500 CORBA::Long HOMARD_Gen_i::DeleteZone(const char* nomZone)
502 MESSAGE ( "DeleteZone : nomZone = " << nomZone );
503 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[nomZone];
504 if (CORBA::is_nil(myZone))
506 SALOME::ExceptionStruct es;
507 es.type = SALOME::BAD_PARAM;
508 es.text = "Invalid zone";
509 throw SALOME::SALOME_Exception(es);
513 // On verifie que la zone n'est plus utilisee
514 HOMARD::listeHypo* maListe = myZone->GetHypo();
515 int numberOfHypo = maListe->length();
516 MESSAGE ( ".. Nombre d'hypotheses = " << numberOfHypo );
517 if ( numberOfHypo > 0 )
519 SALOME::ExceptionStruct es;
520 es.type = SALOME::BAD_PARAM;
521 es.text = "This zone is used in an hypothesis and cannot be deleted.";
522 throw SALOME::SALOME_Exception(es);
526 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
527 myContextMap[GetCurrentStudyID()]._mesZones.erase(nomZone);
528 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomZone, ComponentDataType());
529 SALOMEDS::SObject_var aSO =listSO[0];
530 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
531 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
535 //=============================================================================
536 //=============================================================================
538 //=============================================================================
539 //=============================================================================
540 // Invalidation des structures identifiees par leurs noms
541 //=============================================================================
542 //=============================================================================
543 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
545 MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName );
546 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
547 if (CORBA::is_nil(myBoundary))
549 SALOME::ExceptionStruct es;
550 es.type = SALOME::BAD_PARAM;
551 es.text = "Invalid boundary";
552 throw SALOME::SALOME_Exception(es);
557 SALOME::ExceptionStruct es;
558 es.type = SALOME::BAD_PARAM;
559 es.text = "No change is allowed in a boundary. Ask for evolution.";
560 throw SALOME::SALOME_Exception(es);
564 //=============================================================================
565 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
567 MESSAGE( "InvalideHypo : nomHypo = " << nomHypo );
568 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
569 if (CORBA::is_nil(myHypo))
571 SALOME::ExceptionStruct es;
572 es.type = SALOME::BAD_PARAM;
573 es.text = "Invalid hypothesis";
574 throw SALOME::SALOME_Exception(es);
578 HOMARD::listeIters* maListe = myHypo->GetIterations();
579 int numberOfIter = maListe->length();
580 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
582 std::string nomIter = std::string((*maListe)[NumeIter]);
583 MESSAGE( ".. nomIter = " << nomIter );
584 InvalideIter(nomIter.c_str());
587 //=============================================================================
588 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
590 MESSAGE("InvalideIter : nomIter = " << nomIter);
591 // Pour invalider totalement une iteration courante
592 CORBA::Long Option = 1 ;
593 return InvalideIterOption(nomIter, Option);
595 //=============================================================================
596 void HOMARD_Gen_i::InvalideIterOption(const char* nomIter, CORBA::Long Option)
598 // Option = 0 : On ne supprime pas le fichier du maillage associe
599 // Option = 1 : On supprime le fichier du maillage associe
600 MESSAGE ( "InvalideIterOption : nomIter = " << nomIter << ", avec option = " << Option );
601 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
602 if (CORBA::is_nil(myIteration))
604 SALOME::ExceptionStruct es;
605 es.type = SALOME::BAD_PARAM;
606 es.text = "Invalid iteration";
607 throw SALOME::SALOME_Exception(es);
611 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
612 int numberOfIter = maListe->length();
613 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
615 std::string nomIterFille = std::string((*maListe)[NumeIter]);
616 MESSAGE ( ".. appel recursif de InvalideIter pour nomIter = " << nomIterFille.c_str() );
617 InvalideIter(nomIterFille.c_str());
620 // On arrive ici pour une iteration sans fille
621 MESSAGE ( "Invalidation effective de " << nomIter );
622 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
623 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
624 for (; aIter->More(); aIter->Next())
626 SALOMEDS::SObject_var so = aIter->Value();
627 SALOMEDS::GenericAttribute_var anAttr;
628 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
629 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
630 std::string value (aCommentAttr->Value());
631 if(value == std::string("IterationHomard")) continue;
632 if(value == std::string("HypoHomard")) continue;
633 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
634 aStudyBuilder->RemoveObject(so);
637 int etat = myIteration->GetState();
640 SetEtatIter(nomIter,1);
641 const char * nomCas = myIteration->GetCaseName();
642 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
643 if (CORBA::is_nil(myCase))
645 SALOME::ExceptionStruct es;
646 es.type = SALOME::BAD_PARAM;
647 es.text = "Invalid case context";
648 throw SALOME::SALOME_Exception(es);
651 std::string nomDir = myIteration->GetDirName();
652 std::string nomFichier = myIteration->GetMeshFile();
653 std::string commande = "rm -rf " + std::string(nomDir);
654 if ( Option == 1 ) { commande = commande + ";rm -rf " + std::string(nomFichier) ; }
655 MESSAGE ( "commande = " << commande );
656 if ((system(commande.c_str())) != 0)
658 SALOME::ExceptionStruct es;
659 es.type = SALOME::BAD_PARAM;
660 es.text = "The directory for the calculation cannot be cleared." ;
661 throw SALOME::SALOME_Exception(es);
664 // Suppression du maillage publie dans SMESH
665 std::string MeshName = myIteration->GetMeshName() ;
666 DeleteResultInSmesh(nomFichier, MeshName) ;
670 //=============================================================================
671 void HOMARD_Gen_i::InvalideIterInfo(const char* nomIter)
673 MESSAGE("InvalideIterInfo : nomIter = " << nomIter);
674 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
675 if (CORBA::is_nil(myIteration))
677 SALOME::ExceptionStruct es;
678 es.type = SALOME::BAD_PARAM;
679 es.text = "Invalid iteration";
680 throw SALOME::SALOME_Exception(es);
684 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
685 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
686 for (; aIter->More(); aIter->Next())
688 SALOMEDS::SObject_var so = aIter->Value();
689 SALOMEDS::GenericAttribute_var anAttr;
690 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
691 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
692 std::string value (aCommentAttr->Value());
693 /* MESSAGE("... value = " << value);*/
694 if( (value == std::string("logInfo")) || ( value == std::string("SummaryInfo")) )
696 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
697 aStudyBuilder->RemoveObject(so);
701 const char * nomCas = myIteration->GetCaseName();
702 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
703 if (CORBA::is_nil(myCase))
705 SALOME::ExceptionStruct es;
706 es.type = SALOME::BAD_PARAM;
707 es.text = "Invalid case context";
708 throw SALOME::SALOME_Exception(es);
711 const char* nomDir = myIteration->GetDirName();
712 std::string commande = "rm -f " + std::string(nomDir) + "/info* " ;
713 commande += std::string(nomDir) + "/Liste.*info" ;
714 /* MESSAGE ( "commande = " << commande );*/
715 if ((system(commande.c_str())) != 0)
717 SALOME::ExceptionStruct es;
718 es.type = SALOME::BAD_PARAM;
719 es.text = "The directory for the calculation cannot be cleared." ;
720 throw SALOME::SALOME_Exception(es);
724 //=============================================================================
725 void HOMARD_Gen_i::InvalideYACS(const char* YACSName)
727 MESSAGE( "InvalideYACS : YACSName = " << YACSName );
728 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[YACSName];
729 if (CORBA::is_nil(myYACS))
731 SALOME::ExceptionStruct es;
732 es.type = SALOME::BAD_PARAM;
733 es.text = "Invalid schema YACS";
734 throw SALOME::SALOME_Exception(es);
738 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
739 SALOMEDS::ChildIterator_var aYACS = myCurrentStudy->NewChildIterator(aYACSSO);
740 for (; aYACS->More(); aYACS->Next())
742 SALOMEDS::SObject_var so = aYACS->Value();
743 SALOMEDS::GenericAttribute_var anAttr;
744 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
745 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
746 std::string value (aCommentAttr->Value());
747 if( value == std::string("xml") )
749 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
750 aStudyBuilder->RemoveObject(so);
753 std::string nomFichier = myYACS->GetXMLFile();
754 std::string commande = "rm -rf " + std::string(nomFichier) ;
755 MESSAGE ( "commande = " << commande );
756 if ((system(commande.c_str())) != 0)
758 SALOME::ExceptionStruct es;
759 es.type = SALOME::BAD_PARAM;
760 es.text = "The XML file for the schema YACS cannot be removed." ;
761 throw SALOME::SALOME_Exception(es);
765 //=============================================================================
766 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
768 MESSAGE( "InvalideZone : ZoneName = " << ZoneName );
769 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
770 if (CORBA::is_nil(myZone))
772 SALOME::ExceptionStruct es;
773 es.type = SALOME::BAD_PARAM;
774 es.text = "Invalid zone";
775 throw SALOME::SALOME_Exception(es);
778 HOMARD::listeHypo* maListe = myZone->GetHypo();
779 int numberOfHypo = maListe->length();
780 MESSAGE( ".. numberOfHypo = " << numberOfHypo );
781 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
783 std::string nomHypo = std::string((*maListe)[NumeHypo]);
784 MESSAGE( ".. nomHypo = " << nomHypo );
785 InvalideHypo(nomHypo.c_str());
788 //=============================================================================
789 //=============================================================================
791 //=============================================================================
792 //=============================================================================
793 // Association de lien entre des structures identifiees par leurs noms
794 //=============================================================================
795 //=============================================================================
796 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
798 MESSAGE( "AssociateCaseIter : " << nomCas << ", " << nomIter << ", " << labelIter );
800 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
801 if (CORBA::is_nil(myCase))
803 SALOME::ExceptionStruct es;
804 es.type = SALOME::BAD_PARAM;
805 es.text = "Invalid case";
806 throw SALOME::SALOME_Exception(es);
810 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
811 if (CORBA::is_nil(myIteration))
813 SALOME::ExceptionStruct es;
814 es.type = SALOME::BAD_PARAM;
815 es.text = "Invalid iteration";
816 throw SALOME::SALOME_Exception(es);
820 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
821 SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
822 if (CORBA::is_nil(aCasSO))
824 SALOME::ExceptionStruct es;
825 es.type = SALOME::BAD_PARAM;
826 es.text = "Invalid case";
827 throw SALOME::SALOME_Exception(es);
831 aStudyBuilder->NewCommand();
832 SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
833 PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
834 "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
835 aStudyBuilder->CommitCommand();
837 myCase->AddIteration(nomIter);
838 myIteration->SetCaseName(nomCas);
840 //=====================================================================================
841 void HOMARD_Gen_i::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
843 MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
845 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
846 ASSERT(!CORBA::is_nil(myHypo));
847 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
848 ASSERT(!CORBA::is_nil(aHypoSO));
850 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
851 ASSERT(!CORBA::is_nil(myZone));
852 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
853 ASSERT(!CORBA::is_nil(aZoneSO));
855 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
857 aStudyBuilder->NewCommand();
859 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
860 aStudyBuilder->Addreference(aSubSO, aZoneSO);
862 aStudyBuilder->CommitCommand();
864 myZone->AddHypo(nomHypothesis);
865 myHypo->AddZone0(ZoneName, TypeUse);
867 //=============================================================================
868 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
870 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
872 // Verification de l'existence de l'hypothese
873 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
874 ASSERT(!CORBA::is_nil(myHypo));
875 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
876 ASSERT(!CORBA::is_nil(aHypoSO));
878 // Verification de l'existence de l'iteration
879 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
880 ASSERT(!CORBA::is_nil(myIteration));
881 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
882 ASSERT(!CORBA::is_nil(aIterSO));
884 // Gestion de l'arbre d'etudes
885 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
886 aStudyBuilder->NewCommand();
887 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
888 aStudyBuilder->Addreference(aSubSO, aHypoSO);
889 aStudyBuilder->CommitCommand();
892 myIteration->SetHypoName(nomHypo);
893 myHypo->LinkIteration(nomIter);
895 // On stocke les noms des champ a interpoler pour le futur controle de la donnee des pas de temps
896 myIteration->SupprFieldInterps() ;
897 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
898 int numberOfFieldsx2 = ListField->length();
899 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
901 std::string FieldName = std::string((*ListField)[iaux]) ;
902 myIteration->SetFieldInterp(FieldName.c_str()) ;
906 //=============================================================================
907 //=============================================================================
909 //=============================================================================
910 //=============================================================================
911 // Dissociation de lien entre des structures identifiees par leurs noms
912 //=============================================================================
913 //=============================================================================
914 void HOMARD_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
916 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
918 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
919 ASSERT(!CORBA::is_nil(myHypo));
920 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
921 ASSERT(!CORBA::is_nil(aHypoSO));
923 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
924 ASSERT(!CORBA::is_nil(myZone));
925 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
926 ASSERT(!CORBA::is_nil(aZoneSO));
928 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
930 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator(aHypoSO);
931 for (; it->More(); it->Next())
933 SALOMEDS::SObject_var aHypObj = it->Value();
934 SALOMEDS::SObject_var ptrObj;
935 if (aHypObj->ReferencedObject(ptrObj))
937 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
939 aStudyBuilder->NewCommand();
940 aStudyBuilder->RemoveObject(aHypObj);
941 aStudyBuilder->CommitCommand();
947 myZone->SupprHypo(nomHypothesis);
948 myHypo->SupprZone(ZoneName);
950 //=============================================================================
951 //=============================================================================
954 //=============================================================================
955 //=============================================================================
956 // Recuperation des listes
957 //=============================================================================
958 //=============================================================================
959 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
961 MESSAGE("GetAllBoundarysName");
964 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
965 ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
966 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
968 for (it = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
969 it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
971 ret[i++] = CORBA::string_dup((*it).first.c_str());
976 //=============================================================================
977 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
979 MESSAGE("GetAllCasesName");
982 HOMARD::listeCases_var ret = new HOMARD::listeCases;
983 ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
984 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
986 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
987 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
989 ret[i++] = CORBA::string_dup((*it).first.c_str());
994 //=============================================================================
995 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
997 MESSAGE("GetAllHypothesesName");
1000 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
1001 ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
1002 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
1004 for (it = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
1005 it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
1007 ret[i++] = CORBA::string_dup((*it).first.c_str());
1012 //=============================================================================
1013 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
1015 MESSAGE("GetAllIterationsName");
1018 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
1019 ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
1020 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
1022 for (it = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
1023 it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
1025 ret[i++] = CORBA::string_dup((*it).first.c_str());
1030 //=============================================================================
1031 HOMARD::listeYACSs* HOMARD_Gen_i::GetAllYACSsName()
1033 MESSAGE("GetAllYACSsName");
1036 HOMARD::listeYACSs_var ret = new HOMARD::listeYACSs;
1037 ret->length(myContextMap[GetCurrentStudyID()]._mesYACSs.size());
1038 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it;
1040 for (it = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
1041 it != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); it++)
1043 ret[i++] = CORBA::string_dup((*it).first.c_str());
1048 //=============================================================================
1049 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
1051 MESSAGE("GetAllZonesName");
1054 HOMARD::listeZones_var ret = new HOMARD::listeZones;
1055 ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
1056 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
1058 for (it = myContextMap[GetCurrentStudyID()]._mesZones.begin();
1059 it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
1061 ret[i++] = CORBA::string_dup((*it).first.c_str());
1066 //=============================================================================
1067 //=============================================================================
1069 //=============================================================================
1070 //=============================================================================
1071 // Recuperation des structures identifiees par leurs noms
1072 //=============================================================================
1073 //=============================================================================
1074 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
1076 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
1077 ASSERT(!CORBA::is_nil(myBoundary));
1078 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1080 //=============================================================================
1081 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
1083 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1084 ASSERT(!CORBA::is_nil(myCase));
1085 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1087 //=============================================================================
1088 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
1090 HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
1091 ASSERT(!CORBA::is_nil(myHypothesis));
1092 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1094 //=============================================================================
1095 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* NomIterationation)
1097 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIterationation];
1098 ASSERT(!CORBA::is_nil(myIteration));
1099 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1101 //=============================================================================
1102 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::GetYACS(const char* nomYACS)
1104 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
1105 ASSERT(!CORBA::is_nil(myYACS));
1106 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
1108 //=============================================================================
1109 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
1111 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1112 ASSERT(!CORBA::is_nil(myZone));
1113 return HOMARD::HOMARD_Zone::_duplicate(myZone);
1115 //=============================================================================
1116 //=============================================================================
1118 //=============================================================================
1119 //=============================================================================
1121 //=============================================================================
1122 //=============================================================================
1123 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)
1125 INFOS ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1126 INFOS ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte );
1131 if ( _PublisMeshIN != 0 ) option = 2 ;
1132 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, 0, option) ;
1133 myCase->SetDirName(DirName) ;
1135 myCase->MeshInfo(Qual, Diam, Conn, Tail, Inte) ;
1139 //=============================================================================
1140 //=============================================================================
1142 //=============================================================================
1143 //=============================================================================
1144 // Recuperation des structures par le contexte
1145 //=============================================================================
1146 //=============================================================================
1147 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::LastIteration(const char* nomCas)
1149 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1150 ASSERT(!CORBA::is_nil(myCase));
1152 HOMARD::HOMARD_Iteration_var myIteration = myCase->LastIteration();
1153 ASSERT(!CORBA::is_nil(myIteration));
1155 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1157 //=============================================================================
1158 //=============================================================================
1160 //=============================================================================
1161 //=============================================================================
1162 // Nouvelles structures
1163 //=============================================================================
1164 //=============================================================================
1165 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1167 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1168 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
1169 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
1170 return aCase._retn();
1172 //=============================================================================
1173 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
1175 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1176 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
1177 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
1178 return aHypo._retn();
1180 //=============================================================================
1181 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
1183 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1184 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
1185 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
1186 return aIter._retn();
1188 //=============================================================================
1189 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1191 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1192 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
1193 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1194 return aBoundary._retn();
1196 //=============================================================================
1197 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
1199 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1200 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
1201 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
1202 return aZone._retn();
1204 //=============================================================================
1205 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::newYACS()
1207 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1208 HOMARD_YACS_i* aServant = new HOMARD_YACS_i(_orb, engine);
1209 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(aServant->_this());
1210 return aYACS._retn();
1212 //=============================================================================
1213 //=============================================================================
1215 //=============================================================================
1216 //=============================================================================
1217 // Creation des structures identifiees par leurs noms
1218 //=============================================================================
1219 //=============================================================================
1220 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
1222 // Creation d'un cas initial
1223 // nomCas : nom du cas a creer
1224 // MeshName, MeshFile : nom et fichier du maillage correspondant
1227 INFOS ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1230 if ( _PublisMeshIN != 0 ) option = 2 ;
1231 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 0, 0, option) ;
1233 // Valeurs par defaut des filtrages
1234 myCase->SetPyram(0);
1236 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1238 //=============================================================================
1239 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromIteration(const char* nomCas, const char* DirNameStart)
1241 // nomCas : nom du cas a creer
1242 // DirNameStart : nom du repertoire contenant l'iteration de reprise
1245 INFOS ( "CreateCaseFromIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1246 std::string nomDirWork = getenv("PWD") ;
1249 // A. Decodage du point de reprise
1250 // A.1. Controle du repertoire de depart de l'iteration
1252 codret = chdir(DirNameStart) ;
1254 codret = _chdir(DirNameStart) ;
1258 SALOME::ExceptionStruct es;
1259 es.type = SALOME::BAD_PARAM;
1260 es.text = "The directory of the iteration does not exist.";
1261 throw SALOME::SALOME_Exception(es);
1264 // A.2. Reperage des fichiers du repertoire de reprise
1265 std::string file_configuration = "" ;
1266 std::string file_maillage_homard = "" ;
1270 struct dirent *dirp;
1271 dp = opendir(DirNameStart);
1272 while ( (dirp = readdir(dp)) != NULL )
1274 std::string file_name(dirp->d_name);
1275 // MESSAGE ( file_name );
1276 bilan = file_name.find("HOMARD.Configuration.") ;
1277 if ( bilan != string::npos ) { file_configuration = file_name ; }
1278 bilan = file_name.find("maill.") ;
1279 if ( bilan != string::npos )
1281 bilan = file_name.find(".hom.med") ;
1282 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1287 HANDLE hFind = INVALID_HANDLE_VALUE;
1288 WIN32_FIND_DATA ffd;
1289 hFind = FindFirstFile(DirNameStart, &ffd);
1290 if (INVALID_HANDLE_VALUE != hFind) {
1291 while (FindNextFile(hFind, &ffd) != 0) {
1292 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1293 std::string file_name(ffd.cFileName);
1294 bilan = file_name.find("HOMARD.Configuration.") ;
1295 if ( bilan != string::npos ) { file_configuration = file_name ; }
1296 bilan = file_name.find("maill.") ;
1297 if ( bilan != string::npos )
1299 bilan = file_name.find(".hom.med") ;
1300 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1306 MESSAGE ( "==> file_configuration : " << file_configuration ) ;
1307 MESSAGE ( "==> file_maillage_homard : " << file_maillage_homard ) ;
1309 if ( ( file_configuration == "" ) || ( file_maillage_homard == "" ) )
1311 SALOME::ExceptionStruct es;
1312 es.type = SALOME::BAD_PARAM;
1314 if ( file_configuration == "" ) { text = "The configuration file cannot be found." ; }
1315 else { text = "The HOMARD mesh file cannot be found." ; }
1316 es.text = CORBA::string_dup(text.c_str());
1317 throw SALOME::SALOME_Exception(es);
1320 // B. Lecture du fichier de configuration
1321 // ATTENTION : on doit veiller a la coherence entre HomardDriver et CreateCaseFromIteration
1327 // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1328 std::ifstream fichier( file_configuration.c_str() );
1329 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1331 std::string ligne; // variable contenant chaque ligne lue
1332 std::string mot_cle;
1333 std::string argument;
1335 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1336 while ( std::getline( fichier, ligne ) )
1338 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1339 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1340 ligne_bis >> mot_cle ;
1341 // B.2. Des valeurs entieres : le second bloc de la ligne
1342 if ( mot_cle == "NumeIter" )
1344 ligne_bis >> NumeIter ;
1347 // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1348 else if ( ( mot_cle == "TypeConf" ) || ( mot_cle == "TypeElem" ) )
1350 ligne_bis >> argument ;
1352 if ( mot_cle == "TypeConf" )
1354 if ( argument == "conforme" ) { TypeConf = 1 ; }
1355 else if ( argument == "non_conforme_1_noeud" ) { TypeConf = 2 ; }
1356 else if ( argument == "non_conforme_1_arete" ) { TypeConf = 3 ; }
1357 else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1359 else if ( mot_cle == "TypeElem" )
1361 if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1362 else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1365 // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1366 // il faut les supprimer
1367 else if ( ( mot_cle == "CCNoMNP1" ) || ( mot_cle == "CCMaiNP1" ) )
1369 ligne_bis >> argument ;
1370 if ( argument[0] == '"' ) { decalage = 1 ; }
1371 else { decalage = 0 ; }
1372 size_t size = argument.size() + 1 - 2*decalage ;
1374 if ( mot_cle == "CCNoMNP1" )
1376 MeshName = new char[ size ];
1377 strncpy( MeshName, argument.c_str()+decalage, size );
1378 MeshName[size-1] = '\0' ;
1380 else if ( mot_cle == "CCMaiNP1" )
1382 MeshFile = new char[ size ];
1383 strncpy( MeshFile, argument.c_str()+decalage, size );
1384 MeshFile[size-1] = '\0' ;
1388 MESSAGE ( "==> TypeConf : " << TypeConf ) ;
1389 MESSAGE ( "==> MeshName : " << MeshName ) ;
1390 MESSAGE ( "==> MeshFile : " << MeshFile ) ;
1391 MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1392 MESSAGE ( "==> Pyram : " << Pyram ) ;
1396 SALOME::ExceptionStruct es;
1397 es.type = SALOME::BAD_PARAM;
1398 std::string text = "The configuration file cannot be read." ;
1399 es.text = CORBA::string_dup(text.c_str());
1400 throw SALOME::SALOME_Exception(es);
1403 // C. Creation effective du cas
1406 if ( _PublisMeshIN != 0 ) option = 2 ;
1407 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, option) ;
1409 // D. Parametrages lus dans le fichier de configuration
1411 myCase->SetConfType (TypeConf) ;
1412 myCase->SetPyram (Pyram) ;
1414 // E. Copie du fichier de maillage homard
1415 // E.1. Repertoire associe au cas
1416 char* nomDirCase = myCase->GetDirName() ;
1417 // E.2. Repertoire 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
1440 codret = chdir(DirNameStart) ;
1442 codret = _chdir(DirNameStart) ;
1444 std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1445 MESSAGE ( "commande : " << commande ) ;
1446 codret = system(commande.c_str()) ;
1447 MESSAGE ( "codret : " << codret ) ;
1450 SALOME::ExceptionStruct es;
1451 es.type = SALOME::BAD_PARAM;
1452 es.text = "The starting point for the case cannot be copied into the working directory.";
1453 throw SALOME::SALOME_Exception(es);
1463 chdir(nomDirWork.c_str());
1465 _chdir(nomDirWork.c_str());
1467 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1469 //=============================================================================
1470 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1472 // nomCas : nom du cas a creer
1473 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1476 INFOS ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1478 std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1480 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1481 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1483 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1485 //=============================================================================
1486 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1488 // nomCas : nom du cas a creer
1489 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1490 // Number : numero de l'iteration de depart
1493 INFOS ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1496 SALOME::ExceptionStruct es;
1497 es.type = SALOME::BAD_PARAM;
1498 es.text = "The number of iteration must be positive.";
1499 throw SALOME::SALOME_Exception(es);
1503 std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1505 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1506 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1508 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1510 //=============================================================================
1511 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1513 // Retourne le nom du repertoire ou se trouve l'iteration voulue.
1514 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1515 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1518 MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1519 std::string nomDirWork = getenv("PWD") ;
1520 std::string DirNameStartIter ;
1522 int NumeIterMax = -1 ;
1524 // A.1. Controle du repertoire de depart du cas
1526 codret = chdir(DirNameStart) ;
1528 codret = _chdir(DirNameStart) ;
1532 SALOME::ExceptionStruct es;
1533 es.type = SALOME::BAD_PARAM;
1534 es.text = "The directory of the case for the pursuit does not exist.";
1535 throw SALOME::SALOME_Exception(es);
1538 // A.2. Reperage des sous-repertoire du repertoire de reprise
1539 bool existe = false ;
1542 struct dirent *dirp;
1543 dp = opendir(DirNameStart);
1544 while ( (dirp = readdir(dp)) != NULL ) {
1545 std::string DirName_1(dirp->d_name);
1547 HANDLE hFind = INVALID_HANDLE_VALUE;
1548 WIN32_FIND_DATA ffd;
1549 hFind = FindFirstFile(DirNameStart, &ffd);
1550 if (INVALID_HANDLE_VALUE != hFind) {
1551 while (FindNextFile(hFind, &ffd) != 0) {
1552 std::string DirName_1 = "";
1553 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1554 DirName_1 = std::string(ffd.cFileName);
1557 if ( ( DirName_1 != "." ) && ( DirName_1 != ".." ) )
1560 if ( chdir(DirName_1.c_str()) == 0 )
1562 // On cherche le fichier de configuration dans ce sous-repertoire
1563 codret = chdir(DirNameStart);
1565 struct dirent *dirp_1;
1566 dp_1 = opendir(DirName_1.c_str()) ;
1567 while ( (dirp_1 = readdir(dp_1)) != NULL )
1569 std::string file_name_1(dirp_1->d_name);
1571 if ( _chdir(DirName_1.c_str()) == 0 )
1573 codret = _chdir(DirNameStart);
1574 HANDLE hFind1 = INVALID_HANDLE_VALUE;
1575 WIN32_FIND_DATA ffd1;
1576 hFind1 = FindFirstFile(DirName_1.c_str(), &ffd1);
1577 while (FindNextFile(hFind1, &ffd1) != 0)
1579 if (ffd1.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1580 std::string file_name_1(ffd1.cFileName);
1582 int bilan = file_name_1.find("HOMARD.Configuration.") ;
1583 if ( bilan != string::npos )
1585 // Decodage du fichier pour trouver le numero d'iteration
1587 chdir(DirName_1.c_str()) ;
1589 _chdir(DirName_1.c_str()) ;
1592 std::ifstream fichier( file_name_1.c_str() );
1593 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1596 std::string ligne; // variable contenant chaque ligne lue
1597 std::string mot_cle;
1598 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1599 while ( std::getline( fichier, ligne ) )
1601 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1602 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1603 ligne_bis >> mot_cle ;
1604 if ( mot_cle == "NumeIter" )
1606 ligne_bis >> NumeIter ;
1608 // MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1609 if ( Number == - 1 )
1611 if ( NumeIter >= NumeIterMax )
1613 NumeIterMax = NumeIter ;
1614 DirNameStartIter = DirName_1 ;
1619 if ( NumeIter == Number )
1621 DirNameStartIter = DirName_1 ;
1631 SALOME::ExceptionStruct es;
1632 es.type = SALOME::BAD_PARAM;
1633 std::string text = "The configuration file cannot be read." ;
1634 es.text = CORBA::string_dup(text.c_str());
1635 throw SALOME::SALOME_Exception(es);
1638 chdir(DirNameStart) ;
1640 _chdir(DirNameStart) ;
1643 if ( existe ) { break ; }
1650 if ( existe ) { break ; }
1656 chdir(nomDirWork.c_str());
1660 _chdir(nomDirWork.c_str());
1663 if ( ( Number >= 0 && ( !existe ) ) || ( Number < 0 && ( NumeIterMax == -1 ) ) )
1665 SALOME::ExceptionStruct es;
1666 es.type = SALOME::BAD_PARAM;
1667 es.text = "The directory of the iteration does not exist.";
1668 throw SALOME::SALOME_Exception(es);
1672 return DirNameStartIter ;
1674 //=============================================================================
1675 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)
1677 // nomCas : nom du cas a creer
1678 // MeshName, MeshFile : nom et fichier du maillage correspondant
1679 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1680 // 1 : le maillage fourni peut ne pas exister ==> on continue si absent
1681 // -1 : le maillage n'est pas fourni
1682 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1683 // Option : multiple de nombres premiers
1684 // 1 : aucune option
1685 // x2 : publication du maillage dans SMESH
1687 MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1688 MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1689 MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1695 // A.2. Controle du nom :
1696 if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
1698 SALOME::ExceptionStruct es;
1699 es.type = SALOME::BAD_PARAM;
1700 es.text = "This case has already been defined.";
1701 throw SALOME::SALOME_Exception(es);
1705 // A.3. Controle du fichier du maillage
1706 int existeMeshFile ;
1707 if ( MeshOption >= 0 )
1709 existeMeshFile = MEDFileExist ( MeshFile ) ;
1710 MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1711 if ( ( existeMeshFile == 0 ) && ( MeshOption == 0 ) )
1713 SALOME::ExceptionStruct es;
1714 es.type = SALOME::BAD_PARAM;
1715 es.text = "The mesh file does not exist.";
1716 throw SALOME::SALOME_Exception(es);
1720 else { existeMeshFile = 0 ; }
1722 // B. Creation de l'objet cas et publication
1723 // MESSAGE ( "CreateCase0 : Creation de l'objet" );
1724 HOMARD::HOMARD_Cas_var myCase = newCase();
1725 myCase->SetName(nomCas);
1726 SALOMEDS::SObject_var aSO;
1727 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
1728 myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
1730 // C. Caracteristiques du maillage
1731 if ( existeMeshFile != 0 )
1733 // Les valeurs extremes des coordonnees
1734 // MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnees" );
1735 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1736 HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1737 if (LesExtremes.size()!=10) { return false; }
1739 for (int i =0 ; i< LesExtremes.size() ; i++)
1740 aSeq[i]=LesExtremes[i] ;
1741 myCase->SetBoundingBox(aSeq) ;
1743 // MESSAGE ( "CreateCase0 : Les groupes" );
1744 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile) ;
1745 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1746 aSeqGroupe->length(LesGroupes.size());
1747 std::set<std::string>::const_iterator it ;
1749 for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1750 aSeqGroupe[i++]=(*it).c_str() ;
1751 myCase->SetGroups(aSeqGroupe) ;
1754 // D. L'iteration initiale du cas
1755 MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1756 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1757 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1759 std::string NomIteration = std::string(MeshName) ;
1760 while ( (myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()) )
1762 std::ostringstream nom;
1763 nom << MeshName << monNum;
1764 NomIteration = nom.str();
1767 MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1769 // D.2. Creation de l'iteration
1770 HOMARD::HOMARD_Iteration_var anIter = newIteration();
1771 myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration] = anIter;
1772 anIter->SetName(NomIteration.c_str());
1773 AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1775 // D.4. Maillage correspondant
1776 if ( existeMeshFile != 0 )
1778 anIter->SetMeshFile(MeshFile);
1779 if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1781 anIter->SetMeshName(MeshName);
1783 // D.5. Numero d'iteration
1784 anIter->SetNumber(NumeIter);
1787 SetEtatIter(NomIteration.c_str(), -NumeIter);
1790 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1792 //=============================================================================
1793 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1795 INFOS ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1798 // A. Controle du nom :
1799 if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
1801 SALOME::ExceptionStruct es;
1802 es.type = SALOME::BAD_PARAM;
1803 es.text = "This hypothesis has already been defined.";
1804 throw SALOME::SALOME_Exception(es);
1808 // B. Creation de l'objet
1809 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1810 if (CORBA::is_nil(myHypothesis))
1812 SALOME::ExceptionStruct es;
1813 es.type = SALOME::BAD_PARAM;
1814 es.text = "Unable to create the hypothesis";
1815 throw SALOME::SALOME_Exception(es);
1818 myHypothesis->SetName(nomHypothesis);
1820 // C. Enregistrement
1821 myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
1823 SALOMEDS::SObject_var aSO;
1824 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
1826 // D. Valeurs par defaut des options avancees
1827 myHypothesis->SetNivMax(-1);
1828 myHypothesis->SetDiamMin(-1.0);
1829 myHypothesis->SetAdapInit(0);
1830 myHypothesis->SetLevelOutput(0);
1832 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1835 //=============================================================================
1836 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1837 //=============================================================================
1839 INFOS ("CreateIteration : NomIteration = " << NomIteration << ", nomIterParent = " << nomIterParent);
1842 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
1843 if (CORBA::is_nil(myIterationParent))
1845 SALOME::ExceptionStruct es;
1846 es.type = SALOME::BAD_PARAM;
1847 es.text = "The parent iteration is not defined.";
1848 throw SALOME::SALOME_Exception(es);
1852 const char* nomCas = myIterationParent->GetCaseName();
1853 MESSAGE ("CreateIteration : nomCas = " << nomCas);
1854 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1855 if (CORBA::is_nil(myCase))
1857 SALOME::ExceptionStruct es;
1858 es.type = SALOME::BAD_PARAM;
1859 es.text = "Invalid case context";
1860 throw SALOME::SALOME_Exception(es);
1863 const char* nomDirCase = myCase->GetDirName();
1865 // Controle du nom :
1866 if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
1868 SALOME::ExceptionStruct es;
1869 es.type = SALOME::BAD_PARAM;
1870 es.text = "This iteration has already been defined.";
1871 throw SALOME::SALOME_Exception(es);
1875 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1876 if (CORBA::is_nil(myIteration))
1878 SALOME::ExceptionStruct es;
1879 es.type = SALOME::BAD_PARAM;
1880 es.text = "Unable to create the iteration";
1881 throw SALOME::SALOME_Exception(es);
1884 myContextMap[GetCurrentStudyID()]._mesIterations[std::string(NomIteration)] = myIteration;
1885 // Nom de l'iteration et du maillage
1886 myIteration->SetName(NomIteration);
1887 myIteration->SetMeshName(NomIteration);
1888 myIteration->SetState(1);
1890 int numero = myIterationParent->GetNumber() + 1;
1891 myIteration->SetNumber(numero);
1893 // Nombre d'iterations deja connues pour le cas, permettant
1894 // la creation d'un sous-repertoire unique
1895 int nbitercase = myCase->GetNumberofIter();
1896 char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1897 myIteration->SetDirNameLoc(nomDirIter);
1899 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1900 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1901 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1902 // situation la plus frequente.
1903 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1904 // le nombre d'iterations du cas permet d'eviter les collisions.
1906 if ( nbitercase < 100 ) { jaux = 2 ; }
1907 else if ( nbitercase < 1000 ) { jaux = 3 ; }
1908 else if ( nbitercase < 10000 ) { jaux = 4 ; }
1909 else if ( nbitercase < 100000 ) { jaux = 5 ; }
1911 std::ostringstream iaux ;
1912 iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1913 std::stringstream MeshFile;
1914 MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1915 myIteration->SetMeshFile(MeshFile.str().c_str());
1917 // Association avec le cas
1918 std::string label = "IterationHomard_" + std::string(nomIterParent);
1919 AssociateCaseIter(nomCas, NomIteration, label.c_str());
1920 // Lien avec l'iteration precedente
1921 myIterationParent->LinkNextIteration(NomIteration);
1922 myIteration->SetIterParentName(nomIterParent);
1923 // Gestion de l'arbre d'etudes
1924 SALOMEDS::SObject_var aIterSOParent = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIterationParent)));
1925 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
1926 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1927 aStudyBuilder->NewCommand();
1928 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
1929 aStudyBuilder->Addreference(aSubSO, aIterSOParent);
1930 aStudyBuilder->CommitCommand();
1932 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1934 //=============================================================================
1935 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1937 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1940 // Controle du nom :
1941 if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
1943 MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1944 SALOME::ExceptionStruct es;
1945 es.type = SALOME::BAD_PARAM;
1946 es.text = "This boundary has already been defined";
1947 throw SALOME::SALOME_Exception(es);
1951 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1952 myBoundary->SetName(BoundaryName);
1953 myBoundary->SetType(BoundaryType);
1955 myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
1957 SALOMEDS::SObject_var aSO;
1958 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
1960 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1962 //=============================================================================
1963 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1965 INFOS ("CreateBoundaryDi : BoundaryName = " << BoundaryName << "MeshName = " << MeshName );
1966 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1967 myBoundary->SetMeshFile( MeshFile ) ;
1968 myBoundary->SetMeshName( MeshName ) ;
1970 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1972 //=============================================================================
1973 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1974 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1975 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1976 CORBA::Double Rayon)
1978 INFOS ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
1980 SALOME::ExceptionStruct es;
1983 { es.text = "The radius must be positive." ;
1985 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1986 if ( daux < 0.0000001 )
1987 { es.text = "The axis must be a non 0 vector." ;
1991 es.type = SALOME::BAD_PARAM;
1992 throw SALOME::SALOME_Exception(es);
1996 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1997 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1999 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2001 //=============================================================================
2002 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
2003 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2004 CORBA::Double Rayon)
2006 INFOS ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
2008 SALOME::ExceptionStruct es;
2011 { es.text = "The radius must be positive." ;
2015 es.type = SALOME::BAD_PARAM;
2016 throw SALOME::SALOME_Exception(es);
2020 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
2021 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2023 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2025 //=============================================================================
2026 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
2027 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
2028 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
2030 INFOS ("CreateBoundaryConeA : BoundaryName = " << BoundaryName ) ;
2032 SALOME::ExceptionStruct es;
2034 if ( Angle <= 0.0 || Angle >= 90.0 )
2035 { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
2037 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2038 if ( daux < 0.0000001 )
2039 { es.text = "The axis must be a non 0 vector." ;
2043 es.type = SALOME::BAD_PARAM;
2044 throw SALOME::SALOME_Exception(es);
2048 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
2049 myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
2051 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2053 //=============================================================================
2054 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
2055 CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
2056 CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
2058 INFOS ("CreateBoundaryConeR : BoundaryName = " << BoundaryName ) ;
2060 SALOME::ExceptionStruct es;
2062 if ( Rayon1 < 0.0 || Rayon2 < 0.0 )
2063 { es.text = "The radius must be positive." ;
2065 double daux = fabs(Rayon2-Rayon1) ;
2066 if ( daux < 0.0000001 )
2067 { es.text = "The radius must be different." ;
2069 daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
2070 if ( daux < 0.0000001 )
2071 { es.text = "The centers must be different." ;
2075 es.type = SALOME::BAD_PARAM;
2076 throw SALOME::SALOME_Exception(es);
2080 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
2081 myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
2083 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2085 //=============================================================================
2086 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryTorus(const char* BoundaryName,
2087 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2088 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2089 CORBA::Double RayonRev, CORBA::Double RayonPri)
2091 INFOS ("CreateBoundaryTorus : BoundaryName = " << BoundaryName ) ;
2093 SALOME::ExceptionStruct es;
2095 if ( ( RayonRev <= 0.0 ) || ( RayonPri <= 0.0 ) )
2096 { es.text = "The radius must be positive." ;
2098 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2099 if ( daux < 0.0000001 )
2100 { es.text = "The axis must be a non 0 vector." ;
2104 es.type = SALOME::BAD_PARAM;
2105 throw SALOME::SALOME_Exception(es);
2109 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 5) ;
2110 myBoundary->SetTorus( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, RayonRev, RayonPri ) ;
2112 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2114 //=============================================================================
2115 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
2117 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
2120 // Controle du nom :
2121 if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
2123 SALOME::ExceptionStruct es;
2124 es.type = SALOME::BAD_PARAM;
2125 es.text = "This zone has already been defined";
2126 throw SALOME::SALOME_Exception(es);
2130 HOMARD::HOMARD_Zone_var myZone = newZone();
2131 myZone->SetName(ZoneName);
2132 myZone->SetType(ZoneType);
2134 myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
2136 SALOMEDS::SObject_var aSO;
2137 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
2139 return HOMARD::HOMARD_Zone::_duplicate(myZone);
2141 //=============================================================================
2142 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
2143 CORBA::Double Xmini, CORBA::Double Xmaxi,
2144 CORBA::Double Ymini, CORBA::Double Ymaxi,
2145 CORBA::Double Zmini, CORBA::Double Zmaxi)
2147 INFOS ("CreateZoneBox : ZoneName = " << ZoneName ) ;
2149 SALOME::ExceptionStruct es;
2151 if ( Xmini > Xmaxi )
2152 { es.text = "The X coordinates are not coherent." ;
2154 if ( Ymini > Ymaxi )
2155 { es.text = "The Y coordinates are not coherent." ;
2157 if ( Zmini > Zmaxi )
2158 { es.text = "The Z coordinates are not coherent." ;
2162 es.type = SALOME::BAD_PARAM;
2163 throw SALOME::SALOME_Exception(es);
2167 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
2168 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2170 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2172 //=============================================================================
2173 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
2174 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
2176 INFOS ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
2178 SALOME::ExceptionStruct es;
2181 { es.text = "The radius must be positive." ;
2185 es.type = SALOME::BAD_PARAM;
2186 throw SALOME::SALOME_Exception(es);
2190 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
2191 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2193 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2195 //=============================================================================
2196 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
2197 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2198 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2199 CORBA::Double Rayon, CORBA::Double Haut)
2201 INFOS ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
2203 SALOME::ExceptionStruct es;
2206 { es.text = "The radius must be positive." ;
2208 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2209 if ( daux < 0.0000001 )
2210 { es.text = "The axis must be a non 0 vector." ;
2213 { es.text = "The height must be positive." ;
2217 es.type = SALOME::BAD_PARAM;
2218 throw SALOME::SALOME_Exception(es);
2222 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
2223 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
2225 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2227 //=============================================================================
2228 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
2229 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2230 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2231 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
2233 INFOS ("CreateZonePipe : ZoneName = " << ZoneName ) ;
2235 SALOME::ExceptionStruct es;
2237 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2238 { es.text = "The radius must be positive." ;
2240 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2241 if ( daux < 0.0000001 )
2242 { es.text = "The axis must be a non 0 vector." ;
2245 { es.text = "The height must be positive." ;
2247 if ( Rayon <= Rayonint )
2248 { es.text = "The external radius must be higher than the internal radius." ;
2252 es.type = SALOME::BAD_PARAM;
2253 throw SALOME::SALOME_Exception(es);
2257 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
2258 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
2260 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2262 //=============================================================================
2263 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
2264 CORBA::Double Umini, CORBA::Double Umaxi,
2265 CORBA::Double Vmini, CORBA::Double Vmaxi,
2268 INFOS ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
2269 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
2270 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
2271 // MESSAGE ("Orient = " << Orient ) ;
2273 SALOME::ExceptionStruct es;
2275 if ( Umini > Umaxi )
2276 { es.text = "The first coordinates are not coherent." ;
2278 if ( Vmini > Vmaxi )
2279 { es.text = "The second coordinates are not coherent." ;
2281 if ( Orient < 1 || Orient > 3 )
2282 { es.text = "The orientation must be 1, 2 or 3." ;
2286 es.type = SALOME::BAD_PARAM;
2287 throw SALOME::SALOME_Exception(es);
2291 double Xmini, Xmaxi ;
2292 double Ymini, Ymaxi ;
2293 double Zmini, Zmaxi ;
2301 else if ( Orient == 2 )
2308 else if ( Orient == 3 )
2315 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2317 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2318 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2320 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2322 //=============================================================================
2323 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2324 CORBA::Double Ucentre, CORBA::Double Vcentre,
2325 CORBA::Double Rayon,
2328 INFOS ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
2330 SALOME::ExceptionStruct es;
2333 { es.text = "The radius must be positive." ;
2335 if ( Orient < 1 || Orient > 3 )
2336 { es.text = "The orientation must be 1, 2 or 3." ;
2340 es.type = SALOME::BAD_PARAM;
2341 throw SALOME::SALOME_Exception(es);
2349 { Xcentre = Ucentre ;
2352 else if ( Orient == 2 )
2355 Zcentre = Vcentre ; }
2356 else if ( Orient == 3 )
2357 { Xcentre = Vcentre ;
2359 Zcentre = Ucentre ; }
2360 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2362 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2363 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2365 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2367 //=============================================================================
2368 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2369 CORBA::Double Ucentre, CORBA::Double Vcentre,
2370 CORBA::Double Rayon, CORBA::Double Rayonint,
2373 INFOS ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
2375 SALOME::ExceptionStruct es;
2377 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2378 { es.text = "The radius must be positive." ;
2380 if ( Orient < 1 || Orient > 3 )
2381 { es.text = "The orientation must be 1, 2 or 3." ;
2383 if ( Rayon <= Rayonint )
2384 { es.text = "The external radius must be higher than the internal radius." ;
2388 es.type = SALOME::BAD_PARAM;
2389 throw SALOME::SALOME_Exception(es);
2397 { Xcentre = Ucentre ;
2400 else if ( Orient == 2 )
2403 Zcentre = Vcentre ; }
2404 else if ( Orient == 3 )
2405 { Xcentre = Vcentre ;
2407 Zcentre = Ucentre ; }
2408 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2410 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2411 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2413 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2415 //=============================================================================
2416 //=============================================================================
2421 //=============================================================================
2422 //=============================================================================
2423 // Traitement d'une iteration
2424 // etatMenage = 1 : destruction du repertoire d'execution
2425 // modeHOMARD = 1 : adaptation
2426 // != 1 : information avec les options modeHOMARD
2427 // Option1 >0 : appel depuis python
2428 // <0 : appel depuis GUI
2429 // Option2 : multiple de nombres premiers
2430 // 1 : aucune option
2431 // x2 : publication du maillage dans SMESH
2432 //=============================================================================
2433 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2435 INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2440 // A.1. L'objet iteration
2441 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
2442 ASSERT(!CORBA::is_nil(myIteration));
2444 // A.2. Controle de la possibilite d'agir
2445 // A.2.1. Etat de l'iteration
2446 int etat = myIteration->GetState();
2447 MESSAGE ( "etat = "<<etat );
2448 // A.2.2. On ne calcule pas l'iteration initiale, ni une iteration deja calculee
2449 if ( modeHOMARD == 1 )
2453 SALOME::ExceptionStruct es;
2454 es.type = SALOME::BAD_PARAM;
2455 es.text = "This iteration is the first of the case and cannot be computed.";
2456 throw SALOME::SALOME_Exception(es);
2459 else if ( ( etat == 2 ) & ( modeHOMARD == 1 ) )
2461 SALOME::ExceptionStruct es;
2462 es.type = SALOME::BAD_PARAM;
2463 es.text = "This iteration is already computed.";
2464 throw SALOME::SALOME_Exception(es);
2468 // A.2.3. On n'analyse pas une iteration non calculee
2473 SALOME::ExceptionStruct es;
2474 es.type = SALOME::BAD_PARAM;
2475 es.text = "This iteration is not computed.";
2476 throw SALOME::SALOME_Exception(es);
2481 // A.3. Numero de l'iteration
2482 // siterp1 : numero de l'iteration a traiter
2484 // siter : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2485 // Ou si information :
2487 int NumeIter = myIteration->GetNumber();
2488 std::string siterp1 ;
2489 std::stringstream saux1 ;
2491 siterp1 = saux1.str() ;
2492 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2495 if ( modeHOMARD==1 )
2497 std::stringstream saux0 ;
2498 int iaux = max(0, NumeIter-1) ;
2500 siter = saux0.str() ;
2501 if (NumeIter < 11) { siter = "0" + siter ; }
2504 { siter = siterp1 ; }
2507 const char* nomCas = myIteration->GetCaseName();
2508 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
2509 ASSERT(!CORBA::is_nil(myCase));
2511 // B. Les repertoires
2512 // B.1. Le repertoire courant
2513 std::string nomDirWork = getenv("PWD") ;
2514 // B.2. Le sous-repertoire de l'iteration a traiter
2515 char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2516 MESSAGE( ". DirCompute = " << DirCompute );
2518 // C. Le fichier des messages
2519 // C.1. Le deroulement de l'execution de HOMARD
2520 std::string LogFile = DirCompute ;
2521 LogFile += "/Liste" ;
2522 if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2524 MESSAGE (". LogFile = " << LogFile);
2525 if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2526 // C.2. Le bilan de l'analyse du maillage
2527 std::string FileInfo = DirCompute ;
2529 if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2531 { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2532 else { FileInfo += "info_ap" ; }
2534 FileInfo += "." + siterp1 + ".bilan" ;
2535 myIteration->SetFileInfo(FileInfo.c_str());
2537 // D. On passe dans le repertoire de l'iteration a calculer
2538 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2545 // E. Les donnees de l'execution HOMARD
2546 // E.1. L'objet du texte du fichier de configuration
2547 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2548 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2550 // E.2. Le maillage associe a l'iteration
2551 const char* NomMesh = myIteration->GetMeshName();
2552 MESSAGE ( ". NomMesh = " << NomMesh );
2553 const char* MeshFile = myIteration->GetMeshFile();
2554 MESSAGE ( ". MeshFile = " << MeshFile );
2556 // E.3. Les donnees du traitement HOMARD
2558 if ( modeHOMARD == 1 )
2561 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2562 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2563 codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2567 InvalideIterInfo(NomIteration);
2568 myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2570 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2571 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2572 myDriver->CreeFichierDonn();
2575 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2576 DriverTexteBoundary(myCase, myDriver) ;
2578 // E.5. Ecriture du texte dans le fichier
2579 MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2581 { myDriver->CreeFichier(); }
2585 int codretexec = 12 ;
2588 codretexec = myDriver->ExecuteHomard(Option1);
2590 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2591 // En mode adaptation, on ajuste l'etat de l'iteration
2592 if ( modeHOMARD == 1 )
2594 if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2595 else { SetEtatIter(NomIteration,1); }
2596 // GERALD -- QMESSAGE BOX
2600 // H. Gestion des resultats
2603 std::string Commentaire ;
2604 // H.1. Le fichier des messages, dans tous les cas
2605 Commentaire = "log" ;
2606 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2607 else { Commentaire += "Info" ; }
2608 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2610 // H.2. Si tout s'est bien passe :
2611 if (codretexec == 0)
2613 // H.2.1. Le fichier de bilan
2614 Commentaire = "Summary" ;
2615 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2616 else { Commentaire += "Info" ; }
2617 PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2618 // H.2.2. Le fichier de maillage obtenu
2619 if ( modeHOMARD == 1 )
2621 std::stringstream saux0 ;
2622 Commentaire = "Mesh" ;
2623 Commentaire += " " + siterp1 ;
2624 PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2625 if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2628 // H.3 Message d'erreur
2629 if (codretexec != 0)
2632 // Message d'erreur en cas de probleme en adaptation
2633 if ( modeHOMARD == 1 )
2635 text = "Error during the adaptation.\n" ;
2636 bool stopvu = false ;
2637 std::ifstream fichier( LogFile.c_str() );
2638 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
2640 std::string ligne; // variable contenant chaque ligne lue
2641 while ( std::getline( fichier, ligne ) )
2645 { text += ligne+ "\n"; }
2648 int position = ligne.find( "===== HOMARD ===== STOP =====" ) ;
2649 if ( position > 0 ) { stopvu = true ; }
2656 text = "Voir le fichier Liste.log.\n" ;
2659 SALOME::ExceptionStruct es;
2660 es.type = SALOME::BAD_PARAM;
2661 es.text = CORBA::string_dup(text.c_str());
2662 throw SALOME::SALOME_Exception(es);
2664 // En mode information, on force le succes pour pouvoir consulter le fichier log
2665 if ( modeHOMARD != 1 ) { codretexec = 0 ; }
2669 // I. Menage et retour dans le repertoire du cas
2673 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2676 chdir(nomDirWork.c_str());
2678 _chdir(nomDirWork.c_str());
2684 //=============================================================================
2685 // Calcul d'une iteration : partie specifique a l'adaptation
2686 //=============================================================================
2687 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)
2689 MESSAGE ( "ComputeAdap" );
2694 // Numero de l'iteration
2695 int NumeIter = myIteration->GetNumber();
2696 std::stringstream saux0 ;
2697 saux0 << NumeIter-1 ;
2698 std::string siter = saux0.str() ;
2699 if (NumeIter < 11) { siter = "0" + siter ; }
2701 // A.2. On verifie qu il y a une hypothese (erreur improbable);
2702 const char* nomHypo = myIteration->GetHypoName();
2703 if (std::string(nomHypo) == std::string(""))
2705 SALOME::ExceptionStruct es;
2706 es.type = SALOME::BAD_PARAM;
2707 es.text = "This iteration does not have any associated hypothesis.";
2708 throw SALOME::SALOME_Exception(es);
2711 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
2712 ASSERT(!CORBA::is_nil(myHypo));
2714 // B. L'iteration parent
2715 const char* nomIterationParent = myIteration->GetIterParentName();
2716 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2717 ASSERT(!CORBA::is_nil(myIterationParent));
2718 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2719 if ( myIterationParent->GetState() == 1 )
2722 int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2725 // GERALD -- QMESSAGE BOX
2726 VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2730 // C. Le sous-repertoire de l'iteration precedente
2731 char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2732 MESSAGE( ". DirComputePa = " << DirComputePa );
2734 // D. Les donnees de l'adaptation HOMARD
2735 // D.1. Le type de conformite
2736 int ConfType = myCase->GetConfType();
2737 MESSAGE ( ". ConfType = " << ConfType );
2739 // D.2. Le maillage de depart
2740 const char* NomMeshParent = myIterationParent->GetMeshName();
2741 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2742 const char* MeshFileParent = myIterationParent->GetMeshFile();
2743 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2745 // D.3. Le maillage associe a l'iteration
2746 const char* MeshFile = myIteration->GetMeshFile();
2747 MESSAGE ( ". MeshFile = " << MeshFile );
2748 FILE *file = fopen(MeshFile,"r");
2752 if (etatMenage == 0)
2754 SALOME::ExceptionStruct es;
2755 es.type = SALOME::BAD_PARAM;
2756 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2757 es.text = CORBA::string_dup(text.c_str());
2758 throw SALOME::SALOME_Exception(es);
2763 std::string commande = "rm -f " + std::string(MeshFile);
2764 codret = system(commande.c_str());
2767 SALOME::ExceptionStruct es;
2768 es.type = SALOME::BAD_PARAM;
2769 es.text = "The mesh file cannot be deleted.";
2770 throw SALOME::SALOME_Exception(es);
2776 // D.4. Les types de raffinement et de deraffinement
2777 // Les appels corba sont lourds, il vaut mieux les grouper
2778 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2779 ASSERT(ListTypes->length() == 3);
2780 int TypeAdap = (*ListTypes)[0];
2781 int TypeRaff = (*ListTypes)[1];
2782 int TypeDera = (*ListTypes)[2];
2784 // E. Texte du fichier de configuration
2785 // E.1. Incontournables du texte
2786 myDriver->TexteAdap();
2788 myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2789 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2790 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2792 // E.2. Ajout des informations liees aux zones eventuelles
2793 if ( TypeAdap == 0 )
2794 { DriverTexteZone(myHypo, myDriver) ; }
2796 // E.3. Ajout des informations liees aux champs eventuels
2797 if ( TypeAdap == 1 )
2798 { DriverTexteField(myIteration, myHypo, myDriver) ; }
2800 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2801 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2802 int numberOfGroups = listeGroupes->length();
2803 MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2804 if (numberOfGroups > 0)
2806 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2808 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2809 MESSAGE( "... GroupName = " << GroupName );
2810 myDriver->TexteGroup(GroupName);
2814 // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2815 DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2817 // E.6. Ajout des options avancees
2818 int Pyram = myCase->GetPyram();
2819 MESSAGE ( ". Pyram = " << Pyram );
2820 int NivMax = myHypo->GetNivMax();
2821 MESSAGE ( ". NivMax = " << NivMax );
2822 double DiamMin = myHypo->GetDiamMin() ;
2823 MESSAGE ( ". DiamMin = " << DiamMin );
2824 int AdapInit = myHypo->GetAdapInit();
2825 MESSAGE ( ". AdapInit = " << AdapInit );
2826 int LevelOutput = myHypo->GetLevelOutput();
2827 MESSAGE ( ". LevelOutput = " << LevelOutput );
2828 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
2830 // E.7. Ajout des informations sur le deroulement de l'execution
2831 int MessInfo = myIteration->GetInfoCompute();
2832 MESSAGE ( ". MessInfo = " << MessInfo );
2833 myDriver->TexteInfoCompute(MessInfo);
2837 //=============================================================================
2838 // Creation d'un nom de sous-repertoire pour l'iteration au sein d'un repertoire parent
2839 // nomrep : nom du repertoire parent
2840 // num : le nom du sous-repertoire est sous la forme 'In', n est >= num
2841 //=============================================================================
2842 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
2844 MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2845 // On verifie que le repertoire parent existe
2847 int codret = chdir(nomrep) ;
2849 int codret = _chdir(nomrep) ;
2853 SALOME::ExceptionStruct es;
2854 es.type = SALOME::BAD_PARAM;
2855 es.text = "The directory of the case does not exist.";
2856 throw SALOME::SALOME_Exception(es);
2859 std::string nomDirActuel = getenv("PWD") ;
2860 std::string DirName ;
2861 // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un repertoire inconnu
2862 bool a_chercher = true ;
2863 while ( a_chercher )
2865 // On passe dans le repertoire parent
2872 // On recherche un nom sous la forme Iabc, avec abc representant le numero
2874 if ( num < 100 ) { jaux = 2 ; }
2875 else if ( num < 1000 ) { jaux = 3 ; }
2876 else if ( num < 10000 ) { jaux = 4 ; }
2877 else if ( num < 100000 ) { jaux = 5 ; }
2879 std::ostringstream iaux ;
2880 iaux << std::setw(jaux) << std::setfill('0') << num ;
2881 std::ostringstream DirNameA ;
2882 DirNameA << "I" << iaux.str();
2883 // Si on ne pas peut entrer dans le repertoire, on doit verifier
2884 // que c'est bien un probleme d'absence
2886 if ( chdir(DirNameA.str().c_str()) != 0 )
2889 if ( _chdir(DirNameA.str().c_str()) != 0 )
2892 bool existe = false ;
2895 struct dirent *dirp;
2896 dp = opendir(nomrep);
2897 while ( (dirp = readdir(dp)) != NULL )
2899 std::string file_name(dirp->d_name);
2901 HANDLE hFind = INVALID_HANDLE_VALUE;
2902 WIN32_FIND_DATA ffd;
2903 hFind = FindFirstFile(nomrep, &ffd);
2904 if (INVALID_HANDLE_VALUE != hFind) {
2905 while (FindNextFile(hFind, &ffd) != 0) {
2906 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2907 std::string file_name(ffd.cFileName);
2909 if ( file_name == DirNameA.str() ) { existe = true ; }
2919 DirName = DirNameA.str() ;
2920 a_chercher = false ;
2927 MESSAGE ( "==> DirName = " << DirName);
2928 MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
2930 chdir(nomDirActuel.c_str());
2932 _chdir(nomDirActuel.c_str());
2934 return CORBA::string_dup( DirName.c_str() );
2936 //=============================================================================
2937 // Calcul d'une iteration : gestion du repertoire de calcul
2938 // Si le sous-repertoire existe :
2939 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
2940 // etatMenage = 1 : on fait le menage du repertoire
2941 // etatMenage = -1 : on ne fait rien
2942 //=============================================================================
2943 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
2945 MESSAGE ( "ComputeDirManagement : repertoires pour le calcul" );
2946 // B.2. Le repertoire du cas
2947 const char* nomDirCase = myCase->GetDirName();
2948 MESSAGE ( ". nomDirCase = " << nomDirCase );
2950 // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
2951 // B.3.1. Le nom du sous-repertoire
2952 const char* nomDirIt = myIteration->GetDirNameLoc();
2954 // B.3.2. Le nom complet du sous-repertoire
2955 std::stringstream DirCompute ;
2956 DirCompute << nomDirCase << "/" << nomDirIt;
2957 MESSAGE (". DirCompute = " << DirCompute.str() );
2959 // B.3.3. Si le sous-repertoire n'existe pas, on le cree
2961 if (chdir(DirCompute.str().c_str()) != 0)
2963 // Creation du repertoire car il n'existe pas :
2964 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2967 if (_chdir(DirCompute.str().c_str()) != 0)
2969 // Creation du repertoire car il n'existe pas :
2970 if (_mkdir(DirCompute.str().c_str()) != 0)
2973 // GERALD -- QMESSAGE BOX
2974 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
2975 VERIFICATION("Pb a la creation du repertoire" == 0);
2980 // Le repertoire existe
2981 // On demande de faire le menage de son contenu :
2982 if (etatMenage == 1)
2984 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
2985 std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
2986 int codret = system(commande.c_str());
2989 // GERALD -- QMESSAGE BOX
2990 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
2991 VERIFICATION("Pb au menage du repertoire de calcul" == 0);
2994 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2997 if (etatMenage == 0)
3001 struct dirent *dirp;
3002 dp = opendir(DirCompute.str().c_str());
3004 while ((dirp = readdir(dp)) != NULL && result )
3006 std::string file_name(dirp->d_name);
3007 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3011 HANDLE hFind = INVALID_HANDLE_VALUE;
3012 WIN32_FIND_DATA ffd;
3013 hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
3015 if (INVALID_HANDLE_VALUE != hFind) {
3016 while (FindNextFile(hFind, &ffd) != 0) {
3017 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
3018 std::string file_name(ffd.cFileName);
3019 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3024 if ( result == false)
3026 SALOME::ExceptionStruct es;
3027 es.type = SALOME::BAD_PARAM;
3028 std::string text = "Directory : " + DirCompute.str() + " is not empty";
3029 es.text = CORBA::string_dup(text.c_str());
3030 throw SALOME::SALOME_Exception(es);
3031 VERIFICATION("Directory is not empty" == 0);
3037 return CORBA::string_dup( DirCompute.str().c_str() );
3039 //=============================================================================
3040 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
3041 //=============================================================================
3042 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
3044 MESSAGE ( "ComputeDirPaManagement : repertoires pour le calcul" );
3045 // Le repertoire du cas
3046 const char* nomDirCase = myCase->GetDirName();
3047 MESSAGE ( ". nomDirCase = " << nomDirCase );
3049 // Le sous-repertoire de l'iteration precedente
3051 const char* nomIterationParent = myIteration->GetIterParentName();
3052 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
3053 const char* nomDirItPa = myIterationParent->GetDirNameLoc();
3054 std::stringstream DirComputePa ;
3055 DirComputePa << nomDirCase << "/" << nomDirItPa;
3056 MESSAGE( ". nomDirItPa = " << nomDirItPa);
3057 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
3059 return CORBA::string_dup( DirComputePa.str().c_str() );
3061 //=============================================================================
3062 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
3063 //=============================================================================
3064 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3066 MESSAGE ( "... DriverTexteZone" );
3067 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3068 int numberOfZonesx2 = ListZone->length();
3071 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3073 std::string ZoneName = std::string((*ListZone)[iaux]);
3074 MESSAGE ( "... ZoneName = " << ZoneName);
3075 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
3076 ASSERT(!CORBA::is_nil(myZone));
3078 int ZoneType = myZone->GetType();
3079 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
3080 int TypeUse = atoi( TypeUsestr.c_str() );
3081 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
3082 NumZone = iaux/2 + 1 ;
3083 HOMARD::double_array* zone = myZone->GetCoords();
3084 if ( ZoneType == 2 || ( ZoneType>=11 && ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
3085 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
3086 else if ( ZoneType == 4 ) // Cas d une sphere
3087 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
3088 else if ( ZoneType == 5 || ( ZoneType>=31 && ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
3089 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
3090 else if ( ZoneType == 7 || ( ZoneType>=61 && ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
3091 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
3092 else { VERIFICATION("ZoneType est incorrect." == 0) ; }
3097 //=============================================================================
3098 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
3099 //=============================================================================
3100 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3102 MESSAGE ( "... DriverTexteField" );
3103 // Le fichier du champ
3104 char* FieldFile = myIteration->GetFieldFile();
3105 MESSAGE ( ". FieldFile = " << FieldFile );
3106 if (strlen(FieldFile) == 0)
3108 // GERALD -- QMESSAGE BOX
3109 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
3110 VERIFICATION("The file for the field is not given." == 0);
3112 // Les caracteristiques d'instants du champ de pilotage
3113 int TimeStep = myIteration->GetTimeStep();
3114 MESSAGE( ". TimeStep = " << TimeStep );
3115 int Rank = myIteration->GetRank();
3116 MESSAGE( ". Rank = " << Rank );
3117 // Les informations sur les champs
3118 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
3120 const char* FieldName = aInfosHypo->FieldName;
3122 int TypeThR = aInfosHypo->TypeThR;
3123 double ThreshR = aInfosHypo->ThreshR;
3124 int TypeThC = aInfosHypo->TypeThC;
3125 double ThreshC = aInfosHypo->ThreshC;
3126 // Saut entre mailles ou non ?
3127 int UsField = aInfosHypo->UsField;
3128 MESSAGE( ". UsField = " << UsField );
3129 // L'usage des composantes
3130 int UsCmpI = aInfosHypo->UsCmpI;
3131 MESSAGE( ". UsCmpI = " << UsCmpI );
3133 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
3136 HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
3137 int numberOfCompos = mescompo->length();
3138 MESSAGE( ". numberOfCompos = " << numberOfCompos );
3139 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
3141 std::string nomCompo = std::string((*mescompo)[NumeComp]);
3142 MESSAGE( "... nomCompo = " << nomCompo );
3143 myDriver->TexteCompo(NumeComp, nomCompo);
3147 //=============================================================================
3148 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
3149 // On ecrit dans l'ordre :
3150 // 1. la definition des frontieres
3151 // 2. les liens avec les groupes
3152 // 3. un entier resumant le type de comportement pour les frontieres
3153 //=============================================================================
3154 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
3156 MESSAGE ( "... DriverTexteBoundary" );
3157 // 1. Recuperation des frontieres
3158 std::list<std::string> ListeBoundaryTraitees ;
3159 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3160 int numberOfitems = ListBoundaryGroupType->length();
3161 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
3162 int BoundaryOption = 1 ;
3163 // 2. Parcours des frontieres pour ecrire leur description
3164 int NumBoundaryAnalytical = 0 ;
3165 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3167 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3168 MESSAGE ( "... BoundaryName = " << BoundaryName);
3169 // 2.1. La frontiere a-t-elle deja ete ecrite ?
3170 // Cela arrive quand elle estliéé a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
3172 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3173 while (it != ListeBoundaryTraitees.end())
3175 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3176 if ( BoundaryName == *it ) { A_faire = 0 ; }
3179 // 2.2. Ecriture de la frontiere
3182 // 2.2.1. Caracteristiques de la frontiere
3183 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3184 ASSERT(!CORBA::is_nil(myBoundary));
3185 int BoundaryType = myBoundary->GetType();
3186 MESSAGE ( "... BoundaryType = " << BoundaryType );
3187 // 2.2.2. Ecriture selon le type
3188 // 2.2.2.1. Cas d une frontiere discrete
3189 if (BoundaryType == 0)
3191 const char* MeshName = myBoundary->GetMeshName() ;
3192 const char* MeshFile = myBoundary->GetMeshFile() ;
3193 myDriver->TexteBoundaryDi( MeshName, MeshFile);
3194 if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
3196 // 2.2.2.1. Cas d une frontiere analytique
3199 NumBoundaryAnalytical++ ;
3200 HOMARD::double_array* coor = myBoundary->GetCoords();
3201 if (BoundaryType == 1) // Cas d un cylindre
3203 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3204 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3206 else if (BoundaryType == 2) // Cas d une sphere
3208 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
3209 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3211 else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
3213 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3214 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3216 else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
3218 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3219 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3221 else if (BoundaryType == 5) // Cas d un tore
3223 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3224 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3227 // 2.2.3. Memorisation du traitement
3228 ListeBoundaryTraitees.push_back( BoundaryName );
3231 // 3. Parcours des frontieres pour ecrire les liens avec les groupes
3232 NumBoundaryAnalytical = 0 ;
3233 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3235 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3236 MESSAGE ( "... BoundaryName = " << BoundaryName);
3237 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3238 ASSERT(!CORBA::is_nil(myBoundary));
3239 int BoundaryType = myBoundary->GetType();
3240 MESSAGE ( "... BoundaryType = " << BoundaryType );
3241 // 3.1. Recuperation du nom du groupe
3242 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
3243 MESSAGE ( "... GroupName = " << GroupName);
3244 // 3.2. Cas d une frontiere discrete
3245 if ( BoundaryType == 0 )
3247 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
3249 // 3.3. Cas d une frontiere analytique
3252 NumBoundaryAnalytical++ ;
3253 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
3256 // 4. Ecriture de l'option finale
3257 myDriver->TexteBoundaryOption(BoundaryOption);
3261 //=============================================================================
3262 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3263 //=============================================================================
3264 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3266 MESSAGE ( "... DriverTexteFieldInterp" );
3267 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3268 MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3269 if (TypeFieldInterp != 0)
3271 // Le fichier des champs
3272 char* FieldFile = myIteration->GetFieldFile();
3273 MESSAGE ( ". FieldFile = " << FieldFile );
3274 if (strlen(FieldFile) == 0)
3276 // GERALD -- QMESSAGE BOX
3277 VERIFICATION("The file for the field is not given." == 0);
3280 const char* MeshFile = myIteration->GetMeshFile();
3281 myDriver->TexteFieldInterp(FieldFile, MeshFile);
3284 // Interpolation de tous les champs
3285 if ( TypeFieldInterp == 1 )
3287 myDriver->TexteFieldInterpAll();
3289 // Interpolation de certains champs
3290 else if (TypeFieldInterp == 2)
3292 // Les champs et leurs instants pour l'iteration
3293 HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3294 int numberOfFieldsx3 = ListFieldTSR->length();
3295 MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3296 // Les champs pour l'hypothese
3297 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3298 int numberOfFieldsx2 = ListField->length();
3299 MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3300 // On parcourt tous les champs de l'hypothese
3302 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3305 std::string FieldName = std::string((*ListField)[iaux]) ;
3306 // Le type d'interpolation
3307 std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3308 MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3309 // On cherche à savoir si des instants ont été précisés pour cette itération
3311 for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3314 std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3315 MESSAGE( "..... FieldName2 = " << FieldName2 );
3316 // Quand c'est le bon champ, on ecrit le pas de temps
3317 if ( FieldName == FieldName2 )
3321 std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3322 // Le numero d'ordre
3323 std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3324 MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3326 int TimeStep = atoi( TimeStepstr.c_str() );
3327 int Rank = atoi( Rankstr.c_str() );
3328 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3332 // Si aucun instant n'a été défini
3336 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3344 //===========================================================================
3345 //===========================================================================
3348 //===========================================================================
3349 //===========================================================================
3351 //===========================================================================
3352 //===========================================================================
3353 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
3354 SALOMEDS::SObject_ptr theSObject,
3355 CORBA::Object_ptr theObject,
3356 const char* theName)
3358 MESSAGE("PublishInStudy pour " << theName);
3359 SALOMEDS::SObject_var aResultSO;
3360 if (CORBA::is_nil(theStudy))
3362 SALOME::ExceptionStruct es;
3363 es.type = SALOME::BAD_PARAM;
3364 es.text = "Invalid study context";
3365 throw SALOME::SALOME_Exception(es);
3369 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3370 // Rq : Iteration est publiee ailleurs
3371 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3372 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
3373 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3374 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3375 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3377 addInStudy(theStudy);
3379 // Controle de la non publication d'un objet de meme nom
3380 if ( (!aBoundary->_is_nil()) || (!aHypo->_is_nil()) || (!aYACS->_is_nil()) || (!aZone->_is_nil()) )
3382 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
3383 if (listSO->length() >= 1)
3385 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3386 aResultSO = listSO[0];
3387 return aResultSO._retn();
3391 // Caracteristiques de l'etude
3392 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
3393 aStudyBuilder->NewCommand();
3394 if(!aBoundary->_is_nil())
3395 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
3396 else if(!aCase->_is_nil())
3397 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
3398 else if(!aHypo->_is_nil())
3399 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
3400 else if(!aYACS->_is_nil())
3401 aResultSO = PublishYACSInStudy(theStudy, aStudyBuilder, aYACS, theName);
3402 else if(!aZone->_is_nil())
3403 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
3405 aStudyBuilder->CommitCommand();
3407 return aResultSO._retn();
3409 //=============================================================================
3410 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3411 SALOMEDS::StudyBuilder_var aStudyBuilder,
3412 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3414 MESSAGE("PublishBoundaryStudy pour "<<theName);
3415 SALOMEDS::SObject_var aResultSO;
3417 // Caracteristique de la Boundary
3418 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3420 // On recupere le module pere dans l etude
3421 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3422 if (theFatherHomard->_is_nil())
3424 MESSAGE("theFatherHomard->_is_nil()");
3425 return aResultSO._retn();
3428 // On ajoute la categorie des boundarys dans l etude si necessaire
3429 if ( _tag_boun == 0 )
3432 _tag_boun = _tag_gene ;
3434 MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3435 SALOMEDS::SObject_var aSObject;
3436 if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3438 MESSAGE("Ajout de la categorie des boundarys");
3439 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3440 PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3442 else { MESSAGE("La categorie des boundarys existe deja."); }
3444 CORBA::Long BoundaryType = myBoundary->GetType();
3445 // MESSAGE("BoundaryType : "<<BoundaryType);
3448 switch (BoundaryType)
3451 { value = "BoundaryDiHomard" ;
3452 icone = "mesh_tree_mesh.png" ;
3456 { value = "BoundaryAnHomard" ;
3457 icone = "cylinderpointvector_2.png" ;
3461 { value = "BoundaryAnHomard" ;
3462 icone = "spherepoint_2.png" ;
3466 { value = "BoundaryAnHomard" ;
3467 icone = "conepointvector.png" ;
3471 { value = "BoundaryAnHomard" ;
3472 icone = "conedxyz.png" ;
3476 { value = "BoundaryAnHomard" ;
3477 icone = "toruspointvector.png" ;
3481 aResultSO = aStudyBuilder->NewObject(aSObject);
3482 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3483 return aResultSO._retn();
3485 //=============================================================================
3486 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
3487 SALOMEDS::StudyBuilder_var aStudyBuilder,
3488 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3490 MESSAGE("PublishCaseInStudy pour "<<theName);
3491 SALOMEDS::SObject_var aResultSO;
3493 if (CORBA::is_nil(theObject)) {
3494 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3495 return aResultSO._retn();
3497 if (theStudy->_is_nil()) {
3498 MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
3499 return aResultSO._retn();
3502 // On recupere le module pere dans l etude
3503 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3504 if (theFatherHomard->_is_nil())
3506 MESSAGE("theFatherHomard->_is_nil()");
3507 return aResultSO._retn();
3511 MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3512 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3513 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3514 _orb->object_to_string(theObject) ) ;
3516 return aResultSO._retn();
3518 //=============================================================================
3519 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3520 SALOMEDS::StudyBuilder_var aStudyBuilder,
3521 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3523 MESSAGE("PublishHypotheseInStudy pour "<<theName);
3524 SALOMEDS::SObject_var aResultSO;
3526 // On recupere le module pere dans l etude
3527 // On ajoute la categorie des hypotheses dans l etude si necessaire
3528 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3529 if (theFatherHomard->_is_nil())
3531 MESSAGE("theFatherHomard->_is_nil()");
3532 return aResultSO._retn();
3535 // On ajoute la categorie des hypotheses dans l etude si necessaire
3536 SALOMEDS::SObject_var aSObject;
3537 if ( _tag_hypo == 0 )
3540 _tag_hypo = _tag_gene ;
3542 MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3543 if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3545 MESSAGE("Ajout de la categorie des hypotheses");
3546 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3547 PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3549 else { MESSAGE("La categorie des hypotheses existe deja."); }
3551 // Creation du resultat dans l'etude
3552 aResultSO = aStudyBuilder->NewObject(aSObject);
3553 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3555 return aResultSO._retn();
3557 //=============================================================================
3558 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::Study_ptr theStudy,
3559 SALOMEDS::StudyBuilder_var aStudyBuilder,
3560 HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3562 MESSAGE("PublishYACSInStudy pour "<<theName);
3563 SALOMEDS::SObject_var aResultSO;
3565 // On recupere le module pere dans l etude
3566 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3567 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3568 if (theFatherHomard->_is_nil())
3570 MESSAGE("theFatherHomard->_is_nil()");
3571 return aResultSO._retn();
3573 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3574 if ( _tag_yacs == 0 )
3577 _tag_yacs = _tag_gene ;
3579 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3580 SALOMEDS::SObject_var aSObject;
3581 if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3583 MESSAGE("Ajout de la categorie des schemas YACS");
3584 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3585 PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3587 else { MESSAGE("La categorie des schemas YACS existe deja."); }
3589 // Creation du resultat dans l'etude
3590 aResultSO = aStudyBuilder->NewObject(aSObject);
3591 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3593 return aResultSO._retn();
3596 //=============================================================================
3597 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
3598 SALOMEDS::StudyBuilder_var aStudyBuilder,
3599 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3601 MESSAGE("PublishZoneStudy pour "<<theName);
3602 SALOMEDS::SObject_var aResultSO;
3603 if (CORBA::is_nil(theObject))
3605 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3606 return aResultSO._retn();
3608 if (theStudy->_is_nil())
3610 MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3611 return aResultSO._retn();
3613 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3614 if (theFatherHomard->_is_nil())
3616 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3617 return aResultSO._retn();
3620 // Caracteristique de la zone
3621 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3622 CORBA::Long ZoneType = myZone->GetType();
3624 // On ajoute la categorie des zones dans l etude si necessaire
3625 if ( _tag_zone == 0 )
3628 _tag_zone = _tag_gene ;
3630 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3631 SALOMEDS::SObject_var aSObject;
3632 if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3634 MESSAGE("Ajout de la categorie des zones");
3635 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3636 PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3638 else { MESSAGE("La categorie des zones existe deja."); }
3640 aResultSO = aStudyBuilder->NewObject(aSObject);
3649 { icone = "boxdxy_2.png" ;
3653 { icone = "boxdxyz_2.png" ;
3661 { icone = "disk_2.png" ;
3665 { icone = "spherepoint_2.png" ;
3669 { icone = "cylinderpointvector_2.png" ;
3677 { icone = "diskwithhole_2.png" ;
3681 { icone = "pipe_2.png" ;
3685 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3687 return aResultSO._retn();
3689 //===========================================================================
3690 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3691 SALOMEDS::SObject_var aResultSO,
3692 const char* name, const char* comment, const char* icone, const char* ior)
3694 MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3695 // MESSAGE("icone = "<<icone);
3696 // MESSAGE("ior = "<<ior);
3697 SALOMEDS::GenericAttribute_var anAttr ;
3701 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3702 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3703 aNameAttrib->SetValue(name);
3706 // Ajout du commentaire
3707 if ( comment != NULL )
3709 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3710 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3711 aCommentAttrib->SetValue(comment);
3715 if ( icone != NULL )
3717 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3718 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3719 aPixmap->SetPixMap(icone);
3725 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3726 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3727 anIOR->SetValue(ior);
3731 //=====================================================================================
3732 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3734 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3736 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3737 ASSERT(!CORBA::is_nil(myCase));
3738 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3739 ASSERT(!CORBA::is_nil(aCaseSO));
3741 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3742 ASSERT(!CORBA::is_nil(myBoundary));
3743 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3744 ASSERT(!CORBA::is_nil(aBoundarySO));
3746 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3748 aStudyBuilder->NewCommand();
3750 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3751 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3752 // aStudyBuilder->RemoveReference(aSubSO);
3754 aStudyBuilder->CommitCommand();
3757 //=====================================================================================
3758 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3760 MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3762 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3763 ASSERT(!CORBA::is_nil(myYACS));
3764 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3765 ASSERT(!CORBA::is_nil(aYACSSO));
3767 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3768 ASSERT(!CORBA::is_nil(myCase));
3769 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3770 ASSERT(!CORBA::is_nil(aCaseSO));
3772 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3774 aStudyBuilder->NewCommand();
3776 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3777 aStudyBuilder->Addreference(aSubSO, aCaseSO);
3779 aStudyBuilder->CommitCommand();
3782 //=============================================================================
3783 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3784 // Option = 0 : fichier issu d'une importation
3785 // Option = 1 : fichier issu d'une execution HOMARD
3787 MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3788 if (CORBA::is_nil(myCurrentStudy))
3790 SALOME::ExceptionStruct es;
3791 es.type = SALOME::BAD_PARAM;
3792 es.text = "Invalid study context";
3793 throw SALOME::SALOME_Exception(es);
3797 // Le module SMESH est-il actif ?
3798 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3800 if (!CORBA::is_nil(aSmeshSO))
3802 // On verifie que le fichier n est pas deja publie
3803 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3804 for (; aIter->More(); aIter->Next())
3806 SALOMEDS::SObject_var aSO = aIter->Value();
3807 SALOMEDS::GenericAttribute_var aGAttr;
3808 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3810 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3811 CORBA::String_var value=anAttr->Value();
3812 if (strcmp((const char*)value,NomFich) == 0)
3814 MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3815 // Pour un fichier importe, on ne republie pas
3816 if ( Option == 0 ) { return; }
3817 // Pour un fichier calcule, on commence par faire la depublication
3820 MESSAGE ( "PublishResultInSmesh : depublication" );
3821 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3822 CORBA::String_var value2=anAttr2->Value();
3823 std::string MeshName = string(value2) ;
3824 MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3825 DeleteResultInSmesh(NomFich, MeshName) ;
3832 // On enregistre le fichier
3833 MESSAGE( "Enregistrement du fichier");
3834 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
3835 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
3836 ASSERT(!CORBA::is_nil(aSmeshEngine));
3837 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
3838 SMESH::DriverMED_ReadStatus theStatus;
3839 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3841 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
3842 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3843 for (int i = 0; i < mesMaillages->length(); i++)
3845 MESSAGE( ". Mise a jour des attributs du maillage");
3846 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
3847 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
3848 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3849 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
3850 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3851 anAttr->SetValue(NomFich);
3852 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
3853 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
3855 if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
3856 else { icone = "mesh_tree_mesh.png" ; }
3857 anAttr2->SetPixMap( icone );
3861 //=============================================================================
3862 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
3864 MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
3865 if (CORBA::is_nil(myCurrentStudy))
3867 SALOME::ExceptionStruct es;
3868 es.type = SALOME::BAD_PARAM;
3869 es.text = "Invalid study context";
3870 throw SALOME::SALOME_Exception(es);
3874 // Le module SMESH est-il actif ?
3875 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3877 if (CORBA::is_nil(aSmeshSO))
3881 // On verifie que le fichier est deja publie
3882 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
3883 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3884 for (; aIter->More(); aIter->Next())
3886 SALOMEDS::SObject_var aSO = aIter->Value();
3887 SALOMEDS::GenericAttribute_var aGAttr;
3888 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3890 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3891 CORBA::String_var value=anAttr->Value();
3892 if (strcmp((const char*)value,NomFich.c_str()) == 0)
3894 if (aSO->FindAttribute(aGAttr,"AttributeName"))
3896 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3897 CORBA::String_var value2=anAttr2->Value();
3898 if (strcmp((const char*)value2,MeshName.c_str()) == 0)
3900 myBuilder->RemoveObjectWithChildren( aSO ) ;
3908 //=============================================================================
3909 void HOMARD_Gen_i::PublishMeshIterInSmesh(const char* NomIter)
3911 MESSAGE( "PublishMeshIterInSmesh " << NomIter);
3912 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3914 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3915 if (CORBA::is_nil(myIteration))
3917 SALOME::ExceptionStruct es;
3918 es.type = SALOME::BAD_PARAM;
3919 es.text = "Invalid iterationStudy Object";
3920 throw SALOME::SALOME_Exception(es);
3923 const char* MeshFile = myIteration->GetMeshFile() ;
3924 const char* MeshName = myIteration->GetMeshName() ;
3925 CORBA::Long Option = -1 ;
3926 int etat = myIteration->GetState();
3927 // Iteration initiale
3928 if ( etat <= 0 ) { Option = 0 ; }
3929 // ou iteration calculee
3930 else if ( etat == 2 ) { Option = 1 ; }
3931 // Publication effective apres menage eventuel
3934 DeleteResultInSmesh(MeshFile, MeshName) ;
3935 PublishResultInSmesh(MeshFile, Option) ;
3939 //=============================================================================
3940 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
3942 // MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3943 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3945 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3946 if (CORBA::is_nil(myIteration))
3948 SALOME::ExceptionStruct es;
3949 es.type = SALOME::BAD_PARAM;
3950 es.text = "Invalid iterationStudy Object";
3951 throw SALOME::SALOME_Exception(es);
3955 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3957 aStudyBuilder->NewCommand();
3959 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
3960 // Pour les fichiers med, on affiche une icone de maillage
3961 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
3962 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
3964 std::string ior = " " ;
3965 if ( Commentaire[0] == 'I' )
3966 { icone = "med.png" ; }
3968 { icone = "texte_2.png" ; }
3969 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3971 aStudyBuilder->CommitCommand();
3974 //=============================================================================
3975 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
3977 // MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3978 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3980 SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3981 if (CORBA::is_nil(myYACS))
3983 SALOME::ExceptionStruct es;
3984 es.type = SALOME::BAD_PARAM;
3985 es.text = "Invalid YACSStudy Object";
3986 throw SALOME::SALOME_Exception(es);
3990 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3992 aStudyBuilder->NewCommand();
3994 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3995 std::string icone = "texte_2.png" ;
3996 std::string ior = " " ;
3997 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3999 aStudyBuilder->CommitCommand();
4002 //=============================================================================
4003 //=============================================================================
4005 //=============================================================================
4006 //=============================================================================
4007 //=============================================================================
4008 // Creation d'un schema YACS
4009 // nomCas : nom du cas a traiter
4010 // FileName : nom du fichier contenant le script de lancement du calcul
4011 // DirName : le repertoire de lancement des calculs du schéma
4012 //=============================================================================
4013 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
4015 INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
4016 INFOS ( ". nomCas : " << nomCas);
4017 INFOS ( ". ScriptFile : " << ScriptFile);
4018 INFOS ( ". DirName : " << DirName);
4019 INFOS ( ". MeshFile : " << MeshFile);
4021 // A. Controle du nom :
4022 if ((myContextMap[GetCurrentStudyID()]._mesYACSs).find(nomYACS) != (myContextMap[GetCurrentStudyID()]._mesYACSs).end())
4024 SALOME::ExceptionStruct es;
4025 es.type = SALOME::BAD_PARAM;
4026 es.text = "This schema YACS has already been defined.";
4027 throw SALOME::SALOME_Exception(es);
4031 // B. Creation de l'objet
4032 HOMARD::HOMARD_YACS_var myYACS = newYACS();
4033 if (CORBA::is_nil(myYACS))
4035 SALOME::ExceptionStruct es;
4036 es.type = SALOME::BAD_PARAM;
4037 es.text = "Unable to create the schema YACS";
4038 throw SALOME::SALOME_Exception(es);
4041 myYACS->SetName( nomYACS ) ;
4043 // C. Enregistrement
4044 myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS] = myYACS;
4046 SALOMEDS::SObject_var aSO;
4047 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myYACS, nomYACS);
4049 PublishCaseUnderYACS(nomYACS, nomCas);
4051 // D. Caracterisation
4053 myYACS->SetDirName( DirName ) ;
4054 myYACS->SetMeshFile( MeshFile ) ;
4055 myYACS->SetScriptFile( ScriptFile ) ;
4056 myYACS->SetCaseName( nomCas ) ;
4059 // D.2.1. Type constant
4060 myYACS->SetType( 1 ) ;
4061 // D.2.2. Convergence
4062 defaut_i = GetYACSMaxIter() ;
4063 myYACS->SetMaxIter( defaut_i ) ;
4064 defaut_i = GetYACSMaxNode() ;
4065 myYACS->SetMaxNode( defaut_i ) ;
4066 defaut_i = GetYACSMaxElem() ;
4067 myYACS->SetMaxElem( defaut_i ) ;
4068 // D.3. Fichier de sauvegarde dans le repertoire du cas
4069 HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
4070 std::string dirnamecase = caseyacs->GetDirName() ;
4071 std::string XMLFile ;
4072 XMLFile = dirnamecase + "/schema.xml" ;
4073 myYACS->SetXMLFile( XMLFile.c_str() ) ;
4075 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
4077 //=============================================================================
4078 // Ecriture d'un schema YACS
4079 //=============================================================================
4080 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
4082 INFOS ( "YACSWrite : Ecriture de " << nomYACS );
4083 // Le repertoire du cas
4084 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4085 ASSERT(!CORBA::is_nil(myYACS));
4086 // Le nom du fichier du schema
4087 std::string XMLFile ;
4088 XMLFile = myYACS->GetXMLFile() ;
4090 int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
4094 //=============================================================================
4095 // Ecriture d'un schema YACS sur un fichier donne
4096 //=============================================================================
4097 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
4099 INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
4106 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4107 ASSERT(!CORBA::is_nil(myYACS));
4108 // B.2. Les caracteristiques
4109 std::string DirName = myYACS->GetDirName() ;
4110 std::string MeshFile = myYACS->GetMeshFile() ;
4111 std::string ScriptFile = myYACS->GetScriptFile() ;
4112 // B.3. Les caracteristiques de convergence
4113 int MaxIter = myYACS->GetMaxIter() ;
4114 int MaxNode = myYACS->GetMaxNode() ;
4115 int MaxElem = myYACS->GetMaxElem() ;
4119 const char* nomCas = myYACS->GetCaseName();
4120 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
4121 ASSERT(!CORBA::is_nil(myCase));
4122 // C.2. Les instructions python associees au cas
4123 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4124 std::string pythonCas = dumpCorbaCase.in();
4125 MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
4127 // D. Les iterations
4128 // D.1. L'iteration initiale
4129 HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
4130 std::string Iter0Name = myCase->GetIter0Name() ;
4131 MESSAGE (". Iter0Name = " << Iter0Name);
4132 std::string MeshName = Iter0->GetMeshName();
4133 MESSAGE (". MeshName = " << MeshName);
4134 // D.2. L'iteration numero 1
4135 HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
4136 int numberOfIter = maListe->length();
4137 if ( numberOfIter > 1 )
4139 MESSAGE (". numberOfIter = " << numberOfIter);
4140 SALOME::ExceptionStruct es ;
4141 es.type = SALOME::BAD_PARAM;
4142 std::string text = "Une seule iteration est permise." ;
4143 es.text = CORBA::string_dup(text.c_str());
4144 throw SALOME::SALOME_Exception(es);
4147 std::string Iter1Name = std::string((*maListe)[0]);
4148 MESSAGE ("... Iter1Name = " << Iter1Name);
4149 HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
4150 // D.3. Les instructions python associees a l'iteration
4151 CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
4152 std::string pythonIter = dumpCorbaIter.in();
4153 MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
4155 // E. L'hypothese pour passer de l'iteration initiale a la suivante
4156 // E.1. La structure
4157 std::string nomHypo = Iter1->GetHypoName();
4158 MESSAGE (". nomHypo = " << nomHypo);
4159 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
4160 ASSERT(!CORBA::is_nil(myHypo));
4161 // E.2. Les caracteristiques de l'adaptation
4162 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
4163 ASSERT(ListTypes->length() == 3);
4164 int TypeAdap = (*ListTypes)[0];
4165 // int TypeRaff = (*ListTypes)[1];
4166 // int TypeDera = (*ListTypes)[2];
4167 // E.3. Les instructions python associees a l'hypothese
4168 CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
4169 std::string pythonHypo = dumpCorbaHypo.in();
4170 MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
4172 // F. Le fichier du schema de reference
4173 // HOMARD_ROOT_DIR : repertoire ou se trouve le module HOMARD
4174 std::string XMLFile_base ;
4175 if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
4178 SALOME::ExceptionStruct es ;
4179 es.type = SALOME::BAD_PARAM;
4180 std::string text = "HOMARD_ROOT_DIR est inconnu." ;
4181 es.text = CORBA::string_dup(text.c_str());
4182 throw SALOME::SALOME_Exception(es);
4185 XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
4187 MESSAGE("XMLFile_base ="<<XMLFile_base);
4189 // G. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4190 YACSDriver* myDriver = new YACSDriver(XMLFile, DirName);
4191 std::ifstream fichier( XMLFile_base.c_str() );
4192 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
4194 // G.1. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4195 std::string ligne; // variable contenant chaque ligne lue
4196 std::string mot_cle;
4197 while ( std::getline( fichier, ligne ) )
4199 // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
4200 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
4201 ligne_bis >> mot_cle ;
4202 // G.1.2. Le maillage initial
4203 if ( mot_cle == "DataInit_MeshFile" )
4204 { myDriver->Texte_DataInit_MeshFile(MeshFile); }
4205 // G.1.3. Le script de lancement
4206 else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
4207 { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
4208 // G.1.4. Les options du cas
4209 else if ( mot_cle == "Iter_1_Case_Options" )
4210 { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
4211 // G.1.5. Execution de HOMARD : le repertoire du cas
4212 else if ( mot_cle == "HOMARD_Exec_DirName" )
4213 { myDriver->Texte_HOMARD_Exec_DirName(); }
4214 // G.1.6. Execution de HOMARD : le nom du maillage
4215 else if ( mot_cle == "HOMARD_Exec_MeshName" )
4217 myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
4218 std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
4219 myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
4221 // G.1.7. Execution de HOMARD : les options de l'hypothese
4222 else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
4223 { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ; }
4224 // G.1.8. Execution de HOMARD : les options de l'iteration
4225 else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
4226 { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ; }
4227 // G.1.9. Zones et frontieres : les creations
4228 else if ( mot_cle == "Iter_1" )
4230 std::string texte_control = myDriver->Texte_Iter_1_control() ;
4231 if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
4232 texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
4233 myDriver->TexteAdd(texte_control);
4235 // G.1.10. Les tests de convergence
4236 else if ( mot_cle == "Analyse_Test_Convergence" )
4237 { myDriver->TexteAnalyse_Test_Convergence(MaxIter, MaxNode, MaxElem); }
4238 // G.1.11. Les parametres
4239 else if ( mot_cle == "PARAMETRES" )
4240 { myDriver->TexteAddParametres(); }
4241 // G.1.n. La ligne est recopiee telle quelle
4242 else { myDriver->TexteAdd(ligne); }
4244 // G.2. Ecriture du texte dans le fichier
4246 { myDriver->CreeFichier(); }
4250 SALOME::ExceptionStruct es;
4251 es.type = SALOME::BAD_PARAM;
4252 std::string text = "The reference file for the YACS schema cannot be read." ;
4253 es.text = CORBA::string_dup(text.c_str());
4254 throw SALOME::SALOME_Exception(es);
4259 // H. Publication du fichier dans l'arbre
4261 std::string Commentaire = "xml" ;
4262 PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
4266 //=============================================================================
4267 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
4268 //=============================================================================
4269 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
4271 MESSAGE ( "YACSDriverTexteZone" );
4272 // A. Les zones associees a cette hypothese
4273 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
4274 int numberOfZonesx2 = ListZone->length();
4276 // B. Parcours des zones
4277 std::string texte_control ;
4278 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
4280 // 1. Reperage de la zone
4281 std::string ZoneName = std::string((*ListZone)[iaux]);
4282 MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
4283 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
4284 ASSERT(!CORBA::is_nil(myZone));
4285 // 2. Les instructions python associees a la zone
4286 // La premiere ligne est un commentaire a eliminer
4287 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4288 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4289 std::string pythonStructure_0 = dumpCorbaZone.in();
4290 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4291 std::istringstream tout (pythonStructure_0) ;
4293 std::string pythonStructure ;
4294 while ( std::getline( tout, ligne ) )
4295 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4296 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4297 // 3. Decodage du nom du service
4298 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4299 MESSAGE ( "... methode = " << methode);
4300 // 4. Mise en place des instructions
4301 int ZoneType = myZone->GetType();
4302 MESSAGE ( "... ZoneType = " << ZoneType);
4303 std::string texte_control_0 ;
4304 texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
4305 texte_control += texte_control_0 ;
4310 return texte_control ;
4312 //=============================================================================
4313 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4314 //=============================================================================
4315 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4317 MESSAGE ( "YACSDriverTexteBoundary" );
4318 // A. Les frontieres associees au cas
4319 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4320 int numberOfitems = ListBoundaryGroupType->length();
4322 // B. Parcours des frontieres
4323 std::string texte_control ;
4324 std::list<std::string> ListeBoundaryTraitees ;
4325 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4327 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4328 MESSAGE ( "... BoundaryName = " << BoundaryName);
4329 // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4330 // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4332 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4333 while (it != ListeBoundaryTraitees.end())
4335 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4336 if ( BoundaryName == *it ) { A_faire = 0 ; }
4341 // 1. Caracteristiques de la frontiere
4342 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
4343 ASSERT(!CORBA::is_nil(myBoundary));
4344 // 2. Les instructions python associees a la frontiere
4345 // La premiere ligne est un commentaire a eliminer
4346 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4347 CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4348 std::string pythonStructure_0 = dumpCorbaBoundary.in();
4349 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4350 std::istringstream tout (pythonStructure_0) ;
4352 std::string pythonStructure ;
4353 while ( std::getline( tout, ligne ) )
4354 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4355 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4356 // 3. Decodage du nom du service
4357 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4358 MESSAGE ( "... methode = " << methode);
4359 // 4. Mise en place des instructions
4360 int BoundaryType = myBoundary->GetType();
4361 MESSAGE ( "... BoundaryType = " << BoundaryType);
4362 std::string texte_control_0 ;
4363 texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName );
4364 texte_control += texte_control_0 ;
4365 // 5. Memorisation du traitement
4366 ListeBoundaryTraitees.push_back( BoundaryName );
4370 return texte_control ;
4373 //=============================================================================
4374 //=============================================================================
4375 // Next functions are inherited from SALOMEDS::Driver interface
4376 //=============================================================================
4377 //=============================================================================
4378 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4380 CORBA::Boolean isMultiFile)
4382 MESSAGE ("Save for theURL = "<< theURL);
4383 SALOMEDS::TMPFile_var aStreamFile;
4385 // get temporary directory name
4386 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4388 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4389 StudyContext& context = myContextMap[ aStudy->StudyId() ];
4391 // HOMARD data file name
4392 std::string aFileName = "";
4394 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4395 aFileName += "_HOMARD.dat";
4397 // initialize sequence of file names
4398 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
4399 aFileSeq->length(1);
4400 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
4402 // get full path to the data file
4403 aFileName = tmpDir + aFileName;
4407 std::ofstream f(aFileName.c_str());
4409 // clear temporary id map
4410 context._idmap.clear();
4415 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4416 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4417 HOMARD::HOMARD_Cas_var aCas = it_case->second;
4418 PortableServer::ServantBase_var aServant = GetServant(aCas);
4419 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4421 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4422 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4426 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4427 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4428 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4429 PortableServer::ServantBase_var aServant = GetServant(aZone);
4430 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4432 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4433 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4436 // -> save hypotheses
4437 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4438 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4439 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4440 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4441 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4443 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4444 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4447 // -> save iterations
4448 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4449 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4450 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4451 PortableServer::ServantBase_var aServant = GetServant(aIter);
4452 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4454 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4455 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4458 // -> save boundaries
4459 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4460 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4461 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4462 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4463 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4464 if (aBoundaryServant) {
4465 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4466 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4470 MESSAGE ("close file");
4473 // put temporary files to the stream
4474 MESSAGE ("put temporary files to the stream");
4475 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
4477 // remove temporary files
4478 MESSAGE ("remove temporary files");
4479 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4481 // return data stream
4482 MESSAGE ("return data stream");
4483 return aStreamFile._retn();
4486 //===========================================================================
4487 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4489 CORBA::Boolean isMultiFile)
4491 // No specific ASCII persistence
4492 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4493 return aStreamFile._retn();
4496 //===========================================================================
4497 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4498 const SALOMEDS::TMPFile& theStream,
4500 CORBA::Boolean isMultiFile)
4502 MESSAGE ("Load pour theURL = "<< theURL);
4503 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4505 // set current study
4506 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
4507 SetCurrentStudy(aStudy);
4509 // get temporary directory name
4510 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4512 // Convert the stream into sequence of files to process
4513 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4516 // HOMARD data file name
4517 std::string aFileName = "";
4519 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4520 aFileName = tmpDir + aFileName + "_HOMARD.dat";
4522 StudyContext& context = myContextMap[ aStudy->StudyId() ];
4526 std::ifstream f(aFileName.c_str());
4529 context._mesCas.clear();
4530 context._mesHypotheses.clear();
4531 context._mesIterations.clear();
4532 context._mesZones.clear();
4533 context._mesBoundarys.clear();
4534 context._idmap.clear();
4540 std::getline(f, line);
4541 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4542 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4543 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4544 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4545 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4546 std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4547 if (line.substr(0, bounSignature.size()) == bounSignature) {
4548 // re-create boundary
4549 MESSAGE ("Recreation de la frontiere" );
4550 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4551 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4552 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4553 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4554 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4555 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4558 else if (line.substr(0, caseSignature.size()) == caseSignature) {
4560 MESSAGE ("Recreation du cas" );
4561 HOMARD::HOMARD_Cas_var aCase = newCase();
4562 PortableServer::ServantBase_var aServant = GetServant(aCase);
4563 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4564 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4565 context._mesCas[aCase->GetName()] = aCase;
4566 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4569 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4570 // re-create hypothesis
4571 MESSAGE ("Recreation de l hypothese" );
4572 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4573 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4574 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4575 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4576 context._mesHypotheses[aHypo->GetName()] = aHypo;
4577 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4580 else if (line.substr(0, iterSignature.size()) == iterSignature) {
4581 // re-create iteration
4582 MESSAGE ("Recreation de l'iteration" );
4583 HOMARD::HOMARD_Iteration_var aIter = newIteration();
4584 PortableServer::ServantBase_var aServant = GetServant(aIter);
4585 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4586 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4587 context._mesIterations[aIter->GetName()] = aIter;
4588 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4591 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4592 MESSAGE ("Recreation de la zone" );
4594 HOMARD::HOMARD_Zone_var aZone = newZone();
4595 PortableServer::ServantBase_var aServant = GetServant(aZone);
4596 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4597 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4598 context._mesZones[aZone->GetName()] = aZone;
4599 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4602 else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4603 MESSAGE ("Recreation du schema YACS" );
4605 HOMARD::HOMARD_YACS_var aYACS = newYACS();
4606 PortableServer::ServantBase_var aServant = GetServant(aYACS);
4607 HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4608 if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4609 context._mesYACSs[aYACS->GetName()] = aYACS;
4610 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4619 // Remove temporary files created from the stream
4621 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4626 //===========================================================================
4627 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4628 const SALOMEDS::TMPFile& theStream,
4630 CORBA::Boolean isMultiFile)
4632 // No specific ASCII persistence
4633 return Load(theComponent, theStream, theURL, isMultiFile);
4636 //===========================================================================
4637 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4639 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
4640 // clearing study context should be done here:
4641 // - destroy all servants and related CORBA objects
4643 // - remove context from myContextMap
4644 myContextMap.erase(theComponent->GetStudy()->StudyId());
4645 // - nullify myCurrentStudy
4646 myCurrentStudy = SALOMEDS::Study::_nil();
4650 //===========================================================================
4651 char* HOMARD_Gen_i::ComponentDataType()
4653 return CORBA::string_dup("HOMARD");
4656 //===========================================================================
4657 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4658 const char* IORString,
4659 CORBA::Boolean isMultiFile,
4660 CORBA::Boolean isASCII)
4662 CORBA::String_var aString("");
4663 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4664 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4665 CORBA::Object_var anObj = _orb->string_to_object(IORString);
4666 if (!CORBA::is_nil(anObj)) {
4667 PortableServer::ServantBase_var aServant = GetServant(anObj);
4668 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4670 std::map<int, PortableServer::ServantBase*>::const_iterator it;
4671 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4672 if (it->second == aStorable) {
4673 std::stringstream os;
4675 aString = CORBA::string_dup(os.str().c_str());
4681 return aString._retn();
4684 //===========================================================================
4685 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4686 const char* aLocalPersistentID,
4687 CORBA::Boolean isMultiFile,
4688 CORBA::Boolean isASCII)
4690 CORBA::String_var aString("");
4691 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4692 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4693 int id = atoi(aLocalPersistentID);
4694 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4695 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4696 if (!CORBA::is_nil(object)) {
4697 aString = _orb->object_to_string(object);
4701 return aString._retn();
4704 //===========================================================================
4705 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4707 if(CORBA::is_nil(myCurrentStudy))
4710 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4711 if(!aCas->_is_nil())
4714 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4715 if(!aHypo->_is_nil())
4718 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4719 if(!aZone->_is_nil())
4722 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4723 if(!aBoundary->_is_nil())
4726 /* Iteration is not published directly
4727 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4728 if(!aIter->_is_nil())
4734 //===========================================================================
4735 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4737 // No Copy/Paste support
4741 //===========================================================================
4742 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4743 CORBA::Long& theObjectID)
4745 // No Copy/Paste support
4746 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4747 return aStreamFile._retn();
4750 //===========================================================================
4751 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
4752 CORBA::Long theObjectID)
4754 // No Copy/Paste support
4758 //===========================================================================
4759 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4760 CORBA::Long theObjectID,
4761 SALOMEDS::SObject_ptr theSObject)
4763 // No Copy/Paste support
4764 SALOMEDS::SObject_var aResultSO;
4765 return aResultSO._retn();
4768 //===========================================================================
4769 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4771 PortableServer::Servant aServant = 0;
4772 if (!CORBA::is_nil(theObject)) {
4774 aServant = _poa->reference_to_servant(theObject);
4782 //==========================================================================
4783 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4784 CORBA::Boolean isPublished,
4785 CORBA::Boolean isMultiFile,
4786 CORBA::Boolean& isValidScript)
4788 MESSAGE ("Entree dans DumpPython");
4790 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
4791 if(CORBA::is_nil(aStudy))
4792 return new Engines::TMPFile(0);
4794 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
4795 if(CORBA::is_nil(aSO))
4796 return new Engines::TMPFile(0);
4798 std::string aScript = "\"\"\"\n";
4799 aScript += "Python script for HOMARD\n";
4800 aScript += "Copyright EDF-R&D 1996, 2011, 2014\n";
4801 aScript += "\"\"\"\n";
4802 aScript += "__revision__ = \"V1.2\"\n";
4803 aScript += "import HOMARD\n";
4805 aScript += "import salome\n";
4806 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4808 aScript += "def RebuildData(theStudy):\n";
4809 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
4812 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
4813 MESSAGE (". Au depart \n"<<aScript);
4816 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
4818 MESSAGE (". Ecritures des frontieres");
4819 aScript += "#\n# Creation of the boundaries";
4820 aScript += "\n# ==========================";
4822 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4823 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
4824 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
4826 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4827 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4828 std::string dumpBoundary = dumpCorbaBoundary.in();
4829 MESSAGE (dumpBoundary<<"\n");
4830 aScript += dumpBoundary;
4834 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
4836 MESSAGE (". Ecritures des zones");
4837 aScript += "#\n# Creation of the zones";
4838 aScript += "\n# =====================";
4840 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4841 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
4842 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
4844 HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
4845 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4846 std::string dumpZone = dumpCorbaZone.in();
4847 MESSAGE (dumpZone<<"\n");
4848 aScript += dumpZone;
4852 if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
4854 MESSAGE (". Ecritures des hypotheses");
4855 aScript += "#\n# Creation of the hypotheses";
4856 aScript += "\n# ==========================";
4858 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4859 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
4860 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
4862 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
4863 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
4864 std::string dumpHypo = dumpCorbaHypo.in();
4865 MESSAGE (dumpHypo<<"\n");
4866 aScript += dumpHypo;
4870 if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
4872 MESSAGE (". Ecritures des cas");
4873 aScript += "#\n# Creation of the cases";
4874 aScript += "\n# =====================";
4876 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
4877 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4878 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
4880 std::string nomCas = (*it_cas).first;
4881 std::string dumpCas = std::string("\n# Creation of the case ") ;
4882 dumpCas += nomCas + std::string("\n");
4883 dumpCas += std::string("\t") + nomCas;
4884 dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
4886 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
4887 CORBA::String_var cIter0= myCase->GetIter0Name();
4888 std::string iter0 = cIter0.in();
4890 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
4891 CORBA::String_var cMesh0= myIteration->GetMeshFile();
4892 std::string mesh0 = cMesh0.in();
4893 CORBA::String_var cMeshName0= myIteration->GetMeshName();
4894 std::string meshName0 = cMeshName0.in();
4895 dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
4896 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4897 std::string dumpCas2= dumpCorbaCase.in();
4899 MESSAGE (dumpCas<<dumpCas2<<"\n");
4900 aScript += dumpCas + dumpCas2;
4904 if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
4906 MESSAGE (". Ecritures des iterations");
4907 aScript += "#\n# Creation of the iterations" ;
4908 aScript += "\n# ==========================";
4910 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4911 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
4912 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
4914 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
4915 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
4916 std::string dumpIter = dumpCorbaIter.in();
4917 MESSAGE (dumpIter<<"\n");
4918 aScript += dumpIter;
4922 if (myContextMap[GetCurrentStudyID()]._mesYACSs.size() > 0)
4924 MESSAGE (". Ecritures des schemas YACS");
4925 aScript += "#\n# Creation of the schemas YACS";
4926 aScript += "\n# ============================";
4928 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
4929 for ( it_yacs = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
4930 it_yacs != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); ++it_yacs)
4932 HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
4933 CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
4934 std::string dumpYACS = dumpCorbaYACS.in();
4935 MESSAGE (dumpYACS<<"\n");
4936 aScript += dumpYACS;
4939 MESSAGE (". Ecritures finales");
4941 aScript += "\n\tpass";
4944 if( !isMultiFile ) // remove unnecessary tabulation
4945 aScript = RemoveTabulation( aScript );
4947 // MESSAGE ("A ecrire \n"<<aScript);
4948 const size_t aLen = strlen(aScript.c_str());
4949 char* aBuffer = new char[aLen+1];
4950 strcpy(aBuffer, aScript.c_str());
4952 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
4953 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
4955 MESSAGE ("Sortie de DumpPython");
4956 return aStreamFile._retn();
4960 //=============================================================================
4961 //=============================================================================
4963 //=============================================================================
4964 //=============================================================================
4965 void HOMARD_Gen_i::IsValidStudy( )
4967 // MESSAGE( "IsValidStudy" );
4968 if (CORBA::is_nil(myCurrentStudy))
4970 SALOME::ExceptionStruct es;
4971 es.type = SALOME::BAD_PARAM;
4972 es.text = "Invalid study context";
4973 throw SALOME::SALOME_Exception(es);
4978 //=============================================================================
4979 char* HOMARD_Gen_i::VerifieDir(const char* nomDir)
4981 std::string casename = std::string("") ;
4982 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
4983 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4984 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
4986 if (std::string(nomDir) == std::string(it->second->GetDirName()))
4988 casename = std::string(it->second->GetName()) ;
4992 return CORBA::string_dup( casename.c_str() );
4994 /*//=============================================================================
4995 void SALOMEException( std::string message )
4997 SALOME::ExceptionStruct es;
4998 es.type = SALOME::BAD_PARAM;
5000 throw SALOME::SALOME_Exception(es);
5003 //=============================================================================
5004 char* HOMARD_Gen_i::getVersion()
5006 #if HOMARD_DEVELOPMENT
5007 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
5009 return CORBA::string_dup(HOMARD_VERSION_STR);
5012 //===============================================================================
5013 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un caractere
5014 // ligne : la ligne a manipuler
5015 // caractere : le caractere a reperer
5016 // option : 0 : la chaine avant la premiere apparition du caractere
5017 // 1 : la chaine apres la premiere apparition du caractere
5018 // 2 : la chaine avant la derniere apparition du caractere
5019 // 3 : la chaine apres la derniere apparition du caractere
5020 // Si le caractere est absent, on retourne la chaine totale
5021 //===============================================================================
5022 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string caractere, int option )
5024 // MESSAGE("GetStringInTexte, recherche de '"<<caractere<<"' dans '"<<ligne<<"'"<<", option = "<<option);
5026 std::string chaine = ligne ;
5028 if ( option < 2 ) { position = ligne.find_first_of( caractere ) ; }
5029 else { position = ligne.find_last_of( caractere ) ; }
5030 // MESSAGE("position = "<<position);
5031 // MESSAGE("a = "<<ligne.substr( 0, position ).c_str());
5032 // MESSAGE("b = "<<ligne.substr( position+1 ).c_str());
5034 if ( position != std::string::npos )
5036 if ( ( option == 0 ) || ( option == 2 ) ) { chaine = ligne.substr( 0, position ) ; }
5037 else { chaine = ligne.substr( position+1 ) ; }
5042 //=============================================================================
5043 //=============================================================================
5044 // Gestion des preferences
5045 //=============================================================================
5046 //=============================================================================
5047 // Decodage du fichier d'arcihvage des preferences
5049 void HOMARD_Gen_i::SetPreferences( )
5051 MESSAGE ( "SetPreferences" );
5053 std::string ligne, mot_cle, salome_version ;
5056 // A. Les valeurs par defaut ; elles doivent etre coherentes
5057 std::string LanguageShort = "en" ;
5058 int PublisMeshIN = 0 ;
5059 int PublisMeshOUT = 0 ;
5060 int YACSMaxIter = 0 ;
5061 int YACSMaxNode = 0 ;
5062 int YACSMaxElem = 0 ;
5064 // B. La version de salome
5065 // Cela se presente sous la forme :
5066 // [SALOME KERNEL] : 7.3.0
5068 File = getenv("KERNEL_ROOT_DIR") ;
5069 File += "/bin/salome/VERSION" ;
5070 MESSAGE ( "File = "<<File ) ;
5071 std::ifstream fichier0( File.c_str() ) ;
5072 if ( fichier0 ) // ce test échoue si le fichier n'est pas ouvert
5074 std::string ligne; // variable contenant chaque ligne lue
5075 while ( std::getline( fichier0, ligne ) )
5077 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5078 ligne_bis >> mot_cle ;
5079 if ( mot_cle == "[SALOME" )
5081 salome_version = GetStringInTexte ( ligne, " ", 3 ) ;
5082 // MESSAGE ( "salome_version = "<<salome_version<<"|||");
5087 else { ok = false ; }
5089 // B. Decodage du fichier de preferences
5092 std::string PrefFile ;
5093 PrefFile = getenv("HOME") ;
5094 PrefFile += "/.config/salome/SalomeApprc." + salome_version ;
5095 MESSAGE ( "PrefFile = "<<PrefFile ) ;
5097 std::ifstream fichier( PrefFile.c_str() );
5098 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
5100 bool section_langue = false ;
5101 bool section_homard = false ;
5102 while ( std::getline( fichier, ligne ) )
5104 std::string chaine ;
5105 // 1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
5106 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5107 ligne_bis >> mot_cle ;
5110 // 2.1. Debut d'une section
5111 // MESSAGE(mot_cle);
5112 if ( mot_cle == "<section" )
5113 { /*MESSAGE ( "Debut de la section : "<< ligne);*/
5114 ligne_bis >> mot_cle ;
5115 chaine = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5116 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5117 if ( chaine == "language" ) { section_langue = true ; }
5118 if ( chaine == "HOMARD" ) { section_homard = true ; }
5119 // MESSAGE ( "section_langue = "<<section_langue<<", section_homard = "<<section_homard);
5121 // 2.2. Fin d'une section
5122 else if ( mot_cle == "</section>" )
5123 { /*MESSAGE ( "Fin de la section : "<< ligne<<", section_langue = "<<section_langue<<", section_homard = "<<section_homard);*/
5124 section_langue = false ;
5125 section_homard = false ; }
5129 else if ( section_langue || section_homard )
5130 { /*MESSAGE ( "a decoder : "<< ligne);*/
5131 ligne_bis >> mot_cle ;
5132 chaine = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5133 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5134 // MESSAGE("chaine = "<<chaine<<"|");
5135 ligne_bis >> mot_cle ;
5136 std::string chaine2 = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5137 chaine2 = GetStringInTexte ( chaine2, "\"", 0 ) ;
5138 MESSAGE("chaine2 = "<<chaine2<<"|");
5140 if ( section_langue )
5141 { if ( chaine2 == "language" ) { LanguageShort = chaine ; } }
5143 if ( section_homard )
5145 std::istringstream chainebis( chaine ) ;
5146 // 3.2.1. Les publications
5147 if ( chaine2 == "publish_mesh_in" ) { chainebis >> PublisMeshIN ; }
5148 if ( chaine2 == "publish_mesh_out" ) { chainebis >> PublisMeshOUT ; }
5149 // 3.2.2. Les maximum pour YACS
5150 if ( chaine2 == "yacs_max_iter" ) { chainebis >> YACSMaxIter ; }
5151 if ( chaine2 == "yacs_max_node" ) { chainebis >> YACSMaxNode ; }
5152 if ( chaine2 == "yacs_max_elem" ) { chainebis >> YACSMaxElem ; }
5159 // C. Enregistrement
5160 MESSAGE ("Enregistrement de LanguageShort = " << LanguageShort );
5161 MESSAGE ("Enregistrement de PublisMeshIN = " << PublisMeshIN<<", PublisMeshOUT = "<< PublisMeshOUT);
5162 MESSAGE ("Enregistrement de YACSMaxIter = " << YACSMaxIter<<", YACSMaxNode = "<< YACSMaxNode<<", YACSMaxElem = "<< YACSMaxElem);
5163 SetLanguageShort( LanguageShort.c_str() ) ;
5164 SetPublisMesh(PublisMeshIN, PublisMeshOUT) ;
5165 SetYACSMaximum(YACSMaxIter, YACSMaxNode, YACSMaxElem) ;
5169 //===============================================================================
5171 //===============================================================================
5172 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
5174 // MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
5175 _LangueShort = LanguageShort ;
5176 if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
5177 else { _Langue = "English" ; }
5180 char* HOMARD_Gen_i::GetLanguageShort()
5182 // MESSAGE ("GetLanguageShort");
5183 return CORBA::string_dup( _LangueShort.c_str() );
5185 //===============================================================================
5186 // Options de publications
5187 //===============================================================================
5188 void HOMARD_Gen_i::SetPublisMesh(CORBA::Long PublisMeshIN, CORBA::Long PublisMeshOUT)
5190 _PublisMeshIN = PublisMeshIN ;
5191 _PublisMeshOUT = PublisMeshOUT ;
5194 CORBA::Long HOMARD_Gen_i::GetPublisMeshIN()
5196 return _PublisMeshIN ;
5198 CORBA::Long HOMARD_Gen_i::GetPublisMeshOUT()
5200 return _PublisMeshOUT ;
5202 //===============================================================================
5204 //===============================================================================
5205 void HOMARD_Gen_i::SetYACSMaximum(CORBA::Long YACSMaxIter, CORBA::Long YACSMaxNode, CORBA::Long YACSMaxElem)
5207 _YACSMaxIter = YACSMaxIter ;
5208 _YACSMaxNode = YACSMaxNode ;
5209 _YACSMaxElem = YACSMaxElem ;
5212 CORBA::Long HOMARD_Gen_i::GetYACSMaxIter()
5214 return _YACSMaxIter ;
5216 CORBA::Long HOMARD_Gen_i::GetYACSMaxNode()
5218 return _YACSMaxNode ;
5220 CORBA::Long HOMARD_Gen_i::GetYACSMaxElem()
5222 return _YACSMaxElem ;
5225 //=============================================================================
5229 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
5230 PortableServer::POA_ptr poa,
5231 PortableServer::ObjectId* contId,
5232 const char* instanceName,
5233 const char* interfaceName)
5235 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
5236 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
5237 return myHOMARD_Gen->getId();