1 // Copyright (C) 2011-2014 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "HOMARD_Gen_i.hxx"
21 #include "HOMARD_Cas_i.hxx"
22 #include "HOMARD_Hypothesis_i.hxx"
23 #include "HOMARD_Iteration_i.hxx"
24 #include "HOMARD_Boundary_i.hxx"
25 #include "HOMARD_Zone_i.hxx"
26 #include "HOMARD_YACS_i.hxx"
27 #include "HomardDriver.hxx"
28 #include "HOMARD_DriverTools.hxx"
29 #include "HomardMedCommun.h"
30 #include "YACSDriver.hxx"
33 #include "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
1251 codret = CHDIR(DirNameStart) ;
1254 SALOME::ExceptionStruct es;
1255 es.type = SALOME::BAD_PARAM;
1256 es.text = "The directory of the iteration does not exist.";
1257 throw SALOME::SALOME_Exception(es);
1260 // A.2. Reperage des fichiers du repertoire de reprise
1261 std::string file_configuration = "" ;
1262 std::string file_maillage_homard = "" ;
1266 struct dirent *dirp;
1267 dp = opendir(DirNameStart);
1268 while ( (dirp = readdir(dp)) != NULL )
1270 std::string file_name(dirp->d_name);
1271 // MESSAGE ( file_name );
1272 bilan = file_name.find("HOMARD.Configuration.") ;
1273 if ( bilan != string::npos ) { file_configuration = file_name ; }
1274 bilan = file_name.find("maill.") ;
1275 if ( bilan != string::npos )
1277 bilan = file_name.find(".hom.med") ;
1278 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1283 HANDLE hFind = INVALID_HANDLE_VALUE;
1284 WIN32_FIND_DATA ffd;
1285 hFind = FindFirstFile(DirNameStart, &ffd);
1286 if (INVALID_HANDLE_VALUE != hFind) {
1287 while (FindNextFile(hFind, &ffd) != 0) {
1288 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1289 std::string file_name(ffd.cFileName);
1290 bilan = file_name.find("HOMARD.Configuration.") ;
1291 if ( bilan != string::npos ) { file_configuration = file_name ; }
1292 bilan = file_name.find("maill.") ;
1293 if ( bilan != string::npos )
1295 bilan = file_name.find(".hom.med") ;
1296 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1302 MESSAGE ( "==> file_configuration : " << file_configuration ) ;
1303 MESSAGE ( "==> file_maillage_homard : " << file_maillage_homard ) ;
1305 if ( ( file_configuration == "" ) || ( file_maillage_homard == "" ) )
1307 SALOME::ExceptionStruct es;
1308 es.type = SALOME::BAD_PARAM;
1310 if ( file_configuration == "" ) { text = "The configuration file cannot be found." ; }
1311 else { text = "The HOMARD mesh file cannot be found." ; }
1312 es.text = CORBA::string_dup(text.c_str());
1313 throw SALOME::SALOME_Exception(es);
1316 // B. Lecture du fichier de configuration
1317 // ATTENTION : on doit veiller a la coherence entre HomardDriver et CreateCaseFromIteration
1323 // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1324 std::ifstream fichier( file_configuration.c_str() );
1325 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1327 std::string ligne; // variable contenant chaque ligne lue
1328 std::string mot_cle;
1329 std::string argument;
1331 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1332 while ( std::getline( fichier, ligne ) )
1334 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1335 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1336 ligne_bis >> mot_cle ;
1337 // B.2. Des valeurs entieres : le second bloc de la ligne
1338 if ( mot_cle == "NumeIter" )
1340 ligne_bis >> NumeIter ;
1343 // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1344 else if ( ( mot_cle == "TypeConf" ) || ( mot_cle == "TypeElem" ) )
1346 ligne_bis >> argument ;
1348 if ( mot_cle == "TypeConf" )
1350 if ( argument == "conforme" ) { TypeConf = 1 ; }
1351 else if ( argument == "non_conforme_1_noeud" ) { TypeConf = 2 ; }
1352 else if ( argument == "non_conforme_1_arete" ) { TypeConf = 3 ; }
1353 else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1355 else if ( mot_cle == "TypeElem" )
1357 if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1358 else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1361 // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1362 // il faut les supprimer
1363 else if ( ( mot_cle == "CCNoMNP1" ) || ( mot_cle == "CCMaiNP1" ) )
1365 ligne_bis >> argument ;
1366 if ( argument[0] == '"' ) { decalage = 1 ; }
1367 else { decalage = 0 ; }
1368 size_t size = argument.size() + 1 - 2*decalage ;
1370 if ( mot_cle == "CCNoMNP1" )
1372 MeshName = new char[ size ];
1373 strncpy( MeshName, argument.c_str()+decalage, size );
1374 MeshName[size-1] = '\0' ;
1376 else if ( mot_cle == "CCMaiNP1" )
1378 MeshFile = new char[ size ];
1379 strncpy( MeshFile, argument.c_str()+decalage, size );
1380 MeshFile[size-1] = '\0' ;
1384 MESSAGE ( "==> TypeConf : " << TypeConf ) ;
1385 MESSAGE ( "==> MeshName : " << MeshName ) ;
1386 MESSAGE ( "==> MeshFile : " << MeshFile ) ;
1387 MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1388 MESSAGE ( "==> Pyram : " << Pyram ) ;
1392 SALOME::ExceptionStruct es;
1393 es.type = SALOME::BAD_PARAM;
1394 std::string text = "The configuration file cannot be read." ;
1395 es.text = CORBA::string_dup(text.c_str());
1396 throw SALOME::SALOME_Exception(es);
1399 // C. Creation effective du cas
1402 if ( _PublisMeshIN != 0 ) option = 2 ;
1403 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, option) ;
1405 // D. Parametrages lus dans le fichier de configuration
1407 myCase->SetConfType (TypeConf) ;
1408 myCase->SetPyram (Pyram) ;
1410 // E. Copie du fichier de maillage homard
1411 // E.1. Repertoire associe au cas
1412 char* nomDirCase = myCase->GetDirName() ;
1413 // E.2. Repertoire associe a l'iteration de ce cas
1415 IterName = myCase->GetIter0Name() ;
1416 HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1417 char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1418 Iter->SetDirNameLoc(nomDirIter);
1419 std::string nomDirIterTotal ;
1420 nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1422 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1424 if (_mkdir(nomDirIterTotal.c_str()) != 0)
1427 MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1428 SALOME::ExceptionStruct es;
1429 es.type = SALOME::BAD_PARAM;
1430 std::string text = "The directory for the computation cannot be created." ;
1431 es.text = CORBA::string_dup(text.c_str());
1432 throw SALOME::SALOME_Exception(es);
1434 // E.3. Copie du maillage HOMARD au format MED
1435 codret = CHDIR(DirNameStart) ;
1436 std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1437 MESSAGE ( "commande : " << commande ) ;
1438 codret = system(commande.c_str()) ;
1439 MESSAGE ( "codret : " << codret ) ;
1442 SALOME::ExceptionStruct es;
1443 es.type = SALOME::BAD_PARAM;
1444 es.text = "The starting point for the case cannot be copied into the working directory.";
1445 throw SALOME::SALOME_Exception(es);
1454 CHDIR(nomDirWork.c_str());
1455 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1457 //=============================================================================
1458 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1460 // nomCas : nom du cas a creer
1461 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1464 INFOS ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1466 std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1468 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1469 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1471 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1473 //=============================================================================
1474 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1476 // nomCas : nom du cas a creer
1477 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1478 // Number : numero de l'iteration de depart
1481 INFOS ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1484 SALOME::ExceptionStruct es;
1485 es.type = SALOME::BAD_PARAM;
1486 es.text = "The number of iteration must be positive.";
1487 throw SALOME::SALOME_Exception(es);
1491 std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1493 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1494 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1496 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1498 //=============================================================================
1499 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1501 // Retourne le nom du repertoire ou se trouve l'iteration voulue.
1502 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1503 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1506 MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1507 std::string nomDirWork = getenv("PWD") ;
1508 std::string DirNameStartIter ;
1510 int NumeIterMax = -1 ;
1512 // A.1. Controle du repertoire de depart du cas
1513 codret = CHDIR(DirNameStart) ;
1516 SALOME::ExceptionStruct es;
1517 es.type = SALOME::BAD_PARAM;
1518 es.text = "The directory of the case for the pursuit does not exist.";
1519 throw SALOME::SALOME_Exception(es);
1522 // A.2. Reperage des sous-repertoire du repertoire de reprise
1523 bool existe = false ;
1526 struct dirent *dirp;
1527 dp = opendir(DirNameStart);
1528 while ( (dirp = readdir(dp)) != NULL ) {
1529 std::string DirName_1(dirp->d_name);
1531 HANDLE hFind = INVALID_HANDLE_VALUE;
1532 WIN32_FIND_DATA ffd;
1533 hFind = FindFirstFile(DirNameStart, &ffd);
1534 if (INVALID_HANDLE_VALUE != hFind) {
1535 while (FindNextFile(hFind, &ffd) != 0) {
1536 std::string DirName_1 = "";
1537 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1538 DirName_1 = std::string(ffd.cFileName);
1541 if ( ( DirName_1 != "." ) && ( DirName_1 != ".." ) )
1543 if ( CHDIR(DirName_1.c_str()) == 0 )
1545 // On cherche le fichier de configuration dans ce sous-repertoire
1546 codret = CHDIR(DirNameStart);
1549 struct dirent *dirp_1;
1550 dp_1 = opendir(DirName_1.c_str()) ;
1551 while ( (dirp_1 = readdir(dp_1)) != NULL )
1553 std::string file_name_1(dirp_1->d_name);
1555 HANDLE hFind1 = INVALID_HANDLE_VALUE;
1556 WIN32_FIND_DATA ffd1;
1557 hFind1 = FindFirstFile(DirName_1.c_str(), &ffd1);
1558 while (FindNextFile(hFind1, &ffd1) != 0)
1560 if (ffd1.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1561 std::string file_name_1(ffd1.cFileName);
1563 int bilan = file_name_1.find("HOMARD.Configuration.") ;
1564 if ( bilan != string::npos )
1566 // Decodage du fichier pour trouver le numero d'iteration
1567 CHDIR(DirName_1.c_str()) ;
1569 std::ifstream fichier( file_name_1.c_str() );
1570 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1573 std::string ligne; // variable contenant chaque ligne lue
1574 std::string mot_cle;
1575 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1576 while ( std::getline( fichier, ligne ) )
1578 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1579 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1580 ligne_bis >> mot_cle ;
1581 if ( mot_cle == "NumeIter" )
1583 ligne_bis >> NumeIter ;
1585 // MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1586 if ( Number == - 1 )
1588 if ( NumeIter >= NumeIterMax )
1590 NumeIterMax = NumeIter ;
1591 DirNameStartIter = DirName_1 ;
1596 if ( NumeIter == Number )
1598 DirNameStartIter = DirName_1 ;
1608 SALOME::ExceptionStruct es;
1609 es.type = SALOME::BAD_PARAM;
1610 std::string text = "The configuration file cannot be read." ;
1611 es.text = CORBA::string_dup(text.c_str());
1612 throw SALOME::SALOME_Exception(es);
1614 CHDIR(DirNameStart) ;
1616 if ( existe ) { break ; }
1623 if ( existe ) { break ; }
1632 CHDIR(nomDirWork.c_str());
1634 if ( ( Number >= 0 && ( !existe ) ) || ( Number < 0 && ( NumeIterMax == -1 ) ) )
1636 SALOME::ExceptionStruct es;
1637 es.type = SALOME::BAD_PARAM;
1638 es.text = "The directory of the iteration does not exist.";
1639 throw SALOME::SALOME_Exception(es);
1643 return DirNameStartIter ;
1645 //=============================================================================
1646 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)
1648 // nomCas : nom du cas a creer
1649 // MeshName, MeshFile : nom et fichier du maillage correspondant
1650 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1651 // 1 : le maillage fourni peut ne pas exister ==> on continue si absent
1652 // -1 : le maillage n'est pas fourni
1653 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1654 // Option : multiple de nombres premiers
1655 // 1 : aucune option
1656 // x2 : publication du maillage dans SMESH
1658 MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1659 MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1660 MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1666 // A.2. Controle du nom :
1667 if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
1669 SALOME::ExceptionStruct es;
1670 es.type = SALOME::BAD_PARAM;
1671 es.text = "This case has already been defined.";
1672 throw SALOME::SALOME_Exception(es);
1676 // A.3. Controle du fichier du maillage
1677 int existeMeshFile ;
1678 if ( MeshOption >= 0 )
1680 existeMeshFile = MEDFileExist ( MeshFile ) ;
1681 MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1682 if ( ( existeMeshFile == 0 ) && ( MeshOption == 0 ) )
1684 SALOME::ExceptionStruct es;
1685 es.type = SALOME::BAD_PARAM;
1686 es.text = "The mesh file does not exist.";
1687 throw SALOME::SALOME_Exception(es);
1691 else { existeMeshFile = 0 ; }
1693 // B. Creation de l'objet cas et publication
1694 // MESSAGE ( "CreateCase0 : Creation de l'objet" );
1695 HOMARD::HOMARD_Cas_var myCase = newCase();
1696 myCase->SetName(nomCas);
1697 SALOMEDS::SObject_var aSO;
1698 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
1699 myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
1701 // C. Caracteristiques du maillage
1702 if ( existeMeshFile != 0 )
1704 // Les valeurs extremes des coordonnees
1705 // MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnees" );
1706 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1707 HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1708 if (LesExtremes.size()!=10) { return false; }
1710 for (int i =0 ; i< LesExtremes.size() ; i++)
1711 aSeq[i]=LesExtremes[i] ;
1712 myCase->SetBoundingBox(aSeq) ;
1714 // MESSAGE ( "CreateCase0 : Les groupes" );
1715 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile) ;
1716 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1717 aSeqGroupe->length(LesGroupes.size());
1718 std::set<std::string>::const_iterator it ;
1720 for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1721 aSeqGroupe[i++]=(*it).c_str() ;
1722 myCase->SetGroups(aSeqGroupe) ;
1725 // D. L'iteration initiale du cas
1726 MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1727 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1728 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1730 std::string NomIteration = std::string(MeshName) ;
1731 while ( (myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()) )
1733 std::ostringstream nom;
1734 nom << MeshName << monNum;
1735 NomIteration = nom.str();
1738 MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1740 // D.2. Creation de l'iteration
1741 HOMARD::HOMARD_Iteration_var anIter = newIteration();
1742 myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration] = anIter;
1743 anIter->SetName(NomIteration.c_str());
1744 AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1746 // D.4. Maillage correspondant
1747 if ( existeMeshFile != 0 )
1749 anIter->SetMeshFile(MeshFile);
1750 if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1752 anIter->SetMeshName(MeshName);
1754 // D.5. Numero d'iteration
1755 anIter->SetNumber(NumeIter);
1758 SetEtatIter(NomIteration.c_str(), -NumeIter);
1761 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1763 //=============================================================================
1764 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1766 INFOS ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1769 // A. Controle du nom :
1770 if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
1772 SALOME::ExceptionStruct es;
1773 es.type = SALOME::BAD_PARAM;
1774 es.text = "This hypothesis has already been defined.";
1775 throw SALOME::SALOME_Exception(es);
1779 // B. Creation de l'objet
1780 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1781 if (CORBA::is_nil(myHypothesis))
1783 SALOME::ExceptionStruct es;
1784 es.type = SALOME::BAD_PARAM;
1785 es.text = "Unable to create the hypothesis";
1786 throw SALOME::SALOME_Exception(es);
1789 myHypothesis->SetName(nomHypothesis);
1791 // C. Enregistrement
1792 myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
1794 SALOMEDS::SObject_var aSO;
1795 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
1797 // D. Valeurs par defaut des options avancees
1798 myHypothesis->SetNivMax(-1);
1799 myHypothesis->SetDiamMin(-1.0);
1800 myHypothesis->SetAdapInit(0);
1801 myHypothesis->SetLevelOutput(0);
1803 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1806 //=============================================================================
1807 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1808 //=============================================================================
1810 INFOS ("CreateIteration : NomIteration = " << NomIteration << ", nomIterParent = " << nomIterParent);
1813 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
1814 if (CORBA::is_nil(myIterationParent))
1816 SALOME::ExceptionStruct es;
1817 es.type = SALOME::BAD_PARAM;
1818 es.text = "The parent iteration is not defined.";
1819 throw SALOME::SALOME_Exception(es);
1823 const char* nomCas = myIterationParent->GetCaseName();
1824 MESSAGE ("CreateIteration : nomCas = " << nomCas);
1825 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1826 if (CORBA::is_nil(myCase))
1828 SALOME::ExceptionStruct es;
1829 es.type = SALOME::BAD_PARAM;
1830 es.text = "Invalid case context";
1831 throw SALOME::SALOME_Exception(es);
1834 const char* nomDirCase = myCase->GetDirName();
1836 // Controle du nom :
1837 if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
1839 SALOME::ExceptionStruct es;
1840 es.type = SALOME::BAD_PARAM;
1841 es.text = "This iteration has already been defined.";
1842 throw SALOME::SALOME_Exception(es);
1846 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1847 if (CORBA::is_nil(myIteration))
1849 SALOME::ExceptionStruct es;
1850 es.type = SALOME::BAD_PARAM;
1851 es.text = "Unable to create the iteration";
1852 throw SALOME::SALOME_Exception(es);
1855 myContextMap[GetCurrentStudyID()]._mesIterations[std::string(NomIteration)] = myIteration;
1856 // Nom de l'iteration et du maillage
1857 myIteration->SetName(NomIteration);
1858 myIteration->SetMeshName(NomIteration);
1859 myIteration->SetState(1);
1861 int numero = myIterationParent->GetNumber() + 1;
1862 myIteration->SetNumber(numero);
1864 // Nombre d'iterations deja connues pour le cas, permettant
1865 // la creation d'un sous-repertoire unique
1866 int nbitercase = myCase->GetNumberofIter();
1867 char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1868 myIteration->SetDirNameLoc(nomDirIter);
1870 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1871 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1872 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1873 // situation la plus frequente.
1874 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1875 // le nombre d'iterations du cas permet d'eviter les collisions.
1877 if ( nbitercase < 100 ) { jaux = 2 ; }
1878 else if ( nbitercase < 1000 ) { jaux = 3 ; }
1879 else if ( nbitercase < 10000 ) { jaux = 4 ; }
1880 else if ( nbitercase < 100000 ) { jaux = 5 ; }
1882 std::ostringstream iaux ;
1883 iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1884 std::stringstream MeshFile;
1885 MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1886 myIteration->SetMeshFile(MeshFile.str().c_str());
1888 // Association avec le cas
1889 std::string label = "IterationHomard_" + std::string(nomIterParent);
1890 AssociateCaseIter(nomCas, NomIteration, label.c_str());
1891 // Lien avec l'iteration precedente
1892 myIterationParent->LinkNextIteration(NomIteration);
1893 myIteration->SetIterParentName(nomIterParent);
1894 // Gestion de l'arbre d'etudes
1895 SALOMEDS::SObject_var aIterSOParent = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIterationParent)));
1896 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
1897 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1898 aStudyBuilder->NewCommand();
1899 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
1900 aStudyBuilder->Addreference(aSubSO, aIterSOParent);
1901 aStudyBuilder->CommitCommand();
1903 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1905 //=============================================================================
1906 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1908 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1911 // Controle du nom :
1912 if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
1914 MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1915 SALOME::ExceptionStruct es;
1916 es.type = SALOME::BAD_PARAM;
1917 es.text = "This boundary has already been defined";
1918 throw SALOME::SALOME_Exception(es);
1922 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1923 myBoundary->SetName(BoundaryName);
1924 myBoundary->SetType(BoundaryType);
1926 myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
1928 SALOMEDS::SObject_var aSO;
1929 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
1931 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1933 //=============================================================================
1934 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1936 INFOS ("CreateBoundaryDi : BoundaryName = " << BoundaryName << "MeshName = " << MeshName );
1937 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1938 myBoundary->SetMeshFile( MeshFile ) ;
1939 myBoundary->SetMeshName( MeshName ) ;
1941 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1943 //=============================================================================
1944 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1945 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1946 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1947 CORBA::Double Rayon)
1949 INFOS ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
1951 SALOME::ExceptionStruct es;
1954 { es.text = "The radius must be positive." ;
1956 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1957 if ( daux < 0.0000001 )
1958 { es.text = "The axis must be a non 0 vector." ;
1962 es.type = SALOME::BAD_PARAM;
1963 throw SALOME::SALOME_Exception(es);
1967 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1968 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1970 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1972 //=============================================================================
1973 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1974 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1975 CORBA::Double Rayon)
1977 INFOS ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
1979 SALOME::ExceptionStruct es;
1982 { es.text = "The radius must be positive." ;
1986 es.type = SALOME::BAD_PARAM;
1987 throw SALOME::SALOME_Exception(es);
1991 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1992 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1994 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1996 //=============================================================================
1997 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
1998 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
1999 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
2001 INFOS ("CreateBoundaryConeA : BoundaryName = " << BoundaryName ) ;
2003 SALOME::ExceptionStruct es;
2005 if ( Angle <= 0.0 || Angle >= 90.0 )
2006 { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
2008 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2009 if ( daux < 0.0000001 )
2010 { es.text = "The axis must be a non 0 vector." ;
2014 es.type = SALOME::BAD_PARAM;
2015 throw SALOME::SALOME_Exception(es);
2019 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
2020 myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
2022 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2024 //=============================================================================
2025 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
2026 CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
2027 CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
2029 INFOS ("CreateBoundaryConeR : BoundaryName = " << BoundaryName ) ;
2031 SALOME::ExceptionStruct es;
2033 if ( Rayon1 < 0.0 || Rayon2 < 0.0 )
2034 { es.text = "The radius must be positive." ;
2036 double daux = fabs(Rayon2-Rayon1) ;
2037 if ( daux < 0.0000001 )
2038 { es.text = "The radius must be different." ;
2040 daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
2041 if ( daux < 0.0000001 )
2042 { es.text = "The centers must be different." ;
2046 es.type = SALOME::BAD_PARAM;
2047 throw SALOME::SALOME_Exception(es);
2051 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
2052 myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
2054 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2056 //=============================================================================
2057 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryTorus(const char* BoundaryName,
2058 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2059 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2060 CORBA::Double RayonRev, CORBA::Double RayonPri)
2062 INFOS ("CreateBoundaryTorus : BoundaryName = " << BoundaryName ) ;
2064 SALOME::ExceptionStruct es;
2066 if ( ( RayonRev <= 0.0 ) || ( RayonPri <= 0.0 ) )
2067 { es.text = "The radius must be positive." ;
2069 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2070 if ( daux < 0.0000001 )
2071 { es.text = "The axis must be a non 0 vector." ;
2075 es.type = SALOME::BAD_PARAM;
2076 throw SALOME::SALOME_Exception(es);
2080 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 5) ;
2081 myBoundary->SetTorus( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, RayonRev, RayonPri ) ;
2083 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2085 //=============================================================================
2086 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
2088 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
2091 // Controle du nom :
2092 if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
2094 SALOME::ExceptionStruct es;
2095 es.type = SALOME::BAD_PARAM;
2096 es.text = "This zone has already been defined";
2097 throw SALOME::SALOME_Exception(es);
2101 HOMARD::HOMARD_Zone_var myZone = newZone();
2102 myZone->SetName(ZoneName);
2103 myZone->SetType(ZoneType);
2105 myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
2107 SALOMEDS::SObject_var aSO;
2108 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
2110 return HOMARD::HOMARD_Zone::_duplicate(myZone);
2112 //=============================================================================
2113 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
2114 CORBA::Double Xmini, CORBA::Double Xmaxi,
2115 CORBA::Double Ymini, CORBA::Double Ymaxi,
2116 CORBA::Double Zmini, CORBA::Double Zmaxi)
2118 INFOS ("CreateZoneBox : ZoneName = " << ZoneName ) ;
2120 SALOME::ExceptionStruct es;
2122 if ( Xmini > Xmaxi )
2123 { es.text = "The X coordinates are not coherent." ;
2125 if ( Ymini > Ymaxi )
2126 { es.text = "The Y coordinates are not coherent." ;
2128 if ( Zmini > Zmaxi )
2129 { es.text = "The Z coordinates are not coherent." ;
2133 es.type = SALOME::BAD_PARAM;
2134 throw SALOME::SALOME_Exception(es);
2138 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
2139 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2141 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2143 //=============================================================================
2144 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
2145 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
2147 INFOS ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
2149 SALOME::ExceptionStruct es;
2152 { es.text = "The radius must be positive." ;
2156 es.type = SALOME::BAD_PARAM;
2157 throw SALOME::SALOME_Exception(es);
2161 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
2162 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2164 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2166 //=============================================================================
2167 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
2168 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2169 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2170 CORBA::Double Rayon, CORBA::Double Haut)
2172 INFOS ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
2174 SALOME::ExceptionStruct es;
2177 { es.text = "The radius must be positive." ;
2179 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2180 if ( daux < 0.0000001 )
2181 { es.text = "The axis must be a non 0 vector." ;
2184 { es.text = "The height must be positive." ;
2188 es.type = SALOME::BAD_PARAM;
2189 throw SALOME::SALOME_Exception(es);
2193 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
2194 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
2196 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2198 //=============================================================================
2199 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
2200 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2201 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2202 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
2204 INFOS ("CreateZonePipe : ZoneName = " << ZoneName ) ;
2206 SALOME::ExceptionStruct es;
2208 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2209 { es.text = "The radius must be positive." ;
2211 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2212 if ( daux < 0.0000001 )
2213 { es.text = "The axis must be a non 0 vector." ;
2216 { es.text = "The height must be positive." ;
2218 if ( Rayon <= Rayonint )
2219 { es.text = "The external radius must be higher than the internal radius." ;
2223 es.type = SALOME::BAD_PARAM;
2224 throw SALOME::SALOME_Exception(es);
2228 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
2229 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
2231 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2233 //=============================================================================
2234 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
2235 CORBA::Double Umini, CORBA::Double Umaxi,
2236 CORBA::Double Vmini, CORBA::Double Vmaxi,
2239 INFOS ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
2240 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
2241 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
2242 // MESSAGE ("Orient = " << Orient ) ;
2244 SALOME::ExceptionStruct es;
2246 if ( Umini > Umaxi )
2247 { es.text = "The first coordinates are not coherent." ;
2249 if ( Vmini > Vmaxi )
2250 { es.text = "The second coordinates are not coherent." ;
2252 if ( Orient < 1 || Orient > 3 )
2253 { es.text = "The orientation must be 1, 2 or 3." ;
2257 es.type = SALOME::BAD_PARAM;
2258 throw SALOME::SALOME_Exception(es);
2262 double Xmini, Xmaxi ;
2263 double Ymini, Ymaxi ;
2264 double Zmini, Zmaxi ;
2272 else if ( Orient == 2 )
2279 else if ( Orient == 3 )
2286 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2288 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2289 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2291 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2293 //=============================================================================
2294 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2295 CORBA::Double Ucentre, CORBA::Double Vcentre,
2296 CORBA::Double Rayon,
2299 INFOS ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
2301 SALOME::ExceptionStruct es;
2304 { es.text = "The radius must be positive." ;
2306 if ( Orient < 1 || Orient > 3 )
2307 { es.text = "The orientation must be 1, 2 or 3." ;
2311 es.type = SALOME::BAD_PARAM;
2312 throw SALOME::SALOME_Exception(es);
2320 { Xcentre = Ucentre ;
2323 else if ( Orient == 2 )
2326 Zcentre = Vcentre ; }
2327 else if ( Orient == 3 )
2328 { Xcentre = Vcentre ;
2330 Zcentre = Ucentre ; }
2331 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2333 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2334 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2336 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2338 //=============================================================================
2339 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2340 CORBA::Double Ucentre, CORBA::Double Vcentre,
2341 CORBA::Double Rayon, CORBA::Double Rayonint,
2344 INFOS ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
2346 SALOME::ExceptionStruct es;
2348 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2349 { es.text = "The radius must be positive." ;
2351 if ( Orient < 1 || Orient > 3 )
2352 { es.text = "The orientation must be 1, 2 or 3." ;
2354 if ( Rayon <= Rayonint )
2355 { es.text = "The external radius must be higher than the internal radius." ;
2359 es.type = SALOME::BAD_PARAM;
2360 throw SALOME::SALOME_Exception(es);
2368 { Xcentre = Ucentre ;
2371 else if ( Orient == 2 )
2374 Zcentre = Vcentre ; }
2375 else if ( Orient == 3 )
2376 { Xcentre = Vcentre ;
2378 Zcentre = Ucentre ; }
2379 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2381 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2382 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2384 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2386 //=============================================================================
2387 //=============================================================================
2392 //=============================================================================
2393 //=============================================================================
2394 // Traitement d'une iteration
2395 // etatMenage = 1 : destruction du repertoire d'execution
2396 // modeHOMARD = 1 : adaptation
2397 // != 1 : information avec les options modeHOMARD
2398 // Option1 >0 : appel depuis python
2399 // <0 : appel depuis GUI
2400 // Option2 : multiple de nombres premiers
2401 // 1 : aucune option
2402 // x2 : publication du maillage dans SMESH
2403 //=============================================================================
2404 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2406 INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2411 // A.1. L'objet iteration
2412 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
2413 ASSERT(!CORBA::is_nil(myIteration));
2415 // A.2. Controle de la possibilite d'agir
2416 // A.2.1. Etat de l'iteration
2417 int etat = myIteration->GetState();
2418 MESSAGE ( "etat = "<<etat );
2419 // A.2.2. On ne calcule pas l'iteration initiale, ni une iteration deja calculee
2420 if ( modeHOMARD == 1 )
2424 SALOME::ExceptionStruct es;
2425 es.type = SALOME::BAD_PARAM;
2426 es.text = "This iteration is the first of the case and cannot be computed.";
2427 throw SALOME::SALOME_Exception(es);
2430 else if ( ( etat == 2 ) & ( modeHOMARD == 1 ) )
2432 SALOME::ExceptionStruct es;
2433 es.type = SALOME::BAD_PARAM;
2434 es.text = "This iteration is already computed.";
2435 throw SALOME::SALOME_Exception(es);
2439 // A.2.3. On n'analyse pas une iteration non calculee
2444 SALOME::ExceptionStruct es;
2445 es.type = SALOME::BAD_PARAM;
2446 es.text = "This iteration is not computed.";
2447 throw SALOME::SALOME_Exception(es);
2452 // A.3. Numero de l'iteration
2453 // siterp1 : numero de l'iteration a traiter
2455 // siter : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2456 // Ou si information :
2458 int NumeIter = myIteration->GetNumber();
2459 std::string siterp1 ;
2460 std::stringstream saux1 ;
2462 siterp1 = saux1.str() ;
2463 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2466 if ( modeHOMARD==1 )
2468 std::stringstream saux0 ;
2469 int iaux = max(0, NumeIter-1) ;
2471 siter = saux0.str() ;
2472 if (NumeIter < 11) { siter = "0" + siter ; }
2475 { siter = siterp1 ; }
2478 const char* nomCas = myIteration->GetCaseName();
2479 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
2480 ASSERT(!CORBA::is_nil(myCase));
2482 // B. Les repertoires
2483 // B.1. Le repertoire courant
2484 std::string nomDirWork = getenv("PWD") ;
2485 // B.2. Le sous-repertoire de l'iteration a traiter
2486 char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2487 MESSAGE( ". DirCompute = " << DirCompute );
2489 // C. Le fichier des messages
2490 // C.1. Le deroulement de l'execution de HOMARD
2491 std::string LogFile = DirCompute ;
2492 LogFile += "/Liste" ;
2493 if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2495 MESSAGE (". LogFile = " << LogFile);
2496 if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2497 // C.2. Le bilan de l'analyse du maillage
2498 std::string FileInfo = DirCompute ;
2500 if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2502 { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2503 else { FileInfo += "info_ap" ; }
2505 FileInfo += "." + siterp1 + ".bilan" ;
2506 myIteration->SetFileInfo(FileInfo.c_str());
2508 // D. On passe dans le repertoire de l'iteration a calculer
2509 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2512 // E. Les donnees de l'execution HOMARD
2513 // E.1. L'objet du texte du fichier de configuration
2514 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2515 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2517 // E.2. Le maillage associe a l'iteration
2518 const char* NomMesh = myIteration->GetMeshName();
2519 MESSAGE ( ". NomMesh = " << NomMesh );
2520 const char* MeshFile = myIteration->GetMeshFile();
2521 MESSAGE ( ". MeshFile = " << MeshFile );
2523 // E.3. Les donnees du traitement HOMARD
2525 if ( modeHOMARD == 1 )
2528 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2529 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2530 codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2534 InvalideIterInfo(NomIteration);
2535 myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2537 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2538 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2539 myDriver->CreeFichierDonn();
2542 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2543 DriverTexteBoundary(myCase, myDriver) ;
2545 // E.5. Ecriture du texte dans le fichier
2546 MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2548 { myDriver->CreeFichier(); }
2552 int codretexec = 12 ;
2555 codretexec = myDriver->ExecuteHomard(Option1);
2557 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2558 // En mode adaptation, on ajuste l'etat de l'iteration
2559 if ( modeHOMARD == 1 )
2561 if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2562 else { SetEtatIter(NomIteration,1); }
2563 // GERALD -- QMESSAGE BOX
2567 // H. Gestion des resultats
2570 std::string Commentaire ;
2571 // H.1. Le fichier des messages, dans tous les cas
2572 Commentaire = "log" ;
2573 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2574 else { Commentaire += "Info" ; }
2575 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2577 // H.2. Si tout s'est bien passe :
2578 if (codretexec == 0)
2580 // H.2.1. Le fichier de bilan
2581 Commentaire = "Summary" ;
2582 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2583 else { Commentaire += "Info" ; }
2584 PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2585 // H.2.2. Le fichier de maillage obtenu
2586 if ( modeHOMARD == 1 )
2588 std::stringstream saux0 ;
2589 Commentaire = "Mesh" ;
2590 Commentaire += " " + siterp1 ;
2591 PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2592 if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2595 // H.3 Message d'erreur
2596 if (codretexec != 0)
2598 std::string text = "" ;
2599 // Message d'erreur en cas de probleme en adaptation
2600 if ( modeHOMARD == 1 )
2602 text = "Error during the adaptation.\n" ;
2603 bool stopvu = false ;
2604 std::ifstream fichier( LogFile.c_str() );
2605 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
2607 std::string ligne; // variable contenant chaque ligne lue
2608 while ( std::getline( fichier, ligne ) )
2612 { text += ligne+ "\n"; }
2615 int position = ligne.find( "===== HOMARD ===== STOP =====" ) ;
2616 if ( position > 0 ) { stopvu = true ; }
2621 text += "\n\nSee the file " + LogFile + "\n" ;
2623 SALOME::ExceptionStruct es;
2624 es.type = SALOME::BAD_PARAM;
2625 es.text = CORBA::string_dup(text.c_str());
2626 throw SALOME::SALOME_Exception(es);
2628 // En mode information, on force le succes pour pouvoir consulter le fichier log
2629 if ( modeHOMARD != 1 ) { codretexec = 0 ; }
2633 // I. Menage et retour dans le repertoire du cas
2637 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2639 CHDIR(nomDirWork.c_str());
2644 //=============================================================================
2645 // Calcul d'une iteration : partie specifique a l'adaptation
2646 //=============================================================================
2647 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)
2649 MESSAGE ( "ComputeAdap" );
2654 // Numero de l'iteration
2655 int NumeIter = myIteration->GetNumber();
2656 std::stringstream saux0 ;
2657 saux0 << NumeIter-1 ;
2658 std::string siter = saux0.str() ;
2659 if (NumeIter < 11) { siter = "0" + siter ; }
2661 // A.2. On verifie qu il y a une hypothese (erreur improbable);
2662 const char* nomHypo = myIteration->GetHypoName();
2663 if (std::string(nomHypo) == std::string(""))
2665 SALOME::ExceptionStruct es;
2666 es.type = SALOME::BAD_PARAM;
2667 es.text = "This iteration does not have any associated hypothesis.";
2668 throw SALOME::SALOME_Exception(es);
2671 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
2672 ASSERT(!CORBA::is_nil(myHypo));
2674 // B. L'iteration parent
2675 const char* nomIterationParent = myIteration->GetIterParentName();
2676 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2677 ASSERT(!CORBA::is_nil(myIterationParent));
2678 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2679 if ( myIterationParent->GetState() == 1 )
2682 int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2685 // GERALD -- QMESSAGE BOX
2686 VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2690 // C. Le sous-repertoire de l'iteration precedente
2691 char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2692 MESSAGE( ". DirComputePa = " << DirComputePa );
2694 // D. Les donnees de l'adaptation HOMARD
2695 // D.1. Le type de conformite
2696 int ConfType = myCase->GetConfType();
2697 MESSAGE ( ". ConfType = " << ConfType );
2699 // D.2. Le maillage de depart
2700 const char* NomMeshParent = myIterationParent->GetMeshName();
2701 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2702 const char* MeshFileParent = myIterationParent->GetMeshFile();
2703 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2705 // D.3. Le maillage associe a l'iteration
2706 const char* MeshFile = myIteration->GetMeshFile();
2707 MESSAGE ( ". MeshFile = " << MeshFile );
2708 FILE *file = fopen(MeshFile,"r");
2712 if (etatMenage == 0)
2714 SALOME::ExceptionStruct es;
2715 es.type = SALOME::BAD_PARAM;
2716 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2717 es.text = CORBA::string_dup(text.c_str());
2718 throw SALOME::SALOME_Exception(es);
2723 std::string commande = "rm -f " + std::string(MeshFile);
2724 codret = system(commande.c_str());
2727 SALOME::ExceptionStruct es;
2728 es.type = SALOME::BAD_PARAM;
2729 es.text = "The mesh file cannot be deleted.";
2730 throw SALOME::SALOME_Exception(es);
2736 // D.4. Les types de raffinement et de deraffinement
2737 // Les appels corba sont lourds, il vaut mieux les grouper
2738 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2739 ASSERT(ListTypes->length() == 3);
2740 int TypeAdap = (*ListTypes)[0];
2741 int TypeRaff = (*ListTypes)[1];
2742 int TypeDera = (*ListTypes)[2];
2743 // MESSAGE ( ". TypeAdap = " << TypeAdap << ", TypeRaff = " << TypeRaff << ", TypeDera = " << TypeDera );
2745 // E. Texte du fichier de configuration
2746 // E.1. Incontournables du texte
2747 myDriver->TexteAdap();
2749 myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2750 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2751 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2753 // E.2. Ajout des informations liees aux zones eventuelles
2754 if ( TypeAdap == 0 )
2755 { DriverTexteZone(myHypo, myDriver) ; }
2757 // E.3. Ajout des informations liees aux champs eventuels
2758 if ( TypeAdap == 1 )
2759 { DriverTexteField(myIteration, myHypo, myDriver) ; }
2761 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2762 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2763 int numberOfGroups = listeGroupes->length();
2764 MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2765 if (numberOfGroups > 0)
2767 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2769 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2770 MESSAGE( "... GroupName = " << GroupName );
2771 myDriver->TexteGroup(GroupName);
2775 // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2776 DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2778 // E.6. Ajout des options avancees
2779 int Pyram = myCase->GetPyram();
2780 MESSAGE ( ". Pyram = " << Pyram );
2781 int NivMax = myHypo->GetNivMax();
2782 MESSAGE ( ". NivMax = " << NivMax );
2783 double DiamMin = myHypo->GetDiamMin() ;
2784 MESSAGE ( ". DiamMin = " << DiamMin );
2785 int AdapInit = myHypo->GetAdapInit();
2786 MESSAGE ( ". AdapInit = " << AdapInit );
2787 int LevelOutput = myHypo->GetLevelOutput();
2788 MESSAGE ( ". LevelOutput = " << LevelOutput );
2789 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
2791 // E.7. Ajout des informations sur le deroulement de l'execution
2792 int MessInfo = myIteration->GetInfoCompute();
2793 MESSAGE ( ". MessInfo = " << MessInfo );
2794 myDriver->TexteInfoCompute(MessInfo);
2798 //=============================================================================
2799 // Creation d'un nom de sous-repertoire pour l'iteration au sein d'un repertoire parent
2800 // nomrep : nom du repertoire parent
2801 // num : le nom du sous-repertoire est sous la forme 'In', n est >= num
2802 //=============================================================================
2803 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
2805 MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2806 // On verifie que le repertoire parent existe
2807 int codret = CHDIR(nomrep) ;
2810 SALOME::ExceptionStruct es;
2811 es.type = SALOME::BAD_PARAM;
2812 es.text = "The directory of the case does not exist.";
2813 throw SALOME::SALOME_Exception(es);
2816 std::string nomDirActuel = getenv("PWD") ;
2817 std::string DirName ;
2818 // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un repertoire inconnu
2819 bool a_chercher = true ;
2820 while ( a_chercher )
2822 // On passe dans le repertoire parent
2825 // On recherche un nom sous la forme Iabc, avec abc representant le numero
2827 if ( num < 100 ) { jaux = 2 ; }
2828 else if ( num < 1000 ) { jaux = 3 ; }
2829 else if ( num < 10000 ) { jaux = 4 ; }
2830 else if ( num < 100000 ) { jaux = 5 ; }
2832 std::ostringstream iaux ;
2833 iaux << std::setw(jaux) << std::setfill('0') << num ;
2834 std::ostringstream DirNameA ;
2835 DirNameA << "I" << iaux.str();
2836 // Si on ne pas peut entrer dans le repertoire, on doit verifier
2837 // que c'est bien un probleme d'absence
2838 if ( CHDIR(DirNameA.str().c_str()) != 0 )
2840 bool existe = false ;
2843 struct dirent *dirp;
2844 dp = opendir(nomrep);
2845 while ( (dirp = readdir(dp)) != NULL )
2847 std::string file_name(dirp->d_name);
2849 HANDLE hFind = INVALID_HANDLE_VALUE;
2850 WIN32_FIND_DATA ffd;
2851 hFind = FindFirstFile(nomrep, &ffd);
2852 if (INVALID_HANDLE_VALUE != hFind) {
2853 while (FindNextFile(hFind, &ffd) != 0) {
2854 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2855 std::string file_name(ffd.cFileName);
2857 if ( file_name == DirNameA.str() ) { existe = true ; }
2866 DirName = DirNameA.str() ;
2867 a_chercher = false ;
2874 MESSAGE ( "==> DirName = " << DirName);
2875 MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
2876 CHDIR(nomDirActuel.c_str());
2877 return CORBA::string_dup( DirName.c_str() );
2879 //=============================================================================
2880 // Calcul d'une iteration : gestion du repertoire de calcul
2881 // Si le sous-repertoire existe :
2882 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
2883 // etatMenage = 1 : on fait le menage du repertoire
2884 // etatMenage = -1 : on ne fait rien
2885 //=============================================================================
2886 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
2888 MESSAGE ( "ComputeDirManagement : repertoires pour le calcul" );
2889 // B.2. Le repertoire du cas
2890 const char* nomDirCase = myCase->GetDirName();
2891 MESSAGE ( ". nomDirCase = " << nomDirCase );
2893 // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
2894 // B.3.1. Le nom du sous-repertoire
2895 const char* nomDirIt = myIteration->GetDirNameLoc();
2897 // B.3.2. Le nom complet du sous-repertoire
2898 std::stringstream DirCompute ;
2899 DirCompute << nomDirCase << "/" << nomDirIt;
2900 MESSAGE (". DirCompute = " << DirCompute.str() );
2902 // B.3.3. Si le sous-repertoire n'existe pas, on le cree
2903 if (CHDIR(DirCompute.str().c_str()) != 0)
2906 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2908 if (_mkdir(DirCompute.str().c_str()) != 0)
2911 // GERALD -- QMESSAGE BOX
2912 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
2913 VERIFICATION("Pb a la creation du repertoire" == 0);
2918 // Le repertoire existe
2919 // On demande de faire le menage de son contenu :
2920 if (etatMenage == 1)
2922 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
2923 std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
2924 int codret = system(commande.c_str());
2927 // GERALD -- QMESSAGE BOX
2928 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
2929 VERIFICATION("Pb au menage du repertoire de calcul" == 0);
2932 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2935 if (etatMenage == 0)
2939 struct dirent *dirp;
2940 dp = opendir(DirCompute.str().c_str());
2942 while ((dirp = readdir(dp)) != NULL && result )
2944 std::string file_name(dirp->d_name);
2945 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2949 HANDLE hFind = INVALID_HANDLE_VALUE;
2950 WIN32_FIND_DATA ffd;
2951 hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
2953 if (INVALID_HANDLE_VALUE != hFind) {
2954 while (FindNextFile(hFind, &ffd) != 0) {
2955 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2956 std::string file_name(ffd.cFileName);
2957 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2962 if ( result == false)
2964 SALOME::ExceptionStruct es;
2965 es.type = SALOME::BAD_PARAM;
2966 std::string text = "Directory : " + DirCompute.str() + " is not empty";
2967 es.text = CORBA::string_dup(text.c_str());
2968 throw SALOME::SALOME_Exception(es);
2969 VERIFICATION("Directory is not empty" == 0);
2975 return CORBA::string_dup( DirCompute.str().c_str() );
2977 //=============================================================================
2978 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
2979 //=============================================================================
2980 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
2982 MESSAGE ( "ComputeDirPaManagement : repertoires pour le calcul" );
2983 // Le repertoire du cas
2984 const char* nomDirCase = myCase->GetDirName();
2985 MESSAGE ( ". nomDirCase = " << nomDirCase );
2987 // Le sous-repertoire de l'iteration precedente
2989 const char* nomIterationParent = myIteration->GetIterParentName();
2990 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2991 const char* nomDirItPa = myIterationParent->GetDirNameLoc();
2992 std::stringstream DirComputePa ;
2993 DirComputePa << nomDirCase << "/" << nomDirItPa;
2994 MESSAGE( ". nomDirItPa = " << nomDirItPa);
2995 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
2997 return CORBA::string_dup( DirComputePa.str().c_str() );
2999 //=============================================================================
3000 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
3001 //=============================================================================
3002 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3004 MESSAGE ( "... DriverTexteZone" );
3005 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3006 int numberOfZonesx2 = ListZone->length();
3009 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3011 std::string ZoneName = std::string((*ListZone)[iaux]);
3012 MESSAGE ( "... ZoneName = " << ZoneName);
3013 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
3014 ASSERT(!CORBA::is_nil(myZone));
3016 int ZoneType = myZone->GetType();
3017 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
3018 int TypeUse = atoi( TypeUsestr.c_str() );
3019 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
3020 NumZone = iaux/2 + 1 ;
3021 HOMARD::double_array* zone = myZone->GetCoords();
3022 if ( ZoneType == 2 || ( ZoneType>=11 && ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
3023 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
3024 else if ( ZoneType == 4 ) // Cas d une sphere
3025 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
3026 else if ( ZoneType == 5 || ( ZoneType>=31 && ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
3027 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
3028 else if ( ZoneType == 7 || ( ZoneType>=61 && ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
3029 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
3030 else { VERIFICATION("ZoneType est incorrect." == 0) ; }
3035 //=============================================================================
3036 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
3037 //=============================================================================
3038 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3040 MESSAGE ( "... DriverTexteField" );
3041 // Le fichier du champ
3042 char* FieldFile = myIteration->GetFieldFile();
3043 MESSAGE ( ". FieldFile = " << FieldFile );
3044 if (strlen(FieldFile) == 0)
3046 // GERALD -- QMESSAGE BOX
3047 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
3048 VERIFICATION("The file for the field is not given." == 0);
3050 // Les caracteristiques d'instants du champ de pilotage
3051 int TimeStep = myIteration->GetTimeStep();
3052 MESSAGE( ". TimeStep = " << TimeStep );
3053 int Rank = myIteration->GetRank();
3054 MESSAGE( ". Rank = " << Rank );
3055 // Les informations sur les champs
3056 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
3058 const char* FieldName = aInfosHypo->FieldName;
3060 int TypeThR = aInfosHypo->TypeThR;
3061 double ThreshR = aInfosHypo->ThreshR;
3062 int TypeThC = aInfosHypo->TypeThC;
3063 double ThreshC = aInfosHypo->ThreshC;
3064 // Saut entre mailles ou non ?
3065 int UsField = aInfosHypo->UsField;
3066 MESSAGE( ". UsField = " << UsField );
3067 // L'usage des composantes
3068 int UsCmpI = aInfosHypo->UsCmpI;
3069 MESSAGE( ". UsCmpI = " << UsCmpI );
3071 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
3074 HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
3075 int numberOfCompos = mescompo->length();
3076 MESSAGE( ". numberOfCompos = " << numberOfCompos );
3077 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
3079 std::string nomCompo = std::string((*mescompo)[NumeComp]);
3080 MESSAGE( "... nomCompo = " << nomCompo );
3081 myDriver->TexteCompo(NumeComp, nomCompo);
3085 //=============================================================================
3086 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
3087 // On ecrit dans l'ordre :
3088 // 1. la definition des frontieres
3089 // 2. les liens avec les groupes
3090 // 3. un entier resumant le type de comportement pour les frontieres
3091 //=============================================================================
3092 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
3094 MESSAGE ( "... DriverTexteBoundary" );
3095 // 1. Recuperation des frontieres
3096 std::list<std::string> ListeBoundaryTraitees ;
3097 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3098 int numberOfitems = ListBoundaryGroupType->length();
3099 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
3100 int BoundaryOption = 1 ;
3101 // 2. Parcours des frontieres pour ecrire leur description
3102 int NumBoundaryAnalytical = 0 ;
3103 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3105 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3106 MESSAGE ( "... BoundaryName = " << BoundaryName);
3107 // 2.1. La frontiere a-t-elle deja ete ecrite ?
3108 // Cela arrive quand elle estliéé a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
3110 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3111 while (it != ListeBoundaryTraitees.end())
3113 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3114 if ( BoundaryName == *it ) { A_faire = 0 ; }
3117 // 2.2. Ecriture de la frontiere
3120 // 2.2.1. Caracteristiques de la frontiere
3121 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3122 ASSERT(!CORBA::is_nil(myBoundary));
3123 int BoundaryType = myBoundary->GetType();
3124 MESSAGE ( "... BoundaryType = " << BoundaryType );
3125 // 2.2.2. Ecriture selon le type
3126 // 2.2.2.1. Cas d une frontiere discrete
3127 if (BoundaryType == 0)
3129 const char* MeshName = myBoundary->GetMeshName() ;
3130 const char* MeshFile = myBoundary->GetMeshFile() ;
3131 myDriver->TexteBoundaryDi( MeshName, MeshFile);
3132 if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
3134 // 2.2.2.1. Cas d une frontiere analytique
3137 NumBoundaryAnalytical++ ;
3138 HOMARD::double_array* coor = myBoundary->GetCoords();
3139 if (BoundaryType == 1) // Cas d un cylindre
3141 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3142 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3144 else if (BoundaryType == 2) // Cas d une sphere
3146 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
3147 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3149 else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
3151 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3152 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3154 else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
3156 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3157 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3159 else if (BoundaryType == 5) // Cas d un tore
3161 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3162 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3165 // 2.2.3. Memorisation du traitement
3166 ListeBoundaryTraitees.push_back( BoundaryName );
3169 // 3. Parcours des frontieres pour ecrire les liens avec les groupes
3170 NumBoundaryAnalytical = 0 ;
3171 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3173 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3174 MESSAGE ( "... BoundaryName = " << BoundaryName);
3175 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3176 ASSERT(!CORBA::is_nil(myBoundary));
3177 int BoundaryType = myBoundary->GetType();
3178 MESSAGE ( "... BoundaryType = " << BoundaryType );
3179 // 3.1. Recuperation du nom du groupe
3180 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
3181 MESSAGE ( "... GroupName = " << GroupName);
3182 // 3.2. Cas d une frontiere discrete
3183 if ( BoundaryType == 0 )
3185 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
3187 // 3.3. Cas d une frontiere analytique
3190 NumBoundaryAnalytical++ ;
3191 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
3194 // 4. Ecriture de l'option finale
3195 myDriver->TexteBoundaryOption(BoundaryOption);
3199 //=============================================================================
3200 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3201 //=============================================================================
3202 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3204 MESSAGE ( "... DriverTexteFieldInterp" );
3205 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3206 MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3207 if (TypeFieldInterp != 0)
3209 // Le fichier des champs
3210 char* FieldFile = myIteration->GetFieldFile();
3211 MESSAGE ( ". FieldFile = " << FieldFile );
3212 if (strlen(FieldFile) == 0)
3214 // GERALD -- QMESSAGE BOX
3215 VERIFICATION("The file for the field is not given." == 0);
3218 const char* MeshFile = myIteration->GetMeshFile();
3219 myDriver->TexteFieldInterp(FieldFile, MeshFile);
3222 // Interpolation de tous les champs
3223 if ( TypeFieldInterp == 1 )
3225 myDriver->TexteFieldInterpAll();
3227 // Interpolation de certains champs
3228 else if (TypeFieldInterp == 2)
3230 // Les champs et leurs instants pour l'iteration
3231 HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3232 int numberOfFieldsx3 = ListFieldTSR->length();
3233 MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3234 // Les champs pour l'hypothese
3235 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3236 int numberOfFieldsx2 = ListField->length();
3237 MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3238 // On parcourt tous les champs de l'hypothese
3240 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3243 std::string FieldName = std::string((*ListField)[iaux]) ;
3244 // Le type d'interpolation
3245 std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3246 MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3247 // On cherche à savoir si des instants ont été précisés pour cette itération
3249 for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3252 std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3253 MESSAGE( "..... FieldName2 = " << FieldName2 );
3254 // Quand c'est le bon champ, on ecrit le pas de temps
3255 if ( FieldName == FieldName2 )
3259 std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3260 // Le numero d'ordre
3261 std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3262 MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3264 int TimeStep = atoi( TimeStepstr.c_str() );
3265 int Rank = atoi( Rankstr.c_str() );
3266 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3270 // Si aucun instant n'a été défini
3274 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3282 //===========================================================================
3283 //===========================================================================
3286 //===========================================================================
3287 //===========================================================================
3289 //===========================================================================
3290 //===========================================================================
3291 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
3292 SALOMEDS::SObject_ptr theSObject,
3293 CORBA::Object_ptr theObject,
3294 const char* theName)
3296 MESSAGE("PublishInStudy pour " << theName);
3297 SALOMEDS::SObject_var aResultSO;
3298 if (CORBA::is_nil(theStudy))
3300 SALOME::ExceptionStruct es;
3301 es.type = SALOME::BAD_PARAM;
3302 es.text = "Invalid study context";
3303 throw SALOME::SALOME_Exception(es);
3307 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3308 // Rq : Iteration est publiee ailleurs
3309 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3310 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
3311 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3312 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3313 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3315 addInStudy(theStudy);
3317 // Controle de la non publication d'un objet de meme nom
3318 if ( (!aBoundary->_is_nil()) || (!aHypo->_is_nil()) || (!aYACS->_is_nil()) || (!aZone->_is_nil()) )
3320 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
3321 if (listSO->length() >= 1)
3323 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3324 aResultSO = listSO[0];
3325 return aResultSO._retn();
3329 // Caracteristiques de l'etude
3330 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
3331 aStudyBuilder->NewCommand();
3332 if(!aBoundary->_is_nil())
3333 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
3334 else if(!aCase->_is_nil())
3335 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
3336 else if(!aHypo->_is_nil())
3337 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
3338 else if(!aYACS->_is_nil())
3339 aResultSO = PublishYACSInStudy(theStudy, aStudyBuilder, aYACS, theName);
3340 else if(!aZone->_is_nil())
3341 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
3343 aStudyBuilder->CommitCommand();
3345 return aResultSO._retn();
3347 //=============================================================================
3348 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3349 SALOMEDS::StudyBuilder_var aStudyBuilder,
3350 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3352 MESSAGE("PublishBoundaryStudy pour "<<theName);
3353 SALOMEDS::SObject_var aResultSO;
3355 // Caracteristique de la Boundary
3356 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3358 // On recupere le module pere dans l etude
3359 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3360 if (theFatherHomard->_is_nil())
3362 MESSAGE("theFatherHomard->_is_nil()");
3363 return aResultSO._retn();
3366 // On ajoute la categorie des boundarys dans l etude si necessaire
3367 if ( _tag_boun == 0 )
3370 _tag_boun = _tag_gene ;
3372 MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3373 SALOMEDS::SObject_var aSObject;
3374 if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3376 MESSAGE("Ajout de la categorie des boundarys");
3377 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3378 PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3380 else { MESSAGE("La categorie des boundarys existe deja."); }
3382 CORBA::Long BoundaryType = myBoundary->GetType();
3383 // MESSAGE("BoundaryType : "<<BoundaryType);
3386 switch (BoundaryType)
3389 { value = "BoundaryDiHomard" ;
3390 icone = "mesh_tree_mesh.png" ;
3394 { value = "BoundaryAnHomard" ;
3395 icone = "cylinderpointvector_2.png" ;
3399 { value = "BoundaryAnHomard" ;
3400 icone = "spherepoint_2.png" ;
3404 { value = "BoundaryAnHomard" ;
3405 icone = "conepointvector.png" ;
3409 { value = "BoundaryAnHomard" ;
3410 icone = "conedxyz.png" ;
3414 { value = "BoundaryAnHomard" ;
3415 icone = "toruspointvector.png" ;
3419 aResultSO = aStudyBuilder->NewObject(aSObject);
3420 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3421 return aResultSO._retn();
3423 //=============================================================================
3424 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
3425 SALOMEDS::StudyBuilder_var aStudyBuilder,
3426 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3428 MESSAGE("PublishCaseInStudy pour "<<theName);
3429 SALOMEDS::SObject_var aResultSO;
3431 if (CORBA::is_nil(theObject)) {
3432 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3433 return aResultSO._retn();
3435 if (theStudy->_is_nil()) {
3436 MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
3437 return aResultSO._retn();
3440 // On recupere le module pere dans l etude
3441 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3442 if (theFatherHomard->_is_nil())
3444 MESSAGE("theFatherHomard->_is_nil()");
3445 return aResultSO._retn();
3449 MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3450 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3451 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3452 _orb->object_to_string(theObject) ) ;
3454 return aResultSO._retn();
3456 //=============================================================================
3457 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3458 SALOMEDS::StudyBuilder_var aStudyBuilder,
3459 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3461 MESSAGE("PublishHypotheseInStudy pour "<<theName);
3462 SALOMEDS::SObject_var aResultSO;
3464 // On recupere le module pere dans l etude
3465 // On ajoute la categorie des hypotheses dans l etude si necessaire
3466 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3467 if (theFatherHomard->_is_nil())
3469 MESSAGE("theFatherHomard->_is_nil()");
3470 return aResultSO._retn();
3473 // On ajoute la categorie des hypotheses dans l etude si necessaire
3474 SALOMEDS::SObject_var aSObject;
3475 if ( _tag_hypo == 0 )
3478 _tag_hypo = _tag_gene ;
3480 MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3481 if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3483 MESSAGE("Ajout de la categorie des hypotheses");
3484 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3485 PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3487 else { MESSAGE("La categorie des hypotheses existe deja."); }
3489 // Creation du resultat dans l'etude
3490 aResultSO = aStudyBuilder->NewObject(aSObject);
3491 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3493 return aResultSO._retn();
3495 //=============================================================================
3496 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::Study_ptr theStudy,
3497 SALOMEDS::StudyBuilder_var aStudyBuilder,
3498 HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3500 MESSAGE("PublishYACSInStudy pour "<<theName);
3501 SALOMEDS::SObject_var aResultSO;
3503 // On recupere le module pere dans l etude
3504 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3505 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3506 if (theFatherHomard->_is_nil())
3508 MESSAGE("theFatherHomard->_is_nil()");
3509 return aResultSO._retn();
3511 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3512 if ( _tag_yacs == 0 )
3515 _tag_yacs = _tag_gene ;
3517 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3518 SALOMEDS::SObject_var aSObject;
3519 if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3521 MESSAGE("Ajout de la categorie des schemas YACS");
3522 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3523 PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3525 else { MESSAGE("La categorie des schemas YACS existe deja."); }
3527 // Creation du resultat dans l'etude
3528 aResultSO = aStudyBuilder->NewObject(aSObject);
3529 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3531 return aResultSO._retn();
3534 //=============================================================================
3535 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
3536 SALOMEDS::StudyBuilder_var aStudyBuilder,
3537 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3539 MESSAGE("PublishZoneStudy pour "<<theName);
3540 SALOMEDS::SObject_var aResultSO;
3541 if (CORBA::is_nil(theObject))
3543 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3544 return aResultSO._retn();
3546 if (theStudy->_is_nil())
3548 MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3549 return aResultSO._retn();
3551 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3552 if (theFatherHomard->_is_nil())
3554 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3555 return aResultSO._retn();
3558 // Caracteristique de la zone
3559 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3560 CORBA::Long ZoneType = myZone->GetType();
3562 // On ajoute la categorie des zones dans l etude si necessaire
3563 if ( _tag_zone == 0 )
3566 _tag_zone = _tag_gene ;
3568 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3569 SALOMEDS::SObject_var aSObject;
3570 if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3572 MESSAGE("Ajout de la categorie des zones");
3573 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3574 PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3576 else { MESSAGE("La categorie des zones existe deja."); }
3578 aResultSO = aStudyBuilder->NewObject(aSObject);
3587 { icone = "boxdxy_2.png" ;
3591 { icone = "boxdxyz_2.png" ;
3599 { icone = "disk_2.png" ;
3603 { icone = "spherepoint_2.png" ;
3607 { icone = "cylinderpointvector_2.png" ;
3615 { icone = "diskwithhole_2.png" ;
3619 { icone = "pipe_2.png" ;
3623 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3625 return aResultSO._retn();
3627 //===========================================================================
3628 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3629 SALOMEDS::SObject_var aResultSO,
3630 const char* name, const char* comment, const char* icone, const char* ior)
3632 MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3633 // MESSAGE("icone = "<<icone);
3634 // MESSAGE("ior = "<<ior);
3635 SALOMEDS::GenericAttribute_var anAttr ;
3639 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3640 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3641 aNameAttrib->SetValue(name);
3644 // Ajout du commentaire
3645 if ( comment != NULL )
3647 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3648 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3649 aCommentAttrib->SetValue(comment);
3653 if ( icone != NULL )
3655 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3656 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3657 aPixmap->SetPixMap(icone);
3663 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3664 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3665 anIOR->SetValue(ior);
3669 //=====================================================================================
3670 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3672 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3674 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3675 ASSERT(!CORBA::is_nil(myCase));
3676 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3677 ASSERT(!CORBA::is_nil(aCaseSO));
3679 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3680 ASSERT(!CORBA::is_nil(myBoundary));
3681 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3682 ASSERT(!CORBA::is_nil(aBoundarySO));
3684 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3686 aStudyBuilder->NewCommand();
3688 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3689 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3690 // aStudyBuilder->RemoveReference(aSubSO);
3692 aStudyBuilder->CommitCommand();
3695 //=====================================================================================
3696 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3698 MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3700 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3701 ASSERT(!CORBA::is_nil(myYACS));
3702 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3703 ASSERT(!CORBA::is_nil(aYACSSO));
3705 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3706 ASSERT(!CORBA::is_nil(myCase));
3707 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3708 ASSERT(!CORBA::is_nil(aCaseSO));
3710 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3712 aStudyBuilder->NewCommand();
3714 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3715 aStudyBuilder->Addreference(aSubSO, aCaseSO);
3717 aStudyBuilder->CommitCommand();
3720 //=============================================================================
3721 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3722 // Option = 0 : fichier issu d'une importation
3723 // Option = 1 : fichier issu d'une execution HOMARD
3725 MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3726 if (CORBA::is_nil(myCurrentStudy))
3728 SALOME::ExceptionStruct es;
3729 es.type = SALOME::BAD_PARAM;
3730 es.text = "Invalid study context";
3731 throw SALOME::SALOME_Exception(es);
3735 // Le module SMESH est-il actif ?
3736 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3738 if (!CORBA::is_nil(aSmeshSO))
3740 // On verifie que le fichier n est pas deja publie
3741 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3742 for (; aIter->More(); aIter->Next())
3744 SALOMEDS::SObject_var aSO = aIter->Value();
3745 SALOMEDS::GenericAttribute_var aGAttr;
3746 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3748 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3749 CORBA::String_var value=anAttr->Value();
3750 if (strcmp((const char*)value,NomFich) == 0)
3752 MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3753 // Pour un fichier importe, on ne republie pas
3754 if ( Option == 0 ) { return; }
3755 // Pour un fichier calcule, on commence par faire la depublication
3758 MESSAGE ( "PublishResultInSmesh : depublication" );
3759 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3760 CORBA::String_var value2=anAttr2->Value();
3761 std::string MeshName = string(value2) ;
3762 MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3763 DeleteResultInSmesh(NomFich, MeshName) ;
3770 // On enregistre le fichier
3771 MESSAGE( "Enregistrement du fichier");
3772 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
3773 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
3774 ASSERT(!CORBA::is_nil(aSmeshEngine));
3775 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
3776 SMESH::DriverMED_ReadStatus theStatus;
3777 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3779 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
3780 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3781 for (int i = 0; i < mesMaillages->length(); i++)
3783 MESSAGE( ". Mise a jour des attributs du maillage");
3784 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
3785 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
3786 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3787 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
3788 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3789 anAttr->SetValue(NomFich);
3790 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
3791 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
3793 if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
3794 else { icone = "mesh_tree_mesh.png" ; }
3795 anAttr2->SetPixMap( icone );
3799 //=============================================================================
3800 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
3802 MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
3803 if (CORBA::is_nil(myCurrentStudy))
3805 SALOME::ExceptionStruct es;
3806 es.type = SALOME::BAD_PARAM;
3807 es.text = "Invalid study context";
3808 throw SALOME::SALOME_Exception(es);
3812 // Le module SMESH est-il actif ?
3813 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3815 if (CORBA::is_nil(aSmeshSO))
3819 // On verifie que le fichier est deja publie
3820 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
3821 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3822 for (; aIter->More(); aIter->Next())
3824 SALOMEDS::SObject_var aSO = aIter->Value();
3825 SALOMEDS::GenericAttribute_var aGAttr;
3826 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3828 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3829 CORBA::String_var value=anAttr->Value();
3830 if (strcmp((const char*)value,NomFich.c_str()) == 0)
3832 if (aSO->FindAttribute(aGAttr,"AttributeName"))
3834 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3835 CORBA::String_var value2=anAttr2->Value();
3836 if (strcmp((const char*)value2,MeshName.c_str()) == 0)
3838 myBuilder->RemoveObjectWithChildren( aSO ) ;
3846 //=============================================================================
3847 void HOMARD_Gen_i::PublishMeshIterInSmesh(const char* NomIter)
3849 MESSAGE( "PublishMeshIterInSmesh " << NomIter);
3850 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3852 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3853 if (CORBA::is_nil(myIteration))
3855 SALOME::ExceptionStruct es;
3856 es.type = SALOME::BAD_PARAM;
3857 es.text = "Invalid iterationStudy Object";
3858 throw SALOME::SALOME_Exception(es);
3861 const char* MeshFile = myIteration->GetMeshFile() ;
3862 const char* MeshName = myIteration->GetMeshName() ;
3863 CORBA::Long Option = -1 ;
3864 int etat = myIteration->GetState();
3865 // Iteration initiale
3866 if ( etat <= 0 ) { Option = 0 ; }
3867 // ou iteration calculee
3868 else if ( etat == 2 ) { Option = 1 ; }
3869 // Publication effective apres menage eventuel
3872 DeleteResultInSmesh(MeshFile, MeshName) ;
3873 PublishResultInSmesh(MeshFile, Option) ;
3877 //=============================================================================
3878 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
3880 // MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3881 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3883 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3884 if (CORBA::is_nil(myIteration))
3886 SALOME::ExceptionStruct es;
3887 es.type = SALOME::BAD_PARAM;
3888 es.text = "Invalid iterationStudy Object";
3889 throw SALOME::SALOME_Exception(es);
3893 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3895 aStudyBuilder->NewCommand();
3897 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
3898 // Pour les fichiers med, on affiche une icone de maillage
3899 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
3900 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
3902 std::string ior = " " ;
3903 if ( Commentaire[0] == 'I' )
3904 { icone = "med.png" ; }
3906 { icone = "texte_2.png" ; }
3907 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3909 aStudyBuilder->CommitCommand();
3912 //=============================================================================
3913 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
3915 // MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3916 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3918 SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3919 if (CORBA::is_nil(myYACS))
3921 SALOME::ExceptionStruct es;
3922 es.type = SALOME::BAD_PARAM;
3923 es.text = "Invalid YACSStudy Object";
3924 throw SALOME::SALOME_Exception(es);
3928 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3930 aStudyBuilder->NewCommand();
3932 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3933 std::string icone = "texte_2.png" ;
3934 std::string ior = " " ;
3935 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3937 aStudyBuilder->CommitCommand();
3940 //=============================================================================
3941 //=============================================================================
3943 //=============================================================================
3944 //=============================================================================
3945 //=============================================================================
3946 // Creation d'un schema YACS
3947 // nomCas : nom du cas a traiter
3948 // FileName : nom du fichier contenant le script de lancement du calcul
3949 // DirName : le repertoire de lancement des calculs du schéma
3950 //=============================================================================
3951 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
3953 INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
3954 INFOS ( ". nomCas : " << nomCas);
3955 INFOS ( ". ScriptFile : " << ScriptFile);
3956 INFOS ( ". DirName : " << DirName);
3957 INFOS ( ". MeshFile : " << MeshFile);
3959 // A. Controle du nom :
3960 if ((myContextMap[GetCurrentStudyID()]._mesYACSs).find(nomYACS) != (myContextMap[GetCurrentStudyID()]._mesYACSs).end())
3962 SALOME::ExceptionStruct es;
3963 es.type = SALOME::BAD_PARAM;
3964 es.text = "This schema YACS has already been defined.";
3965 throw SALOME::SALOME_Exception(es);
3969 // B. Creation de l'objet
3970 HOMARD::HOMARD_YACS_var myYACS = newYACS();
3971 if (CORBA::is_nil(myYACS))
3973 SALOME::ExceptionStruct es;
3974 es.type = SALOME::BAD_PARAM;
3975 es.text = "Unable to create the schema YACS";
3976 throw SALOME::SALOME_Exception(es);
3979 myYACS->SetName( nomYACS ) ;
3981 // C. Enregistrement
3982 myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS] = myYACS;
3984 SALOMEDS::SObject_var aSO;
3985 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myYACS, nomYACS);
3987 PublishCaseUnderYACS(nomYACS, nomCas);
3989 // D. Caracterisation
3991 myYACS->SetDirName( DirName ) ;
3992 myYACS->SetMeshFile( MeshFile ) ;
3993 myYACS->SetScriptFile( ScriptFile ) ;
3994 myYACS->SetCaseName( nomCas ) ;
3997 // D.2.1. Type constant
3998 myYACS->SetType( 1 ) ;
3999 // D.2.2. Convergence
4000 defaut_i = GetYACSMaxIter() ;
4001 myYACS->SetMaxIter( defaut_i ) ;
4002 defaut_i = GetYACSMaxNode() ;
4003 myYACS->SetMaxNode( defaut_i ) ;
4004 defaut_i = GetYACSMaxElem() ;
4005 myYACS->SetMaxElem( defaut_i ) ;
4006 // D.3. Fichier de sauvegarde dans le repertoire du cas
4007 HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
4008 std::string dirnamecase = caseyacs->GetDirName() ;
4009 std::string XMLFile ;
4010 XMLFile = dirnamecase + "/schema.xml" ;
4011 myYACS->SetXMLFile( XMLFile.c_str() ) ;
4013 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
4015 //=============================================================================
4016 // Ecriture d'un schema YACS
4017 //=============================================================================
4018 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
4020 INFOS ( "YACSWrite : Ecriture de " << nomYACS );
4021 // Le repertoire du cas
4022 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4023 ASSERT(!CORBA::is_nil(myYACS));
4024 // Le nom du fichier du schema
4025 std::string XMLFile ;
4026 XMLFile = myYACS->GetXMLFile() ;
4028 int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
4032 //=============================================================================
4033 // Ecriture d'un schema YACS sur un fichier donne
4034 //=============================================================================
4035 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
4037 INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
4044 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4045 ASSERT(!CORBA::is_nil(myYACS));
4046 // B.2. Les caracteristiques
4047 std::string DirName = myYACS->GetDirName() ;
4048 std::string MeshFile = myYACS->GetMeshFile() ;
4049 std::string ScriptFile = myYACS->GetScriptFile() ;
4050 // B.3. Les caracteristiques de convergence
4051 int MaxIter = myYACS->GetMaxIter() ;
4052 int MaxNode = myYACS->GetMaxNode() ;
4053 int MaxElem = myYACS->GetMaxElem() ;
4057 const char* nomCas = myYACS->GetCaseName();
4058 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
4059 ASSERT(!CORBA::is_nil(myCase));
4060 // C.2. Les instructions python associees au cas
4061 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4062 std::string pythonCas = dumpCorbaCase.in();
4063 MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
4065 // D. Les iterations
4066 // D.1. L'iteration initiale
4067 HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
4068 std::string Iter0Name = myCase->GetIter0Name() ;
4069 MESSAGE (". Iter0Name = " << Iter0Name);
4070 std::string MeshName = Iter0->GetMeshName();
4071 MESSAGE (". MeshName = " << MeshName);
4072 // D.2. L'iteration numero 1
4073 HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
4074 int numberOfIter = maListe->length();
4075 if ( numberOfIter > 1 )
4077 MESSAGE (". numberOfIter = " << numberOfIter);
4078 SALOME::ExceptionStruct es ;
4079 es.type = SALOME::BAD_PARAM;
4080 std::string text = "Une seule iteration est permise." ;
4081 es.text = CORBA::string_dup(text.c_str());
4082 throw SALOME::SALOME_Exception(es);
4085 std::string Iter1Name = std::string((*maListe)[0]);
4086 MESSAGE ("... Iter1Name = " << Iter1Name);
4087 HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
4088 // D.3. Les instructions python associees a l'iteration
4089 CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
4090 std::string pythonIter = dumpCorbaIter.in();
4091 MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
4093 // E. L'hypothese pour passer de l'iteration initiale a la suivante
4094 // E.1. La structure
4095 std::string nomHypo = Iter1->GetHypoName();
4096 MESSAGE (". nomHypo = " << nomHypo);
4097 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
4098 ASSERT(!CORBA::is_nil(myHypo));
4099 // E.2. Les caracteristiques de l'adaptation
4100 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
4101 ASSERT(ListTypes->length() == 3);
4102 int TypeAdap = (*ListTypes)[0];
4103 // int TypeRaff = (*ListTypes)[1];
4104 // int TypeDera = (*ListTypes)[2];
4105 // E.3. Les instructions python associees a l'hypothese
4106 CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
4107 std::string pythonHypo = dumpCorbaHypo.in();
4108 MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
4110 // F. Le fichier du schema de reference
4111 // HOMARD_ROOT_DIR : repertoire ou se trouve le module HOMARD
4112 std::string XMLFile_base ;
4113 if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
4116 SALOME::ExceptionStruct es ;
4117 es.type = SALOME::BAD_PARAM;
4118 std::string text = "HOMARD_ROOT_DIR est inconnu." ;
4119 es.text = CORBA::string_dup(text.c_str());
4120 throw SALOME::SALOME_Exception(es);
4123 XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
4125 MESSAGE("XMLFile_base ="<<XMLFile_base);
4127 // G. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4128 YACSDriver* myDriver = new YACSDriver(XMLFile, DirName);
4129 std::ifstream fichier( XMLFile_base.c_str() );
4130 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
4132 // G.1. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4133 std::string ligne; // variable contenant chaque ligne lue
4134 std::string mot_cle;
4135 while ( std::getline( fichier, ligne ) )
4137 // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
4138 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
4139 ligne_bis >> mot_cle ;
4140 // G.1.2. Le maillage initial
4141 if ( mot_cle == "DataInit_MeshFile" )
4142 { myDriver->Texte_DataInit_MeshFile(MeshFile); }
4143 // G.1.3. Le script de lancement
4144 else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
4145 { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
4146 // G.1.4. Les options du cas
4147 else if ( mot_cle == "Iter_1_Case_Options" )
4148 { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
4149 // G.1.5. Execution de HOMARD : le repertoire du cas
4150 else if ( mot_cle == "HOMARD_Exec_DirName" )
4151 { myDriver->Texte_HOMARD_Exec_DirName(); }
4152 // G.1.6. Execution de HOMARD : le nom du maillage
4153 else if ( mot_cle == "HOMARD_Exec_MeshName" )
4155 myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
4156 std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
4157 myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
4159 // G.1.7. Execution de HOMARD : les options de l'hypothese
4160 else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
4161 { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ; }
4162 // G.1.8. Execution de HOMARD : les options de l'iteration
4163 else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
4164 { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ; }
4165 // G.1.9. a. Creation eventuelles des zones et frontieres
4167 else if ( mot_cle == "Iter_1" )
4169 std::string texte_control = "" ;
4170 if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
4171 texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
4172 texte_control += myDriver->Texte_Iter_1_control() ;
4173 myDriver->TexteAdd(texte_control);
4175 // G.1.10. Les tests de convergence
4176 else if ( mot_cle == "Analyse_Test_Convergence" )
4177 { myDriver->TexteAnalyse_Test_Convergence(MaxIter, MaxNode, MaxElem); }
4178 // G.1.11. Les parametres
4179 else if ( mot_cle == "PARAMETRES" )
4180 { myDriver->TexteAddParametres(); }
4181 // G.1.n. La ligne est recopiee telle quelle
4182 else { myDriver->TexteAdd(ligne); }
4184 // G.2. Ecriture du texte dans le fichier
4186 { myDriver->CreeFichier(); }
4190 SALOME::ExceptionStruct es;
4191 es.type = SALOME::BAD_PARAM;
4192 std::string text = "The reference file for the YACS schema cannot be read." ;
4193 es.text = CORBA::string_dup(text.c_str());
4194 throw SALOME::SALOME_Exception(es);
4199 // H. Publication du fichier dans l'arbre
4201 std::string Commentaire = "xml" ;
4202 PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
4206 //=============================================================================
4207 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
4208 //=============================================================================
4209 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
4211 MESSAGE ( "YACSDriverTexteZone" );
4212 // A. Les zones associees a cette hypothese
4213 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
4214 int numberOfZonesx2 = ListZone->length();
4216 // B. Parcours des zones
4217 std::string texte_control ;
4218 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
4220 // 1. Reperage de la zone
4221 std::string ZoneName = std::string((*ListZone)[iaux]);
4222 MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
4223 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
4224 ASSERT(!CORBA::is_nil(myZone));
4225 // 2. Les instructions python associees a la zone
4226 // La premiere ligne est un commentaire a eliminer
4227 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4228 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4229 std::string pythonStructure_0 = dumpCorbaZone.in();
4230 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4231 std::istringstream tout (pythonStructure_0) ;
4233 std::string pythonStructure ;
4234 while ( std::getline( tout, ligne ) )
4235 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4236 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4237 // 3. Decodage du nom du service
4238 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4239 MESSAGE ( "... methode = " << methode);
4240 // 4. Mise en place des instructions
4241 int ZoneType = myZone->GetType();
4242 MESSAGE ( "... ZoneType = " << ZoneType);
4243 std::string texte_control_0 ;
4244 texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
4245 texte_control += texte_control_0 ;
4250 return texte_control ;
4252 //=============================================================================
4253 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4254 //=============================================================================
4255 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4257 MESSAGE ( "YACSDriverTexteBoundary" );
4258 // A. Les frontieres associees au cas
4259 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4260 int numberOfitems = ListBoundaryGroupType->length();
4262 // B. Parcours des frontieres
4263 std::string texte_control ;
4264 std::list<std::string> ListeBoundaryTraitees ;
4265 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4267 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4268 MESSAGE ( "... BoundaryName = " << BoundaryName);
4269 // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4270 // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4272 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4273 while (it != ListeBoundaryTraitees.end())
4275 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4276 if ( BoundaryName == *it ) { A_faire = 0 ; }
4281 // 1. Caracteristiques de la frontiere
4282 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
4283 ASSERT(!CORBA::is_nil(myBoundary));
4284 // 2. Les instructions python associees a la frontiere
4285 // La premiere ligne est un commentaire a eliminer
4286 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4287 CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4288 std::string pythonStructure_0 = dumpCorbaBoundary.in();
4289 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4290 std::istringstream tout (pythonStructure_0) ;
4292 std::string pythonStructure ;
4293 while ( std::getline( tout, ligne ) )
4294 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4295 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4296 // 3. Decodage du nom du service
4297 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4298 MESSAGE ( "... methode = " << methode);
4299 // 4. Mise en place des instructions
4300 int BoundaryType = myBoundary->GetType();
4301 MESSAGE ( "... BoundaryType = " << BoundaryType);
4302 std::string texte_control_0 ;
4303 texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName );
4304 texte_control += texte_control_0 ;
4305 // 5. Memorisation du traitement
4306 ListeBoundaryTraitees.push_back( BoundaryName );
4310 return texte_control ;
4313 //=============================================================================
4314 //=============================================================================
4315 // Next functions are inherited from SALOMEDS::Driver interface
4316 //=============================================================================
4317 //=============================================================================
4318 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4320 CORBA::Boolean isMultiFile)
4322 MESSAGE ("Save for theURL = "<< theURL);
4323 SALOMEDS::TMPFile_var aStreamFile;
4325 // get temporary directory name
4326 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4328 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4329 StudyContext& context = myContextMap[ aStudy->StudyId() ];
4331 // HOMARD data file name
4332 std::string aFileName = "";
4334 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4335 aFileName += "_HOMARD.dat";
4337 // initialize sequence of file names
4338 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
4339 aFileSeq->length(1);
4340 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
4342 // get full path to the data file
4343 aFileName = tmpDir + aFileName;
4347 std::ofstream f(aFileName.c_str());
4349 // clear temporary id map
4350 context._idmap.clear();
4355 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4356 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4357 HOMARD::HOMARD_Cas_var aCas = it_case->second;
4358 PortableServer::ServantBase_var aServant = GetServant(aCas);
4359 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4361 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4362 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4366 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4367 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4368 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4369 PortableServer::ServantBase_var aServant = GetServant(aZone);
4370 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4372 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4373 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4376 // -> save hypotheses
4377 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4378 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4379 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4380 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4381 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4383 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4384 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4387 // -> save iterations
4388 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4389 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4390 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4391 PortableServer::ServantBase_var aServant = GetServant(aIter);
4392 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4394 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4395 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4398 // -> save boundaries
4399 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4400 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4401 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4402 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4403 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4404 if (aBoundaryServant) {
4405 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4406 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4410 MESSAGE ("close file");
4413 // put temporary files to the stream
4414 MESSAGE ("put temporary files to the stream");
4415 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
4417 // remove temporary files
4418 MESSAGE ("remove temporary files");
4419 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4421 // return data stream
4422 MESSAGE ("return data stream");
4423 return aStreamFile._retn();
4426 //===========================================================================
4427 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4429 CORBA::Boolean isMultiFile)
4431 // No specific ASCII persistence
4432 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4433 return aStreamFile._retn();
4436 //===========================================================================
4437 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4438 const SALOMEDS::TMPFile& theStream,
4440 CORBA::Boolean isMultiFile)
4442 MESSAGE ("Load pour theURL = "<< theURL);
4443 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4445 // set current study
4446 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
4447 SetCurrentStudy(aStudy);
4449 // get temporary directory name
4450 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4452 // Convert the stream into sequence of files to process
4453 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4456 // HOMARD data file name
4457 std::string aFileName = "";
4459 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4460 aFileName = tmpDir + aFileName + "_HOMARD.dat";
4462 StudyContext& context = myContextMap[ aStudy->StudyId() ];
4466 std::ifstream f(aFileName.c_str());
4469 context._mesCas.clear();
4470 context._mesHypotheses.clear();
4471 context._mesIterations.clear();
4472 context._mesZones.clear();
4473 context._mesBoundarys.clear();
4474 context._idmap.clear();
4480 std::getline(f, line);
4481 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4482 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4483 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4484 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4485 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4486 std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4487 if (line.substr(0, bounSignature.size()) == bounSignature) {
4488 // re-create boundary
4489 MESSAGE ("Recreation de la frontiere" );
4490 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4491 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4492 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4493 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4494 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4495 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4498 else if (line.substr(0, caseSignature.size()) == caseSignature) {
4500 MESSAGE ("Recreation du cas" );
4501 HOMARD::HOMARD_Cas_var aCase = newCase();
4502 PortableServer::ServantBase_var aServant = GetServant(aCase);
4503 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4504 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4505 context._mesCas[aCase->GetName()] = aCase;
4506 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4509 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4510 // re-create hypothesis
4511 MESSAGE ("Recreation de l hypothese" );
4512 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4513 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4514 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4515 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4516 context._mesHypotheses[aHypo->GetName()] = aHypo;
4517 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4520 else if (line.substr(0, iterSignature.size()) == iterSignature) {
4521 // re-create iteration
4522 MESSAGE ("Recreation de l'iteration" );
4523 HOMARD::HOMARD_Iteration_var aIter = newIteration();
4524 PortableServer::ServantBase_var aServant = GetServant(aIter);
4525 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4526 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4527 context._mesIterations[aIter->GetName()] = aIter;
4528 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4531 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4532 MESSAGE ("Recreation de la zone" );
4534 HOMARD::HOMARD_Zone_var aZone = newZone();
4535 PortableServer::ServantBase_var aServant = GetServant(aZone);
4536 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4537 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4538 context._mesZones[aZone->GetName()] = aZone;
4539 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4542 else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4543 MESSAGE ("Recreation du schema YACS" );
4545 HOMARD::HOMARD_YACS_var aYACS = newYACS();
4546 PortableServer::ServantBase_var aServant = GetServant(aYACS);
4547 HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4548 if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4549 context._mesYACSs[aYACS->GetName()] = aYACS;
4550 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4559 // Remove temporary files created from the stream
4561 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4566 //===========================================================================
4567 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4568 const SALOMEDS::TMPFile& theStream,
4570 CORBA::Boolean isMultiFile)
4572 // No specific ASCII persistence
4573 return Load(theComponent, theStream, theURL, isMultiFile);
4576 //===========================================================================
4577 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4579 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
4580 // clearing study context should be done here:
4581 // - destroy all servants and related CORBA objects
4583 // - remove context from myContextMap
4584 myContextMap.erase(theComponent->GetStudy()->StudyId());
4585 // - nullify myCurrentStudy
4586 myCurrentStudy = SALOMEDS::Study::_nil();
4590 //===========================================================================
4591 char* HOMARD_Gen_i::ComponentDataType()
4593 return CORBA::string_dup("HOMARD");
4596 //===========================================================================
4597 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4598 const char* IORString,
4599 CORBA::Boolean isMultiFile,
4600 CORBA::Boolean isASCII)
4602 CORBA::String_var aString("");
4603 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4604 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4605 CORBA::Object_var anObj = _orb->string_to_object(IORString);
4606 if (!CORBA::is_nil(anObj)) {
4607 PortableServer::ServantBase_var aServant = GetServant(anObj);
4608 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4610 std::map<int, PortableServer::ServantBase*>::const_iterator it;
4611 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4612 if (it->second == aStorable) {
4613 std::stringstream os;
4615 aString = CORBA::string_dup(os.str().c_str());
4621 return aString._retn();
4624 //===========================================================================
4625 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4626 const char* aLocalPersistentID,
4627 CORBA::Boolean isMultiFile,
4628 CORBA::Boolean isASCII)
4630 CORBA::String_var aString("");
4631 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4632 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4633 int id = atoi(aLocalPersistentID);
4634 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4635 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4636 if (!CORBA::is_nil(object)) {
4637 aString = _orb->object_to_string(object);
4641 return aString._retn();
4644 //===========================================================================
4645 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4647 if(CORBA::is_nil(myCurrentStudy))
4650 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4651 if(!aCas->_is_nil())
4654 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4655 if(!aHypo->_is_nil())
4658 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4659 if(!aZone->_is_nil())
4662 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4663 if(!aBoundary->_is_nil())
4666 /* Iteration is not published directly
4667 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4668 if(!aIter->_is_nil())
4674 //===========================================================================
4675 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4677 // No Copy/Paste support
4681 //===========================================================================
4682 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4683 CORBA::Long& theObjectID)
4685 // No Copy/Paste support
4686 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4687 return aStreamFile._retn();
4690 //===========================================================================
4691 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
4692 CORBA::Long theObjectID)
4694 // No Copy/Paste support
4698 //===========================================================================
4699 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4700 CORBA::Long theObjectID,
4701 SALOMEDS::SObject_ptr theSObject)
4703 // No Copy/Paste support
4704 SALOMEDS::SObject_var aResultSO;
4705 return aResultSO._retn();
4708 //===========================================================================
4709 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4711 PortableServer::Servant aServant = 0;
4712 if (!CORBA::is_nil(theObject)) {
4714 aServant = _poa->reference_to_servant(theObject);
4722 //==========================================================================
4723 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4724 CORBA::Boolean isPublished,
4725 CORBA::Boolean isMultiFile,
4726 CORBA::Boolean& isValidScript)
4728 MESSAGE ("Entree dans DumpPython");
4730 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
4731 if(CORBA::is_nil(aStudy))
4732 return new Engines::TMPFile(0);
4734 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
4735 if(CORBA::is_nil(aSO))
4736 return new Engines::TMPFile(0);
4738 std::string aScript = "\"\"\"\n";
4739 aScript += "Python script for HOMARD\n";
4740 aScript += "Copyright EDF-R&D 1996, 2011, 2014\n";
4741 aScript += "\"\"\"\n";
4742 aScript += "__revision__ = \"V1.2\"\n";
4743 aScript += "import HOMARD\n";
4745 aScript += "import salome\n";
4746 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4748 aScript += "def RebuildData(theStudy):\n";
4749 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
4752 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
4753 MESSAGE (". Au depart \n"<<aScript);
4756 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
4758 MESSAGE (". Ecritures des frontieres");
4759 aScript += "#\n# Creation of the boundaries";
4760 aScript += "\n# ==========================";
4762 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4763 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
4764 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
4766 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4767 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4768 std::string dumpBoundary = dumpCorbaBoundary.in();
4769 MESSAGE (dumpBoundary<<"\n");
4770 aScript += dumpBoundary;
4774 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
4776 MESSAGE (". Ecritures des zones");
4777 aScript += "#\n# Creation of the zones";
4778 aScript += "\n# =====================";
4780 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4781 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
4782 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
4784 HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
4785 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4786 std::string dumpZone = dumpCorbaZone.in();
4787 MESSAGE (dumpZone<<"\n");
4788 aScript += dumpZone;
4792 if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
4794 MESSAGE (". Ecritures des hypotheses");
4795 aScript += "#\n# Creation of the hypotheses";
4796 aScript += "\n# ==========================";
4798 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4799 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
4800 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
4802 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
4803 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
4804 std::string dumpHypo = dumpCorbaHypo.in();
4805 MESSAGE (dumpHypo<<"\n");
4806 aScript += dumpHypo;
4810 if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
4812 MESSAGE (". Ecritures des cas");
4813 aScript += "#\n# Creation of the cases";
4814 aScript += "\n# =====================";
4816 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
4817 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4818 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
4820 std::string nomCas = (*it_cas).first;
4821 std::string dumpCas = std::string("\n# Creation of the case ") ;
4822 dumpCas += nomCas + std::string("\n");
4823 dumpCas += std::string("\t") + nomCas;
4824 dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
4826 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
4827 CORBA::String_var cIter0= myCase->GetIter0Name();
4828 std::string iter0 = cIter0.in();
4830 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
4831 CORBA::String_var cMesh0= myIteration->GetMeshFile();
4832 std::string mesh0 = cMesh0.in();
4833 CORBA::String_var cMeshName0= myIteration->GetMeshName();
4834 std::string meshName0 = cMeshName0.in();
4835 dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
4836 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4837 std::string dumpCas2= dumpCorbaCase.in();
4839 MESSAGE (dumpCas<<dumpCas2<<"\n");
4840 aScript += dumpCas + dumpCas2;
4844 if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
4846 MESSAGE (". Ecritures des iterations");
4847 aScript += "#\n# Creation of the iterations" ;
4848 aScript += "\n# ==========================";
4850 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4851 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
4852 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
4854 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
4855 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
4856 std::string dumpIter = dumpCorbaIter.in();
4857 MESSAGE (dumpIter<<"\n");
4858 aScript += dumpIter;
4862 if (myContextMap[GetCurrentStudyID()]._mesYACSs.size() > 0)
4864 MESSAGE (". Ecritures des schemas YACS");
4865 aScript += "#\n# Creation of the schemas YACS";
4866 aScript += "\n# ============================";
4868 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
4869 for ( it_yacs = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
4870 it_yacs != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); ++it_yacs)
4872 HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
4873 CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
4874 std::string dumpYACS = dumpCorbaYACS.in();
4875 MESSAGE (dumpYACS<<"\n");
4876 aScript += dumpYACS;
4879 MESSAGE (". Ecritures finales");
4881 aScript += "\n\tpass";
4884 if( !isMultiFile ) // remove unnecessary tabulation
4885 aScript = RemoveTabulation( aScript );
4887 // MESSAGE ("A ecrire \n"<<aScript);
4888 const size_t aLen = strlen(aScript.c_str());
4889 char* aBuffer = new char[aLen+1];
4890 strcpy(aBuffer, aScript.c_str());
4892 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
4893 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
4895 MESSAGE ("Sortie de DumpPython");
4896 return aStreamFile._retn();
4900 //=============================================================================
4901 //=============================================================================
4903 //=============================================================================
4904 //=============================================================================
4905 void HOMARD_Gen_i::IsValidStudy( )
4907 // MESSAGE( "IsValidStudy" );
4908 if (CORBA::is_nil(myCurrentStudy))
4910 SALOME::ExceptionStruct es;
4911 es.type = SALOME::BAD_PARAM;
4912 es.text = "Invalid study context";
4913 throw SALOME::SALOME_Exception(es);
4918 //=============================================================================
4919 char* HOMARD_Gen_i::VerifieDir(const char* nomDir)
4921 std::string casename = std::string("") ;
4922 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
4923 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4924 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
4926 if (std::string(nomDir) == std::string(it->second->GetDirName()))
4928 casename = std::string(it->second->GetName()) ;
4932 return CORBA::string_dup( casename.c_str() );
4934 /*//=============================================================================
4935 void SALOMEException( std::string message )
4937 SALOME::ExceptionStruct es;
4938 es.type = SALOME::BAD_PARAM;
4940 throw SALOME::SALOME_Exception(es);
4943 //=============================================================================
4944 char* HOMARD_Gen_i::getVersion()
4946 #if HOMARD_DEVELOPMENT
4947 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
4949 return CORBA::string_dup(HOMARD_VERSION_STR);
4952 //===============================================================================
4953 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un caractere
4954 // ligne : la ligne a manipuler
4955 // caractere : le caractere a reperer
4956 // option : 0 : la chaine avant la premiere apparition du caractere
4957 // 1 : la chaine apres la premiere apparition du caractere
4958 // 2 : la chaine avant la derniere apparition du caractere
4959 // 3 : la chaine apres la derniere apparition du caractere
4960 // Si le caractere est absent, on retourne la chaine totale
4961 //===============================================================================
4962 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string caractere, int option )
4964 // MESSAGE("GetStringInTexte, recherche de '"<<caractere<<"' dans '"<<ligne<<"'"<<", option = "<<option);
4966 std::string chaine = ligne ;
4968 if ( option < 2 ) { position = ligne.find_first_of( caractere ) ; }
4969 else { position = ligne.find_last_of( caractere ) ; }
4970 // MESSAGE("position = "<<position);
4971 // MESSAGE("a = "<<ligne.substr( 0, position ).c_str());
4972 // MESSAGE("b = "<<ligne.substr( position+1 ).c_str());
4974 if ( position != std::string::npos )
4976 if ( ( option == 0 ) || ( option == 2 ) ) { chaine = ligne.substr( 0, position ) ; }
4977 else { chaine = ligne.substr( position+1 ) ; }
4982 //=============================================================================
4983 //=============================================================================
4984 // Gestion des preferences
4985 //=============================================================================
4986 //=============================================================================
4987 // Decodage du fichier d'arcihvage des preferences
4989 void HOMARD_Gen_i::SetPreferences( )
4991 MESSAGE ( "SetPreferences" );
4993 std::string ligne, mot_cle, salome_version ;
4996 // A. Les valeurs par defaut ; elles doivent etre coherentes
4997 std::string LanguageShort = "en" ;
4998 int PublisMeshIN = 0 ;
4999 int PublisMeshOUT = 0 ;
5000 int YACSMaxIter = 0 ;
5001 int YACSMaxNode = 0 ;
5002 int YACSMaxElem = 0 ;
5003 std::string YACSTypeTestchaine = "None" ;
5005 // B. La version de salome
5006 // Cela se presente sous la forme :
5007 // [SALOME KERNEL] : 7.3.0
5009 File = getenv("KERNEL_ROOT_DIR") ;
5010 File += "/bin/salome/VERSION" ;
5011 MESSAGE ( "File = "<<File ) ;
5012 std::ifstream fichier0( File.c_str() ) ;
5013 if ( fichier0 ) // ce test échoue si le fichier n'est pas ouvert
5015 std::string ligne; // variable contenant chaque ligne lue
5016 while ( std::getline( fichier0, ligne ) )
5018 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5019 ligne_bis >> mot_cle ;
5020 if ( mot_cle == "[SALOME" )
5022 salome_version = GetStringInTexte ( ligne, " ", 3 ) ;
5023 // MESSAGE ( "salome_version = "<<salome_version<<"|||");
5028 else { ok = false ; }
5030 // B. Decodage du fichier de preferences
5033 std::string PrefFile ;
5034 PrefFile = getenv("HOME") ;
5035 PrefFile += "/.config/salome/SalomeApprc." + salome_version ;
5036 MESSAGE ( "PrefFile = "<<PrefFile ) ;
5038 std::ifstream fichier( PrefFile.c_str() );
5039 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
5041 bool section_langue = false ;
5042 bool section_homard = false ;
5043 while ( std::getline( fichier, ligne ) )
5045 std::string chaine ;
5046 // 1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
5047 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5048 ligne_bis >> mot_cle ;
5051 // 2.1. Debut d'une section
5052 // MESSAGE(mot_cle);
5053 if ( mot_cle == "<section" )
5054 { /*MESSAGE ( "Debut de la section : "<< ligne);*/
5055 ligne_bis >> mot_cle ;
5056 chaine = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5057 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5058 if ( chaine == "language" ) { section_langue = true ; }
5059 if ( chaine == "HOMARD" ) { section_homard = true ; }
5060 // MESSAGE ( "section_langue = "<<section_langue<<", section_homard = "<<section_homard);
5062 // 2.2. Fin d'une section
5063 else if ( mot_cle == "</section>" )
5064 { /*MESSAGE ( "Fin de la section : "<< ligne<<", section_langue = "<<section_langue<<", section_homard = "<<section_homard);*/
5065 section_langue = false ;
5066 section_homard = false ; }
5070 else if ( section_langue || section_homard )
5071 { MESSAGE ( "a decoder : "<< ligne);
5072 // La valeur : entre les deux premieres quotes
5073 chaine = GetStringInTexte ( ligne, "\"", 1 ) ;
5074 // MESSAGE("chaine 1 = |"<<chaine<<"|");
5075 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5076 // MESSAGE("chaine = |"<<chaine<<"|");
5077 // Le mot_cle : entre les deux dernieres quotes
5078 std::string chaine2 = GetStringInTexte ( ligne, "\"", 2 ) ;
5079 // MESSAGE("chaine2 1 = |"<<chaine2<<"|");
5080 chaine2 = GetStringInTexte ( chaine2, "\"", 3 ) ;
5081 // MESSAGE("chaine2 = |"<<chaine2<<"|");
5083 if ( section_langue )
5084 { if ( chaine2 == "language" ) { LanguageShort = chaine ; } }
5086 if ( section_homard )
5088 std::istringstream chainebis( chaine ) ;
5089 // 3.2.1. Les publications
5090 if ( chaine2 == "publish_mesh_in" ) { chainebis >> PublisMeshIN ; }
5091 if ( chaine2 == "publish_mesh_out" ) { chainebis >> PublisMeshOUT ; }
5092 // 3.2.2. Les maximum pour YACS
5093 if ( chaine2 == "yacs_max_iter" ) { chainebis >> YACSMaxIter ; }
5094 if ( chaine2 == "yacs_max_node" ) { chainebis >> YACSMaxNode ; }
5095 if ( chaine2 == "yacs_max_elem" ) { chainebis >> YACSMaxElem ; }
5096 if ( chaine2 == "yacs_type_test" ) { YACSTypeTestchaine = chaine ; }
5103 // C. Enregistrements
5104 MESSAGE ("Enregistrement de LanguageShort = " << LanguageShort );
5105 SetLanguageShort( LanguageShort.c_str() ) ;
5107 MESSAGE ("Enregistrement de PublisMeshIN = " << PublisMeshIN<<", PublisMeshOUT = "<< PublisMeshOUT);
5108 SetPublisMesh(PublisMeshIN, PublisMeshOUT) ;
5110 MESSAGE ("Enregistrement de YACSMaxIter = " << YACSMaxIter<<", YACSMaxNode = "<< YACSMaxNode<<", YACSMaxElem = "<< YACSMaxElem);
5111 SetYACSMaximum(YACSMaxIter, YACSMaxNode, YACSMaxElem) ;
5113 MESSAGE ("Enregistrement de TypeTest = " << YACSTypeTestchaine.c_str() );
5115 if ( ( YACSTypeTestchaine == "VTest > VRef" ) || ( YACSTypeTestchaine == "VTest > VRef" ) ) { YACSTypeTest = 1 ; }
5116 else if ( ( YACSTypeTestchaine == "VTest < VRef" ) || ( YACSTypeTestchaine == "VTest < VRef" ) ) { YACSTypeTest = 2 ; }
5117 else { YACSTypeTest = 0 ; }
5118 MESSAGE ("==> TypeTest = " << YACSTypeTest );
5119 SetYACSConvergenceType( YACSTypeTest ) ;
5123 //===============================================================================
5125 //===============================================================================
5126 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
5128 // MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
5129 _LangueShort = LanguageShort ;
5130 if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
5131 else { _Langue = "English" ; }
5134 char* HOMARD_Gen_i::GetLanguageShort()
5136 // MESSAGE ("GetLanguageShort");
5137 return CORBA::string_dup( _LangueShort.c_str() );
5139 //===============================================================================
5140 // Options de publications
5141 //===============================================================================
5142 void HOMARD_Gen_i::SetPublisMesh(CORBA::Long PublisMeshIN, CORBA::Long PublisMeshOUT)
5144 _PublisMeshIN = PublisMeshIN ;
5145 _PublisMeshOUT = PublisMeshOUT ;
5148 CORBA::Long HOMARD_Gen_i::GetPublisMeshIN()
5150 return _PublisMeshIN ;
5152 CORBA::Long HOMARD_Gen_i::GetPublisMeshOUT()
5154 return _PublisMeshOUT ;
5156 //===============================================================================
5157 // YACS - test de convergence
5158 //===============================================================================
5159 void HOMARD_Gen_i::SetYACSMaximum(CORBA::Long YACSMaxIter, CORBA::Long YACSMaxNode, CORBA::Long YACSMaxElem)
5161 _YACSMaxIter = YACSMaxIter ;
5162 _YACSMaxNode = YACSMaxNode ;
5163 _YACSMaxElem = YACSMaxElem ;
5166 CORBA::Long HOMARD_Gen_i::GetYACSMaxIter()
5168 return _YACSMaxIter ;
5170 CORBA::Long HOMARD_Gen_i::GetYACSMaxNode()
5172 return _YACSMaxNode ;
5174 CORBA::Long HOMARD_Gen_i::GetYACSMaxElem()
5176 return _YACSMaxElem ;
5178 void HOMARD_Gen_i::SetYACSConvergenceType(CORBA::Long YACSTypeTest)
5180 _YACSTypeTest = YACSTypeTest ;
5183 CORBA::Long HOMARD_Gen_i::GetYACSConvergenceType()
5185 return _YACSTypeTest ;
5188 //=============================================================================
5192 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
5193 PortableServer::POA_ptr poa,
5194 PortableServer::ObjectId* contId,
5195 const char* instanceName,
5196 const char* interfaceName)
5198 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
5199 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
5200 return myHOMARD_Gen->getId();