1 // Copyright (C) 2011-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "HOMARD_Gen_i.hxx"
21 #include "HOMARD_Cas_i.hxx"
22 #include "HOMARD_Hypothesis_i.hxx"
23 #include "HOMARD_Iteration_i.hxx"
24 #include "HOMARD_Boundary_i.hxx"
25 #include "HOMARD_Zone_i.hxx"
26 #include "HOMARD_YACS_i.hxx"
27 #include "HomardDriver.hxx"
28 #include "HOMARD_DriverTools.hxx"
29 #include "HomardMedCommun.h"
30 #include "YACSDriver.hxx"
33 #include "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
1324 // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1325 std::ifstream fichier( file_configuration.c_str() );
1326 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1328 std::string ligne; // variable contenant chaque ligne lue
1329 std::string mot_cle;
1330 std::string argument;
1332 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1333 while ( std::getline( fichier, ligne ) )
1335 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1336 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1337 ligne_bis >> mot_cle ;
1338 // B.2. Des valeurs entieres : le second bloc de la ligne
1339 if ( mot_cle == "NumeIter" )
1341 ligne_bis >> NumeIter ;
1344 // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1345 else if ( ( mot_cle == "TypeConf" ) || ( mot_cle == "TypeElem" ) )
1347 ligne_bis >> argument ;
1349 if ( mot_cle == "TypeConf" )
1351 if ( argument == "conforme" ) { TypeConf = 1 ; }
1352 else if ( argument == "non_conforme_1_noeud" ) { TypeConf = 2 ; }
1353 else if ( argument == "non_conforme_1_arete" ) { TypeConf = 3 ; }
1354 else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1356 else if ( mot_cle == "TypeElem" )
1358 if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1359 else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1362 // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1363 // il faut les supprimer
1364 else if ( ( mot_cle == "CCNoMNP1" ) || ( mot_cle == "CCMaiNP1" ) )
1366 ligne_bis >> argument ;
1367 if ( argument[0] == '"' ) { decalage = 1 ; }
1368 else { decalage = 0 ; }
1369 size_t size = argument.size() + 1 - 2*decalage ;
1371 if ( mot_cle == "CCNoMNP1" )
1373 MeshName = new char[ size ];
1374 strncpy( MeshName, argument.c_str()+decalage, size );
1375 MeshName[size-1] = '\0' ;
1377 else if ( mot_cle == "CCMaiNP1" )
1379 MeshFile = new char[ size ];
1380 strncpy( MeshFile, argument.c_str()+decalage, size );
1381 MeshFile[size-1] = '\0' ;
1385 MESSAGE ( "==> TypeConf : " << TypeConf ) ;
1386 MESSAGE ( "==> MeshName : " << MeshName ) ;
1387 MESSAGE ( "==> MeshFile : " << MeshFile ) ;
1388 MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1389 MESSAGE ( "==> Pyram : " << Pyram ) ;
1393 SALOME::ExceptionStruct es;
1394 es.type = SALOME::BAD_PARAM;
1395 std::string text = "The configuration file cannot be read." ;
1396 es.text = CORBA::string_dup(text.c_str());
1397 throw SALOME::SALOME_Exception(es);
1400 // C. Creation effective du cas
1403 if ( _PublisMeshIN != 0 ) option = 2 ;
1404 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, option) ;
1406 // D. Parametrages lus dans le fichier de configuration
1408 myCase->SetConfType (TypeConf) ;
1409 myCase->SetExtType (TypeExt) ;
1410 myCase->SetPyram (Pyram) ;
1412 // E. Copie du fichier de maillage homard
1413 // E.1. Repertoire associe au cas
1414 char* nomDirCase = myCase->GetDirName() ;
1415 // E.2. Repertoire associe a l'iteration de ce cas
1417 IterName = myCase->GetIter0Name() ;
1418 HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1419 char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1420 Iter->SetDirNameLoc(nomDirIter);
1421 std::string nomDirIterTotal ;
1422 nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1424 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1426 if (_mkdir(nomDirIterTotal.c_str()) != 0)
1429 MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1430 SALOME::ExceptionStruct es;
1431 es.type = SALOME::BAD_PARAM;
1432 std::string text = "The directory for the computation cannot be created." ;
1433 es.text = CORBA::string_dup(text.c_str());
1434 throw SALOME::SALOME_Exception(es);
1436 // E.3. Copie du maillage HOMARD au format MED
1437 codret = CHDIR(DirNameStart) ;
1438 std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1439 MESSAGE ( "commande : " << commande ) ;
1440 codret = system(commande.c_str()) ;
1441 MESSAGE ( "codret : " << codret ) ;
1444 SALOME::ExceptionStruct es;
1445 es.type = SALOME::BAD_PARAM;
1446 es.text = "The starting point for the case cannot be copied into the working directory.";
1447 throw SALOME::SALOME_Exception(es);
1456 CHDIR(nomDirWork.c_str());
1457 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1459 //=============================================================================
1460 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1462 // nomCas : nom du cas a creer
1463 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1466 INFOS ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1468 std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1470 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1471 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1473 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1475 //=============================================================================
1476 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1478 // nomCas : nom du cas a creer
1479 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1480 // Number : numero de l'iteration de depart
1483 INFOS ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1486 SALOME::ExceptionStruct es;
1487 es.type = SALOME::BAD_PARAM;
1488 es.text = "The number of iteration must be positive.";
1489 throw SALOME::SALOME_Exception(es);
1493 std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1495 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1496 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1498 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1500 //=============================================================================
1501 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1503 // Retourne le nom du repertoire ou se trouve l'iteration voulue.
1504 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1505 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1508 MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1509 std::string nomDirWork = getenv("PWD") ;
1510 std::string DirNameStartIter ;
1512 int NumeIterMax = -1 ;
1514 // A.1. Controle du repertoire de depart du cas
1515 codret = CHDIR(DirNameStart) ;
1518 SALOME::ExceptionStruct es;
1519 es.type = SALOME::BAD_PARAM;
1520 es.text = "The directory of the case for the pursuit does not exist.";
1521 throw SALOME::SALOME_Exception(es);
1524 // A.2. Reperage des sous-repertoire du repertoire de reprise
1525 bool existe = false ;
1528 struct dirent *dirp;
1529 dp = opendir(DirNameStart);
1530 while ( (dirp = readdir(dp)) != NULL ) {
1531 std::string DirName_1(dirp->d_name);
1533 HANDLE hFind = INVALID_HANDLE_VALUE;
1534 WIN32_FIND_DATA ffd;
1535 hFind = FindFirstFile(DirNameStart, &ffd);
1536 if (INVALID_HANDLE_VALUE != hFind) {
1537 while (FindNextFile(hFind, &ffd) != 0) {
1538 std::string DirName_1 = "";
1539 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1540 DirName_1 = std::string(ffd.cFileName);
1543 if ( ( DirName_1 != "." ) && ( DirName_1 != ".." ) )
1545 if ( CHDIR(DirName_1.c_str()) == 0 )
1547 // On cherche le fichier de configuration dans ce sous-repertoire
1548 codret = CHDIR(DirNameStart);
1551 struct dirent *dirp_1;
1552 dp_1 = opendir(DirName_1.c_str()) ;
1553 while ( (dirp_1 = readdir(dp_1)) != NULL )
1555 std::string file_name_1(dirp_1->d_name);
1557 HANDLE hFind1 = INVALID_HANDLE_VALUE;
1558 WIN32_FIND_DATA ffd1;
1559 hFind1 = FindFirstFile(DirName_1.c_str(), &ffd1);
1560 while (FindNextFile(hFind1, &ffd1) != 0)
1562 if (ffd1.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1563 std::string file_name_1(ffd1.cFileName);
1565 int bilan = file_name_1.find("HOMARD.Configuration.") ;
1566 if ( bilan != string::npos )
1568 // Decodage du fichier pour trouver le numero d'iteration
1569 CHDIR(DirName_1.c_str()) ;
1571 std::ifstream fichier( file_name_1.c_str() );
1572 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1575 std::string ligne; // variable contenant chaque ligne lue
1576 std::string mot_cle;
1577 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1578 while ( std::getline( fichier, ligne ) )
1580 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1581 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1582 ligne_bis >> mot_cle ;
1583 if ( mot_cle == "NumeIter" )
1585 ligne_bis >> NumeIter ;
1587 // MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1588 if ( Number == - 1 )
1590 if ( NumeIter >= NumeIterMax )
1592 NumeIterMax = NumeIter ;
1593 DirNameStartIter = DirName_1 ;
1598 if ( NumeIter == Number )
1600 DirNameStartIter = DirName_1 ;
1610 SALOME::ExceptionStruct es;
1611 es.type = SALOME::BAD_PARAM;
1612 std::string text = "The configuration file cannot be read." ;
1613 es.text = CORBA::string_dup(text.c_str());
1614 throw SALOME::SALOME_Exception(es);
1616 CHDIR(DirNameStart) ;
1618 if ( existe ) { break ; }
1625 if ( existe ) { break ; }
1634 CHDIR(nomDirWork.c_str());
1636 if ( ( Number >= 0 && ( !existe ) ) || ( Number < 0 && ( NumeIterMax == -1 ) ) )
1638 SALOME::ExceptionStruct es;
1639 es.type = SALOME::BAD_PARAM;
1640 es.text = "The directory of the iteration does not exist.";
1641 throw SALOME::SALOME_Exception(es);
1645 return DirNameStartIter ;
1647 //=============================================================================
1648 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)
1650 // nomCas : nom du cas a creer
1651 // MeshName, MeshFile : nom et fichier du maillage correspondant
1652 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1653 // 1 : le maillage fourni peut ne pas exister ==> on continue si absent
1654 // -1 : le maillage n'est pas fourni
1655 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1656 // Option : multiple de nombres premiers
1657 // 1 : aucune option
1658 // x2 : publication du maillage dans SMESH
1660 MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1661 MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1662 MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1668 // A.2. Controle du nom :
1669 if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
1671 SALOME::ExceptionStruct es;
1672 es.type = SALOME::BAD_PARAM;
1673 es.text = "This case has already been defined.";
1674 throw SALOME::SALOME_Exception(es);
1678 // A.3. Controle du fichier du maillage
1679 int existeMeshFile ;
1680 if ( MeshOption >= 0 )
1682 existeMeshFile = MEDFileExist ( MeshFile ) ;
1683 MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1684 if ( ( existeMeshFile == 0 ) && ( MeshOption == 0 ) )
1686 SALOME::ExceptionStruct es;
1687 es.type = SALOME::BAD_PARAM;
1688 es.text = "The mesh file does not exist.";
1689 throw SALOME::SALOME_Exception(es);
1693 else { existeMeshFile = 0 ; }
1695 // B. Creation de l'objet cas et publication
1696 // MESSAGE ( "CreateCase0 : Creation de l'objet" );
1697 HOMARD::HOMARD_Cas_var myCase = newCase();
1698 myCase->SetName(nomCas);
1699 SALOMEDS::SObject_var aSO;
1700 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
1701 myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
1703 // C. Caracteristiques du maillage
1704 if ( existeMeshFile != 0 )
1706 // Les valeurs extremes des coordonnees
1707 // MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnees" );
1708 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1709 HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1710 if (LesExtremes.size()!=10) { return false; }
1712 for (int i =0 ; i< LesExtremes.size() ; i++)
1713 aSeq[i]=LesExtremes[i] ;
1714 myCase->SetBoundingBox(aSeq) ;
1716 // MESSAGE ( "CreateCase0 : Les groupes" );
1717 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile) ;
1718 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1719 aSeqGroupe->length(LesGroupes.size());
1720 std::set<std::string>::const_iterator it ;
1722 for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1723 aSeqGroupe[i++]=(*it).c_str() ;
1724 myCase->SetGroups(aSeqGroupe) ;
1727 // D. L'iteration initiale du cas
1728 MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1729 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1730 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1732 std::string NomIteration = std::string(MeshName) ;
1733 while ( (myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()) )
1735 std::ostringstream nom;
1736 nom << MeshName << monNum;
1737 NomIteration = nom.str();
1740 MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1742 // D.2. Creation de l'iteration
1743 HOMARD::HOMARD_Iteration_var anIter = newIteration();
1744 myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration] = anIter;
1745 anIter->SetName(NomIteration.c_str());
1746 AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1748 // D.4. Maillage correspondant
1749 if ( existeMeshFile != 0 )
1751 anIter->SetMeshFile(MeshFile);
1752 if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1754 anIter->SetMeshName(MeshName);
1756 // D.5. Numero d'iteration
1757 anIter->SetNumber(NumeIter);
1760 SetEtatIter(NomIteration.c_str(), -NumeIter);
1763 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1765 //=============================================================================
1766 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1768 INFOS ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1771 // A. Controle du nom :
1772 if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
1774 SALOME::ExceptionStruct es;
1775 es.type = SALOME::BAD_PARAM;
1776 es.text = "This hypothesis has already been defined.";
1777 throw SALOME::SALOME_Exception(es);
1781 // B. Creation de l'objet
1782 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1783 if (CORBA::is_nil(myHypothesis))
1785 SALOME::ExceptionStruct es;
1786 es.type = SALOME::BAD_PARAM;
1787 es.text = "Unable to create the hypothesis";
1788 throw SALOME::SALOME_Exception(es);
1791 myHypothesis->SetName(nomHypothesis);
1793 // C. Enregistrement
1794 myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
1796 SALOMEDS::SObject_var aSO;
1797 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
1799 // D. Valeurs par defaut des options avancees
1800 myHypothesis->SetNivMax(-1);
1801 myHypothesis->SetDiamMin(-1.0);
1802 myHypothesis->SetAdapInit(0);
1803 myHypothesis->SetExtraOutput(1);
1805 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1808 //=============================================================================
1809 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1810 //=============================================================================
1812 INFOS ("CreateIteration : NomIteration = " << NomIteration << ", nomIterParent = " << nomIterParent);
1815 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
1816 if (CORBA::is_nil(myIterationParent))
1818 SALOME::ExceptionStruct es;
1819 es.type = SALOME::BAD_PARAM;
1820 es.text = "The parent iteration is not defined.";
1821 throw SALOME::SALOME_Exception(es);
1825 const char* nomCas = myIterationParent->GetCaseName();
1826 MESSAGE ("CreateIteration : nomCas = " << nomCas);
1827 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1828 if (CORBA::is_nil(myCase))
1830 SALOME::ExceptionStruct es;
1831 es.type = SALOME::BAD_PARAM;
1832 es.text = "Invalid case context";
1833 throw SALOME::SALOME_Exception(es);
1836 const char* nomDirCase = myCase->GetDirName();
1838 // Controle du nom :
1839 if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
1841 SALOME::ExceptionStruct es;
1842 es.type = SALOME::BAD_PARAM;
1843 es.text = "This iteration has already been defined.";
1844 throw SALOME::SALOME_Exception(es);
1848 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1849 if (CORBA::is_nil(myIteration))
1851 SALOME::ExceptionStruct es;
1852 es.type = SALOME::BAD_PARAM;
1853 es.text = "Unable to create the iteration";
1854 throw SALOME::SALOME_Exception(es);
1857 myContextMap[GetCurrentStudyID()]._mesIterations[std::string(NomIteration)] = myIteration;
1858 // Nom de l'iteration et du maillage
1859 myIteration->SetName(NomIteration);
1860 myIteration->SetMeshName(NomIteration);
1861 myIteration->SetState(1);
1863 int numero = myIterationParent->GetNumber() + 1;
1864 myIteration->SetNumber(numero);
1866 // Nombre d'iterations deja connues pour le cas, permettant
1867 // la creation d'un sous-repertoire unique
1868 int nbitercase = myCase->GetNumberofIter();
1869 char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1870 myIteration->SetDirNameLoc(nomDirIter);
1872 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1873 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1874 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1875 // situation la plus frequente.
1876 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1877 // le nombre d'iterations du cas permet d'eviter les collisions.
1879 if ( nbitercase < 100 ) { jaux = 2 ; }
1880 else if ( nbitercase < 1000 ) { jaux = 3 ; }
1881 else if ( nbitercase < 10000 ) { jaux = 4 ; }
1882 else if ( nbitercase < 100000 ) { jaux = 5 ; }
1884 std::ostringstream iaux ;
1885 iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1886 std::stringstream MeshFile;
1887 MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1888 myIteration->SetMeshFile(MeshFile.str().c_str());
1890 // Association avec le cas
1891 std::string label = "IterationHomard_" + std::string(nomIterParent);
1892 AssociateCaseIter(nomCas, NomIteration, label.c_str());
1893 // Lien avec l'iteration precedente
1894 myIterationParent->LinkNextIteration(NomIteration);
1895 myIteration->SetIterParentName(nomIterParent);
1896 // Gestion de l'arbre d'etudes
1897 SALOMEDS::SObject_var aIterSOParent = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIterationParent)));
1898 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
1899 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1900 aStudyBuilder->NewCommand();
1901 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
1902 aStudyBuilder->Addreference(aSubSO, aIterSOParent);
1903 aStudyBuilder->CommitCommand();
1905 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1907 //=============================================================================
1908 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1910 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1913 // Controle du nom :
1914 if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
1916 MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1917 SALOME::ExceptionStruct es;
1918 es.type = SALOME::BAD_PARAM;
1919 es.text = "This boundary has already been defined";
1920 throw SALOME::SALOME_Exception(es);
1924 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1925 myBoundary->SetName(BoundaryName);
1926 myBoundary->SetType(BoundaryType);
1928 myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
1930 SALOMEDS::SObject_var aSO;
1931 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
1933 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1935 //=============================================================================
1936 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1938 INFOS ("CreateBoundaryDi : BoundaryName = " << BoundaryName << ", MeshName = " << MeshName );
1939 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1940 myBoundary->SetMeshFile( MeshFile ) ;
1941 myBoundary->SetMeshName( MeshName ) ;
1943 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1945 //=============================================================================
1946 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1947 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1948 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1949 CORBA::Double Rayon)
1951 INFOS ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
1953 SALOME::ExceptionStruct es;
1956 { es.text = "The radius must be positive." ;
1958 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1959 if ( daux < 0.0000001 )
1960 { es.text = "The axis must be a non 0 vector." ;
1964 es.type = SALOME::BAD_PARAM;
1965 throw SALOME::SALOME_Exception(es);
1969 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1970 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1972 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1974 //=============================================================================
1975 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1976 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1977 CORBA::Double Rayon)
1979 INFOS ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
1981 SALOME::ExceptionStruct es;
1984 { es.text = "The radius must be positive." ;
1988 es.type = SALOME::BAD_PARAM;
1989 throw SALOME::SALOME_Exception(es);
1993 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1994 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1996 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1998 //=============================================================================
1999 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
2000 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
2001 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
2003 INFOS ("CreateBoundaryConeA : BoundaryName = " << BoundaryName ) ;
2005 SALOME::ExceptionStruct es;
2007 if ( Angle <= 0.0 || Angle >= 90.0 )
2008 { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
2010 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2011 if ( daux < 0.0000001 )
2012 { es.text = "The axis must be a non 0 vector." ;
2016 es.type = SALOME::BAD_PARAM;
2017 throw SALOME::SALOME_Exception(es);
2021 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
2022 myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
2024 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2026 //=============================================================================
2027 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
2028 CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
2029 CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
2031 INFOS ("CreateBoundaryConeR : BoundaryName = " << BoundaryName ) ;
2033 SALOME::ExceptionStruct es;
2035 if ( Rayon1 < 0.0 || Rayon2 < 0.0 )
2036 { es.text = "The radius must be positive." ;
2038 double daux = fabs(Rayon2-Rayon1) ;
2039 if ( daux < 0.0000001 )
2040 { es.text = "The radius must be different." ;
2042 daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
2043 if ( daux < 0.0000001 )
2044 { es.text = "The centers must be different." ;
2048 es.type = SALOME::BAD_PARAM;
2049 throw SALOME::SALOME_Exception(es);
2053 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
2054 myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
2056 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2058 //=============================================================================
2059 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryTorus(const char* BoundaryName,
2060 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2061 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2062 CORBA::Double RayonRev, CORBA::Double RayonPri)
2064 INFOS ("CreateBoundaryTorus : BoundaryName = " << BoundaryName ) ;
2066 SALOME::ExceptionStruct es;
2068 if ( ( RayonRev <= 0.0 ) || ( RayonPri <= 0.0 ) )
2069 { es.text = "The radius must be positive." ;
2071 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2072 if ( daux < 0.0000001 )
2073 { es.text = "The axis must be a non 0 vector." ;
2077 es.type = SALOME::BAD_PARAM;
2078 throw SALOME::SALOME_Exception(es);
2082 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 5) ;
2083 myBoundary->SetTorus( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, RayonRev, RayonPri ) ;
2085 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2087 //=============================================================================
2088 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
2090 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
2093 // Controle du nom :
2094 if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
2096 SALOME::ExceptionStruct es;
2097 es.type = SALOME::BAD_PARAM;
2098 es.text = "This zone has already been defined";
2099 throw SALOME::SALOME_Exception(es);
2103 HOMARD::HOMARD_Zone_var myZone = newZone();
2104 myZone->SetName(ZoneName);
2105 myZone->SetType(ZoneType);
2107 myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
2109 SALOMEDS::SObject_var aSO;
2110 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
2112 return HOMARD::HOMARD_Zone::_duplicate(myZone);
2114 //=============================================================================
2115 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
2116 CORBA::Double Xmini, CORBA::Double Xmaxi,
2117 CORBA::Double Ymini, CORBA::Double Ymaxi,
2118 CORBA::Double Zmini, CORBA::Double Zmaxi)
2120 INFOS ("CreateZoneBox : ZoneName = " << ZoneName ) ;
2122 SALOME::ExceptionStruct es;
2124 if ( Xmini > Xmaxi )
2125 { es.text = "The X coordinates are not coherent." ;
2127 if ( Ymini > Ymaxi )
2128 { es.text = "The Y coordinates are not coherent." ;
2130 if ( Zmini > Zmaxi )
2131 { es.text = "The Z coordinates are not coherent." ;
2135 es.type = SALOME::BAD_PARAM;
2136 throw SALOME::SALOME_Exception(es);
2140 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
2141 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2143 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2145 //=============================================================================
2146 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
2147 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
2149 INFOS ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
2151 SALOME::ExceptionStruct es;
2154 { es.text = "The radius must be positive." ;
2158 es.type = SALOME::BAD_PARAM;
2159 throw SALOME::SALOME_Exception(es);
2163 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
2164 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2166 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2168 //=============================================================================
2169 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
2170 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2171 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2172 CORBA::Double Rayon, CORBA::Double Haut)
2174 INFOS ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
2176 SALOME::ExceptionStruct es;
2179 { es.text = "The radius must be positive." ;
2181 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2182 if ( daux < 0.0000001 )
2183 { es.text = "The axis must be a non 0 vector." ;
2186 { es.text = "The height must be positive." ;
2190 es.type = SALOME::BAD_PARAM;
2191 throw SALOME::SALOME_Exception(es);
2195 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
2196 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
2198 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2200 //=============================================================================
2201 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
2202 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2203 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2204 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
2206 INFOS ("CreateZonePipe : ZoneName = " << ZoneName ) ;
2208 SALOME::ExceptionStruct es;
2210 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2211 { es.text = "The radius must be positive." ;
2213 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2214 if ( daux < 0.0000001 )
2215 { es.text = "The axis must be a non 0 vector." ;
2218 { es.text = "The height must be positive." ;
2220 if ( Rayon <= Rayonint )
2221 { es.text = "The external radius must be higher than the internal radius." ;
2225 es.type = SALOME::BAD_PARAM;
2226 throw SALOME::SALOME_Exception(es);
2230 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
2231 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
2233 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2235 //=============================================================================
2236 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
2237 CORBA::Double Umini, CORBA::Double Umaxi,
2238 CORBA::Double Vmini, CORBA::Double Vmaxi,
2241 INFOS ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
2242 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
2243 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
2244 // MESSAGE ("Orient = " << Orient ) ;
2246 SALOME::ExceptionStruct es;
2248 if ( Umini > Umaxi )
2249 { es.text = "The first coordinates are not coherent." ;
2251 if ( Vmini > Vmaxi )
2252 { es.text = "The second coordinates are not coherent." ;
2254 if ( Orient < 1 || Orient > 3 )
2255 { es.text = "The orientation must be 1, 2 or 3." ;
2259 es.type = SALOME::BAD_PARAM;
2260 throw SALOME::SALOME_Exception(es);
2264 double Xmini, Xmaxi ;
2265 double Ymini, Ymaxi ;
2266 double Zmini, Zmaxi ;
2274 else if ( Orient == 2 )
2281 else if ( Orient == 3 )
2288 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2290 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2291 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2293 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2295 //=============================================================================
2296 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2297 CORBA::Double Ucentre, CORBA::Double Vcentre,
2298 CORBA::Double Rayon,
2301 INFOS ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
2303 SALOME::ExceptionStruct es;
2306 { es.text = "The radius must be positive." ;
2308 if ( Orient < 1 || Orient > 3 )
2309 { es.text = "The orientation must be 1, 2 or 3." ;
2313 es.type = SALOME::BAD_PARAM;
2314 throw SALOME::SALOME_Exception(es);
2322 { Xcentre = Ucentre ;
2325 else if ( Orient == 2 )
2328 Zcentre = Vcentre ; }
2329 else if ( Orient == 3 )
2330 { Xcentre = Vcentre ;
2332 Zcentre = Ucentre ; }
2333 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2335 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2336 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2338 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2340 //=============================================================================
2341 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2342 CORBA::Double Ucentre, CORBA::Double Vcentre,
2343 CORBA::Double Rayon, CORBA::Double Rayonint,
2346 INFOS ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
2348 SALOME::ExceptionStruct es;
2350 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2351 { es.text = "The radius must be positive." ;
2353 if ( Orient < 1 || Orient > 3 )
2354 { es.text = "The orientation must be 1, 2 or 3." ;
2356 if ( Rayon <= Rayonint )
2357 { es.text = "The external radius must be higher than the internal radius." ;
2361 es.type = SALOME::BAD_PARAM;
2362 throw SALOME::SALOME_Exception(es);
2370 { Xcentre = Ucentre ;
2373 else if ( Orient == 2 )
2376 Zcentre = Vcentre ; }
2377 else if ( Orient == 3 )
2378 { Xcentre = Vcentre ;
2380 Zcentre = Ucentre ; }
2381 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2383 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2384 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2386 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2388 //=============================================================================
2389 //=============================================================================
2394 //=============================================================================
2395 //=============================================================================
2396 // Traitement d'une iteration
2397 // etatMenage = 1 : destruction du repertoire d'execution
2398 // modeHOMARD = 1 : adaptation
2399 // != 1 : information avec les options modeHOMARD
2400 // Option1 >0 : appel depuis python
2401 // <0 : appel depuis GUI
2402 // Option2 : multiple de nombres premiers
2403 // 1 : aucune option
2404 // x2 : publication du maillage dans SMESH
2405 //=============================================================================
2406 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2408 INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2413 // A.1. L'objet iteration
2414 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
2415 ASSERT(!CORBA::is_nil(myIteration));
2417 // A.2. Controle de la possibilite d'agir
2418 // A.2.1. Etat de l'iteration
2419 int etat = myIteration->GetState();
2420 MESSAGE ( "etat = "<<etat );
2421 // A.2.2. On ne calcule pas l'iteration initiale, ni une iteration deja calculee
2422 if ( modeHOMARD == 1 )
2426 SALOME::ExceptionStruct es;
2427 es.type = SALOME::BAD_PARAM;
2428 es.text = "This iteration is the first of the case and cannot be computed.";
2429 throw SALOME::SALOME_Exception(es);
2432 else if ( ( etat == 2 ) & ( modeHOMARD == 1 ) )
2434 SALOME::ExceptionStruct es;
2435 es.type = SALOME::BAD_PARAM;
2436 es.text = "This iteration is already computed.";
2437 throw SALOME::SALOME_Exception(es);
2441 // A.2.3. On n'analyse pas une iteration non calculee
2446 SALOME::ExceptionStruct es;
2447 es.type = SALOME::BAD_PARAM;
2448 es.text = "This iteration is not computed.";
2449 throw SALOME::SALOME_Exception(es);
2454 // A.3. Numero de l'iteration
2455 // siterp1 : numero de l'iteration a traiter
2457 // siter : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2458 // Ou si information :
2460 int NumeIter = myIteration->GetNumber();
2461 std::string siterp1 ;
2462 std::stringstream saux1 ;
2464 siterp1 = saux1.str() ;
2465 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2468 if ( modeHOMARD==1 )
2470 std::stringstream saux0 ;
2471 int iaux = max(0, NumeIter-1) ;
2473 siter = saux0.str() ;
2474 if (NumeIter < 11) { siter = "0" + siter ; }
2477 { siter = siterp1 ; }
2480 const char* nomCas = myIteration->GetCaseName();
2481 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
2482 ASSERT(!CORBA::is_nil(myCase));
2484 // B. Les repertoires
2485 // B.1. Le repertoire courant
2486 std::string nomDirWork = getenv("PWD") ;
2487 // B.2. Le sous-repertoire de l'iteration a traiter
2488 char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2489 MESSAGE( ". DirCompute = " << DirCompute );
2491 // C. Le fichier des messages
2492 // C.1. Le deroulement de l'execution de HOMARD
2493 std::string LogFile = DirCompute ;
2494 LogFile += "/Liste" ;
2495 if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2497 MESSAGE (". LogFile = " << LogFile);
2498 if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2499 // C.2. Le bilan de l'analyse du maillage
2500 std::string FileInfo = DirCompute ;
2502 if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2504 { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2505 else { FileInfo += "info_ap" ; }
2507 FileInfo += "." + siterp1 + ".bilan" ;
2508 myIteration->SetFileInfo(FileInfo.c_str());
2510 // D. On passe dans le repertoire de l'iteration a calculer
2511 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2514 // E. Les donnees de l'execution HOMARD
2515 // E.1. L'objet du texte du fichier de configuration
2516 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2517 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2519 // E.2. Le maillage associe a l'iteration
2520 const char* NomMesh = myIteration->GetMeshName();
2521 MESSAGE ( ". NomMesh = " << NomMesh );
2522 const char* MeshFile = myIteration->GetMeshFile();
2523 MESSAGE ( ". MeshFile = " << MeshFile );
2525 // E.3. Les donnees du traitement HOMARD
2527 if ( modeHOMARD == 1 )
2530 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2531 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2532 codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2536 InvalideIterInfo(NomIteration);
2537 myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2539 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2540 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2541 myDriver->CreeFichierDonn();
2544 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2545 DriverTexteBoundary(myCase, myDriver) ;
2547 // E.5. Ecriture du texte dans le fichier
2548 MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2550 { myDriver->CreeFichier(); }
2554 int codretexec = 12 ;
2557 codretexec = myDriver->ExecuteHomard(Option1);
2559 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2560 // En mode adaptation, on ajuste l'etat de l'iteration
2561 if ( modeHOMARD == 1 )
2563 if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2564 else { SetEtatIter(NomIteration,1); }
2565 // GERALD -- QMESSAGE BOX
2569 // H. Gestion des resultats
2572 std::string Commentaire ;
2573 // H.1. Le fichier des messages, dans tous les cas
2574 Commentaire = "log" ;
2575 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2576 else { Commentaire += "Info" ; }
2577 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2579 // H.2. Si tout s'est bien passe :
2580 if (codretexec == 0)
2582 // H.2.1. Le fichier de bilan
2583 Commentaire = "Summary" ;
2584 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2585 else { Commentaire += "Info" ; }
2586 PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2587 // H.2.2. Le fichier de maillage obtenu
2588 if ( modeHOMARD == 1 )
2590 std::stringstream saux0 ;
2591 Commentaire = "Mesh" ;
2592 Commentaire += " " + siterp1 ;
2593 PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2594 if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2597 // H.3 Message d'erreur
2598 if (codretexec != 0)
2600 std::string text = "" ;
2601 // Message d'erreur en cas de probleme en adaptation
2602 if ( modeHOMARD == 1 )
2604 text = "Error during the adaptation.\n" ;
2605 bool stopvu = false ;
2606 std::ifstream fichier( LogFile.c_str() );
2607 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
2609 std::string ligne; // variable contenant chaque ligne lue
2610 while ( std::getline( fichier, ligne ) )
2614 { text += ligne+ "\n"; }
2617 int position = ligne.find( "===== HOMARD ===== STOP =====" ) ;
2618 if ( position > 0 ) { stopvu = true ; }
2623 text += "\n\nSee the file " + LogFile + "\n" ;
2625 SALOME::ExceptionStruct es;
2626 es.type = SALOME::BAD_PARAM;
2627 es.text = CORBA::string_dup(text.c_str());
2628 throw SALOME::SALOME_Exception(es);
2630 // En mode information, on force le succes pour pouvoir consulter le fichier log
2631 if ( modeHOMARD != 1 ) { codretexec = 0 ; }
2635 // I. Menage et retour dans le repertoire du cas
2639 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2641 CHDIR(nomDirWork.c_str());
2646 //=============================================================================
2647 // Calcul d'une iteration : partie specifique a l'adaptation
2648 //=============================================================================
2649 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)
2651 MESSAGE ( "ComputeAdap" );
2656 // Numero de l'iteration
2657 int NumeIter = myIteration->GetNumber();
2658 std::stringstream saux0 ;
2659 saux0 << NumeIter-1 ;
2660 std::string siter = saux0.str() ;
2661 if (NumeIter < 11) { siter = "0" + siter ; }
2663 // A.2. On verifie qu il y a une hypothese (erreur improbable);
2664 const char* nomHypo = myIteration->GetHypoName();
2665 if (std::string(nomHypo) == std::string(""))
2667 SALOME::ExceptionStruct es;
2668 es.type = SALOME::BAD_PARAM;
2669 es.text = "This iteration does not have any associated hypothesis.";
2670 throw SALOME::SALOME_Exception(es);
2673 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
2674 ASSERT(!CORBA::is_nil(myHypo));
2676 // B. L'iteration parent
2677 const char* nomIterationParent = myIteration->GetIterParentName();
2678 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2679 ASSERT(!CORBA::is_nil(myIterationParent));
2680 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2681 if ( myIterationParent->GetState() == 1 )
2684 int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2687 // GERALD -- QMESSAGE BOX
2688 VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2692 // C. Le sous-repertoire de l'iteration precedente
2693 char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2694 MESSAGE( ". DirComputePa = " << DirComputePa );
2696 // D. Les donnees de l'adaptation HOMARD
2697 // D.1. Le type de conformite
2698 int ConfType = myCase->GetConfType();
2699 MESSAGE ( ". ConfType = " << ConfType );
2701 // D.1. Le type externe
2702 int ExtType = myCase->GetExtType();
2703 MESSAGE ( ". ExtType = " << ExtType );
2705 // D.3. Le maillage de depart
2706 const char* NomMeshParent = myIterationParent->GetMeshName();
2707 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2708 const char* MeshFileParent = myIterationParent->GetMeshFile();
2709 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2711 // D.4. Le maillage associe a l'iteration
2712 const char* MeshFile = myIteration->GetMeshFile();
2713 MESSAGE ( ". MeshFile = " << MeshFile );
2714 FILE *file = fopen(MeshFile,"r");
2718 if (etatMenage == 0)
2720 SALOME::ExceptionStruct es;
2721 es.type = SALOME::BAD_PARAM;
2722 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2723 es.text = CORBA::string_dup(text.c_str());
2724 throw SALOME::SALOME_Exception(es);
2729 std::string commande = "rm -f " + std::string(MeshFile);
2730 codret = system(commande.c_str());
2733 SALOME::ExceptionStruct es;
2734 es.type = SALOME::BAD_PARAM;
2735 es.text = "The mesh file cannot be deleted.";
2736 throw SALOME::SALOME_Exception(es);
2742 // D.5. Les types de raffinement et de deraffinement
2743 // Les appels corba sont lourds, il vaut mieux les grouper
2744 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2745 ASSERT(ListTypes->length() == 3);
2746 int TypeAdap = (*ListTypes)[0];
2747 int TypeRaff = (*ListTypes)[1];
2748 int TypeDera = (*ListTypes)[2];
2749 // MESSAGE ( ". TypeAdap = " << TypeAdap << ", TypeRaff = " << TypeRaff << ", TypeDera = " << TypeDera );
2751 // E. Texte du fichier de configuration
2752 // E.1. Incontournables du texte
2753 myDriver->TexteAdap(ExtType);
2755 myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2756 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2757 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2759 // E.2. Ajout des informations liees aux zones eventuelles
2760 if ( TypeAdap == 0 )
2761 { DriverTexteZone(myHypo, myDriver) ; }
2763 // E.3. Ajout des informations liees aux champs eventuels
2764 if ( TypeAdap == 1 )
2765 { DriverTexteField(myIteration, myHypo, myDriver) ; }
2767 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2768 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2769 int numberOfGroups = listeGroupes->length();
2770 MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2771 if (numberOfGroups > 0)
2773 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2775 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2776 MESSAGE( "... GroupName = " << GroupName );
2777 myDriver->TexteGroup(GroupName);
2781 // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2782 DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2784 // E.6. Ajout des options avancees
2785 int Pyram = myCase->GetPyram();
2786 MESSAGE ( ". Pyram = " << Pyram );
2787 int NivMax = myHypo->GetNivMax();
2788 MESSAGE ( ". NivMax = " << NivMax );
2789 double DiamMin = myHypo->GetDiamMin() ;
2790 MESSAGE ( ". DiamMin = " << DiamMin );
2791 int AdapInit = myHypo->GetAdapInit();
2792 MESSAGE ( ". AdapInit = " << AdapInit );
2793 int ExtraOutput = myHypo->GetExtraOutput();
2794 MESSAGE ( ". ExtraOutput = " << ExtraOutput );
2795 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, ExtraOutput);
2797 // E.7. Ajout des informations sur le deroulement de l'execution
2798 int MessInfo = myIteration->GetInfoCompute();
2799 MESSAGE ( ". MessInfo = " << MessInfo );
2800 myDriver->TexteInfoCompute(MessInfo);
2804 //=============================================================================
2805 // Creation d'un nom de sous-repertoire pour l'iteration au sein d'un repertoire parent
2806 // nomrep : nom du repertoire parent
2807 // num : le nom du sous-repertoire est sous la forme 'In', n est >= num
2808 //=============================================================================
2809 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
2811 MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2812 // On verifie que le repertoire parent existe
2813 int codret = CHDIR(nomrep) ;
2816 SALOME::ExceptionStruct es;
2817 es.type = SALOME::BAD_PARAM;
2818 es.text = "The directory of the case does not exist.";
2819 throw SALOME::SALOME_Exception(es);
2822 std::string nomDirActuel = getenv("PWD") ;
2823 std::string DirName ;
2824 // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un repertoire inconnu
2825 bool a_chercher = true ;
2826 while ( a_chercher )
2828 // On passe dans le repertoire parent
2831 // On recherche un nom sous la forme Iabc, avec abc representant le numero
2833 if ( num < 100 ) { jaux = 2 ; }
2834 else if ( num < 1000 ) { jaux = 3 ; }
2835 else if ( num < 10000 ) { jaux = 4 ; }
2836 else if ( num < 100000 ) { jaux = 5 ; }
2838 std::ostringstream iaux ;
2839 iaux << std::setw(jaux) << std::setfill('0') << num ;
2840 std::ostringstream DirNameA ;
2841 DirNameA << "I" << iaux.str();
2842 // Si on ne pas peut entrer dans le repertoire, on doit verifier
2843 // que c'est bien un probleme d'absence
2844 if ( CHDIR(DirNameA.str().c_str()) != 0 )
2846 bool existe = false ;
2849 struct dirent *dirp;
2850 dp = opendir(nomrep);
2851 while ( (dirp = readdir(dp)) != NULL )
2853 std::string file_name(dirp->d_name);
2855 HANDLE hFind = INVALID_HANDLE_VALUE;
2856 WIN32_FIND_DATA ffd;
2857 hFind = FindFirstFile(nomrep, &ffd);
2858 if (INVALID_HANDLE_VALUE != hFind) {
2859 while (FindNextFile(hFind, &ffd) != 0) {
2860 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2861 std::string file_name(ffd.cFileName);
2863 if ( file_name == DirNameA.str() ) { existe = true ; }
2872 DirName = DirNameA.str() ;
2873 a_chercher = false ;
2880 MESSAGE ( "==> DirName = " << DirName);
2881 MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
2882 CHDIR(nomDirActuel.c_str());
2883 return CORBA::string_dup( DirName.c_str() );
2885 //=============================================================================
2886 // Calcul d'une iteration : gestion du repertoire de calcul
2887 // Si le sous-repertoire existe :
2888 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
2889 // etatMenage = 1 : on fait le menage du repertoire
2890 // etatMenage = -1 : on ne fait rien
2891 //=============================================================================
2892 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
2894 MESSAGE ( "ComputeDirManagement : repertoires pour le calcul" );
2895 // B.2. Le repertoire du cas
2896 const char* nomDirCase = myCase->GetDirName();
2897 MESSAGE ( ". nomDirCase = " << nomDirCase );
2899 // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
2900 // B.3.1. Le nom du sous-repertoire
2901 const char* nomDirIt = myIteration->GetDirNameLoc();
2903 // B.3.2. Le nom complet du sous-repertoire
2904 std::stringstream DirCompute ;
2905 DirCompute << nomDirCase << "/" << nomDirIt;
2906 MESSAGE (". DirCompute = " << DirCompute.str() );
2908 // B.3.3. Si le sous-repertoire n'existe pas, on le cree
2909 if (CHDIR(DirCompute.str().c_str()) != 0)
2912 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2914 if (_mkdir(DirCompute.str().c_str()) != 0)
2917 // GERALD -- QMESSAGE BOX
2918 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
2919 VERIFICATION("Pb a la creation du repertoire" == 0);
2924 // Le repertoire existe
2925 // On demande de faire le menage de son contenu :
2926 if (etatMenage == 1)
2928 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
2929 std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
2930 int codret = system(commande.c_str());
2933 // GERALD -- QMESSAGE BOX
2934 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
2935 VERIFICATION("Pb au menage du repertoire de calcul" == 0);
2938 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2941 if (etatMenage == 0)
2945 struct dirent *dirp;
2946 dp = opendir(DirCompute.str().c_str());
2948 while ((dirp = readdir(dp)) != NULL && result )
2950 std::string file_name(dirp->d_name);
2951 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2955 HANDLE hFind = INVALID_HANDLE_VALUE;
2956 WIN32_FIND_DATA ffd;
2957 hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
2959 if (INVALID_HANDLE_VALUE != hFind) {
2960 while (FindNextFile(hFind, &ffd) != 0) {
2961 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2962 std::string file_name(ffd.cFileName);
2963 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2968 if ( result == false)
2970 SALOME::ExceptionStruct es;
2971 es.type = SALOME::BAD_PARAM;
2972 std::string text = "Directory : " + DirCompute.str() + " is not empty";
2973 es.text = CORBA::string_dup(text.c_str());
2974 throw SALOME::SALOME_Exception(es);
2975 VERIFICATION("Directory is not empty" == 0);
2981 return CORBA::string_dup( DirCompute.str().c_str() );
2983 //=============================================================================
2984 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
2985 //=============================================================================
2986 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
2988 MESSAGE ( "ComputeDirPaManagement : repertoires pour le calcul" );
2989 // Le repertoire du cas
2990 const char* nomDirCase = myCase->GetDirName();
2991 MESSAGE ( ". nomDirCase = " << nomDirCase );
2993 // Le sous-repertoire de l'iteration precedente
2995 const char* nomIterationParent = myIteration->GetIterParentName();
2996 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2997 const char* nomDirItPa = myIterationParent->GetDirNameLoc();
2998 std::stringstream DirComputePa ;
2999 DirComputePa << nomDirCase << "/" << nomDirItPa;
3000 MESSAGE( ". nomDirItPa = " << nomDirItPa);
3001 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
3003 return CORBA::string_dup( DirComputePa.str().c_str() );
3005 //=============================================================================
3006 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
3007 //=============================================================================
3008 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3010 MESSAGE ( "... DriverTexteZone" );
3011 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3012 int numberOfZonesx2 = ListZone->length();
3015 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3017 std::string ZoneName = std::string((*ListZone)[iaux]);
3018 MESSAGE ( "... ZoneName = " << ZoneName);
3019 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
3020 ASSERT(!CORBA::is_nil(myZone));
3022 int ZoneType = myZone->GetType();
3023 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
3024 int TypeUse = atoi( TypeUsestr.c_str() );
3025 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
3026 NumZone = iaux/2 + 1 ;
3027 HOMARD::double_array* zone = myZone->GetCoords();
3028 if ( ZoneType == 2 || ( ZoneType>=11 && ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
3029 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
3030 else if ( ZoneType == 4 ) // Cas d une sphere
3031 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
3032 else if ( ZoneType == 5 || ( ZoneType>=31 && ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
3033 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
3034 else if ( ZoneType == 7 || ( ZoneType>=61 && ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
3035 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
3036 else { VERIFICATION("ZoneType est incorrect." == 0) ; }
3041 //=============================================================================
3042 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
3043 //=============================================================================
3044 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3046 MESSAGE ( "... DriverTexteField" );
3047 // Le fichier du champ
3048 char* FieldFile = myIteration->GetFieldFile();
3049 MESSAGE ( ". FieldFile = " << FieldFile );
3050 if (strlen(FieldFile) == 0)
3052 // GERALD -- QMESSAGE BOX
3053 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
3054 VERIFICATION("The file for the field is not given." == 0);
3056 // Les caracteristiques d'instants du champ de pilotage
3057 int TimeStep = myIteration->GetTimeStep();
3058 MESSAGE( ". TimeStep = " << TimeStep );
3059 int Rank = myIteration->GetRank();
3060 MESSAGE( ". Rank = " << Rank );
3061 // Les informations sur les champs
3062 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
3064 const char* FieldName = aInfosHypo->FieldName;
3066 int TypeThR = aInfosHypo->TypeThR;
3067 double ThreshR = aInfosHypo->ThreshR;
3068 int TypeThC = aInfosHypo->TypeThC;
3069 double ThreshC = aInfosHypo->ThreshC;
3070 // Saut entre mailles ou non ?
3071 int UsField = aInfosHypo->UsField;
3072 MESSAGE( ". UsField = " << UsField );
3073 // L'usage des composantes
3074 int UsCmpI = aInfosHypo->UsCmpI;
3075 MESSAGE( ". UsCmpI = " << UsCmpI );
3077 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
3080 HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
3081 int numberOfCompos = mescompo->length();
3082 MESSAGE( ". numberOfCompos = " << numberOfCompos );
3083 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
3085 std::string nomCompo = std::string((*mescompo)[NumeComp]);
3086 if ((system(nomCompo.c_str())) != 0)
3088 MESSAGE( "... nomCompo = " << nomCompo );
3089 myDriver->TexteCompo(NumeComp, nomCompo);
3094 //=============================================================================
3095 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
3096 // On ecrit dans l'ordre :
3097 // 1. la definition des frontieres
3098 // 2. les liens avec les groupes
3099 // 3. un entier resumant le type de comportement pour les frontieres
3100 //=============================================================================
3101 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
3103 MESSAGE ( "... DriverTexteBoundary" );
3104 // 1. Recuperation des frontieres
3105 std::list<std::string> ListeBoundaryTraitees ;
3106 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3107 int numberOfitems = ListBoundaryGroupType->length();
3108 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
3109 int BoundaryOption = 1 ;
3110 // 2. Parcours des frontieres pour ecrire leur description
3111 int NumBoundaryAnalytical = 0 ;
3112 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3114 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3115 MESSAGE ( "... BoundaryName = " << BoundaryName);
3116 // 2.1. La frontiere a-t-elle deja ete ecrite ?
3117 // Cela arrive quand elle est liee a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
3119 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3120 while (it != ListeBoundaryTraitees.end())
3122 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3123 if ( BoundaryName == *it ) { A_faire = 0 ; }
3126 // 2.2. Ecriture de la frontiere
3129 // 2.2.1. Caracteristiques de la frontiere
3130 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3131 ASSERT(!CORBA::is_nil(myBoundary));
3132 int BoundaryType = myBoundary->GetType();
3133 MESSAGE ( "... BoundaryType = " << BoundaryType );
3134 // 2.2.2. Ecriture selon le type
3135 // 2.2.2.1. Cas d une frontiere discrete
3136 if (BoundaryType == 0)
3138 const char* MeshName = myBoundary->GetMeshName() ;
3139 MESSAGE ( ". MeshName = " << MeshName );
3140 const char* MeshFile = myBoundary->GetMeshFile() ;
3141 MESSAGE ( ". MeshFile = " << MeshFile );
3142 myDriver->TexteBoundaryDi( MeshName, MeshFile);
3143 if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
3145 // 2.2.2.1. Cas d une frontiere analytique
3148 NumBoundaryAnalytical++ ;
3149 HOMARD::double_array* coor = myBoundary->GetCoords();
3150 if (BoundaryType == 1) // Cas d un cylindre
3152 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3153 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3155 else if (BoundaryType == 2) // Cas d une sphere
3157 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
3158 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3160 else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
3162 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3163 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3165 else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
3167 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3168 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3170 else if (BoundaryType == 5) // Cas d un tore
3172 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3173 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3176 // 2.2.3. Memorisation du traitement
3177 ListeBoundaryTraitees.push_back( BoundaryName );
3180 // 3. Parcours des frontieres pour ecrire les liens avec les groupes
3181 NumBoundaryAnalytical = 0 ;
3182 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3184 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3185 MESSAGE ( "... BoundaryName = " << BoundaryName);
3186 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3187 ASSERT(!CORBA::is_nil(myBoundary));
3188 int BoundaryType = myBoundary->GetType();
3189 MESSAGE ( "... BoundaryType = " << BoundaryType );
3190 // 3.1. Recuperation du nom du groupe
3191 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
3192 MESSAGE ( "... GroupName = " << GroupName);
3193 // 3.2. Cas d une frontiere discrete
3194 if ( BoundaryType == 0 )
3196 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
3198 // 3.3. Cas d une frontiere analytique
3201 NumBoundaryAnalytical++ ;
3202 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
3205 // 4. Ecriture de l'option finale
3206 myDriver->TexteBoundaryOption(BoundaryOption);
3210 //=============================================================================
3211 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3212 //=============================================================================
3213 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3215 MESSAGE ( "... DriverTexteFieldInterp" );
3216 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3217 MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3218 if (TypeFieldInterp != 0)
3220 // Le fichier des champs
3221 char* FieldFile = myIteration->GetFieldFile();
3222 MESSAGE ( ". FieldFile = " << FieldFile );
3223 if (strlen(FieldFile) == 0)
3225 // GERALD -- QMESSAGE BOX
3226 VERIFICATION("The file for the field is not given." == 0);
3229 const char* MeshFile = myIteration->GetMeshFile();
3230 myDriver->TexteFieldInterp(FieldFile, MeshFile);
3233 // Interpolation de tous les champs
3234 if ( TypeFieldInterp == 1 )
3236 myDriver->TexteFieldInterpAll();
3238 // Interpolation de certains champs
3239 else if (TypeFieldInterp == 2)
3241 // Les champs et leurs instants pour l'iteration
3242 HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3243 int numberOfFieldsx3 = ListFieldTSR->length();
3244 MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3245 // Les champs pour l'hypothese
3246 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3247 int numberOfFieldsx2 = ListField->length();
3248 MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3249 // On parcourt tous les champs de l'hypothese
3251 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3254 std::string FieldName = std::string((*ListField)[iaux]) ;
3255 // Le type d'interpolation
3256 std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3257 MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3258 // On cherche à savoir si des instants ont été précisés pour cette itération
3260 for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3263 std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3264 MESSAGE( "..... FieldName2 = " << FieldName2 );
3265 // Quand c'est le bon champ, on ecrit le pas de temps
3266 if ( FieldName == FieldName2 )
3270 std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3271 // Le numero d'ordre
3272 std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3273 MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3275 int TimeStep = atoi( TimeStepstr.c_str() );
3276 int Rank = atoi( Rankstr.c_str() );
3277 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3281 // Si aucun instant n'a été défini
3285 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3293 //===========================================================================
3294 //===========================================================================
3297 //===========================================================================
3298 //===========================================================================
3300 //===========================================================================
3301 //===========================================================================
3302 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
3303 SALOMEDS::SObject_ptr theSObject,
3304 CORBA::Object_ptr theObject,
3305 const char* theName)
3307 MESSAGE("PublishInStudy pour " << theName);
3308 SALOMEDS::SObject_var aResultSO;
3309 if (CORBA::is_nil(theStudy))
3311 SALOME::ExceptionStruct es;
3312 es.type = SALOME::BAD_PARAM;
3313 es.text = "Invalid study context";
3314 throw SALOME::SALOME_Exception(es);
3318 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3319 // Rq : Iteration est publiee ailleurs
3320 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3321 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
3322 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3323 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3324 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3326 addInStudy(theStudy);
3328 // Controle de la non publication d'un objet de meme nom
3329 if ( (!aBoundary->_is_nil()) || (!aHypo->_is_nil()) || (!aYACS->_is_nil()) || (!aZone->_is_nil()) )
3331 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
3332 if (listSO->length() >= 1)
3334 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3335 aResultSO = listSO[0];
3336 return aResultSO._retn();
3340 // Caracteristiques de l'etude
3341 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
3342 aStudyBuilder->NewCommand();
3343 if(!aBoundary->_is_nil())
3344 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
3345 else if(!aCase->_is_nil())
3346 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
3347 else if(!aHypo->_is_nil())
3348 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
3349 else if(!aYACS->_is_nil())
3350 aResultSO = PublishYACSInStudy(theStudy, aStudyBuilder, aYACS, theName);
3351 else if(!aZone->_is_nil())
3352 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
3354 aStudyBuilder->CommitCommand();
3356 return aResultSO._retn();
3358 //=============================================================================
3359 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3360 SALOMEDS::StudyBuilder_var aStudyBuilder,
3361 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3363 MESSAGE("PublishBoundaryStudy pour "<<theName);
3364 SALOMEDS::SObject_var aResultSO;
3366 // Caracteristique de la Boundary
3367 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3369 // On recupere le module pere dans l etude
3370 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3371 if (theFatherHomard->_is_nil())
3373 MESSAGE("theFatherHomard->_is_nil()");
3374 return aResultSO._retn();
3377 // On ajoute la categorie des boundarys dans l etude si necessaire
3378 if ( _tag_boun == 0 )
3381 _tag_boun = _tag_gene ;
3383 MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3384 SALOMEDS::SObject_var aSObject;
3385 if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3387 MESSAGE("Ajout de la categorie des boundarys");
3388 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3389 PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3391 else { MESSAGE("La categorie des boundarys existe deja."); }
3393 CORBA::Long BoundaryType = myBoundary->GetType();
3394 // MESSAGE("BoundaryType : "<<BoundaryType);
3397 switch (BoundaryType)
3400 { value = "BoundaryDiHomard" ;
3401 icone = "mesh_tree_mesh.png" ;
3405 { value = "BoundaryAnHomard" ;
3406 icone = "cylinderpointvector_2.png" ;
3410 { value = "BoundaryAnHomard" ;
3411 icone = "spherepoint_2.png" ;
3415 { value = "BoundaryAnHomard" ;
3416 icone = "conepointvector.png" ;
3420 { value = "BoundaryAnHomard" ;
3421 icone = "conedxyz.png" ;
3425 { value = "BoundaryAnHomard" ;
3426 icone = "toruspointvector.png" ;
3430 aResultSO = aStudyBuilder->NewObject(aSObject);
3431 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3432 return aResultSO._retn();
3434 //=============================================================================
3435 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
3436 SALOMEDS::StudyBuilder_var aStudyBuilder,
3437 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3439 MESSAGE("PublishCaseInStudy pour "<<theName);
3440 SALOMEDS::SObject_var aResultSO;
3442 if (CORBA::is_nil(theObject)) {
3443 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3444 return aResultSO._retn();
3446 if (theStudy->_is_nil()) {
3447 MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
3448 return aResultSO._retn();
3451 // On recupere le module pere dans l etude
3452 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3453 if (theFatherHomard->_is_nil())
3455 MESSAGE("theFatherHomard->_is_nil()");
3456 return aResultSO._retn();
3460 MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3461 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3462 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3463 _orb->object_to_string(theObject) ) ;
3465 return aResultSO._retn();
3467 //=============================================================================
3468 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3469 SALOMEDS::StudyBuilder_var aStudyBuilder,
3470 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3472 MESSAGE("PublishHypotheseInStudy pour "<<theName);
3473 SALOMEDS::SObject_var aResultSO;
3475 // On recupere le module pere dans l etude
3476 // On ajoute la categorie des hypotheses dans l etude si necessaire
3477 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3478 if (theFatherHomard->_is_nil())
3480 MESSAGE("theFatherHomard->_is_nil()");
3481 return aResultSO._retn();
3484 // On ajoute la categorie des hypotheses dans l etude si necessaire
3485 SALOMEDS::SObject_var aSObject;
3486 if ( _tag_hypo == 0 )
3489 _tag_hypo = _tag_gene ;
3491 MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3492 if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3494 MESSAGE("Ajout de la categorie des hypotheses");
3495 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3496 PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3498 else { MESSAGE("La categorie des hypotheses existe deja."); }
3500 // Creation du resultat dans l'etude
3501 aResultSO = aStudyBuilder->NewObject(aSObject);
3502 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3504 return aResultSO._retn();
3506 //=============================================================================
3507 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::Study_ptr theStudy,
3508 SALOMEDS::StudyBuilder_var aStudyBuilder,
3509 HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3511 MESSAGE("PublishYACSInStudy pour "<<theName);
3512 SALOMEDS::SObject_var aResultSO;
3514 // On recupere le module pere dans l etude
3515 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3516 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3517 if (theFatherHomard->_is_nil())
3519 MESSAGE("theFatherHomard->_is_nil()");
3520 return aResultSO._retn();
3522 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3523 if ( _tag_yacs == 0 )
3526 _tag_yacs = _tag_gene ;
3528 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3529 SALOMEDS::SObject_var aSObject;
3530 if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3532 MESSAGE("Ajout de la categorie des schemas YACS");
3533 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3534 PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3536 else { MESSAGE("La categorie des schemas YACS existe deja."); }
3538 // Creation du resultat dans l'etude
3539 aResultSO = aStudyBuilder->NewObject(aSObject);
3540 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3542 return aResultSO._retn();
3545 //=============================================================================
3546 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
3547 SALOMEDS::StudyBuilder_var aStudyBuilder,
3548 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3550 MESSAGE("PublishZoneStudy pour "<<theName);
3551 SALOMEDS::SObject_var aResultSO;
3552 if (CORBA::is_nil(theObject))
3554 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3555 return aResultSO._retn();
3557 if (theStudy->_is_nil())
3559 MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3560 return aResultSO._retn();
3562 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3563 if (theFatherHomard->_is_nil())
3565 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3566 return aResultSO._retn();
3569 // Caracteristique de la zone
3570 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3571 CORBA::Long ZoneType = myZone->GetType();
3573 // On ajoute la categorie des zones dans l etude si necessaire
3574 if ( _tag_zone == 0 )
3577 _tag_zone = _tag_gene ;
3579 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3580 SALOMEDS::SObject_var aSObject;
3581 if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3583 MESSAGE("Ajout de la categorie des zones");
3584 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3585 PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3587 else { MESSAGE("La categorie des zones existe deja."); }
3589 aResultSO = aStudyBuilder->NewObject(aSObject);
3598 { icone = "boxdxy_2.png" ;
3602 { icone = "boxdxyz_2.png" ;
3610 { icone = "disk_2.png" ;
3614 { icone = "spherepoint_2.png" ;
3618 { icone = "cylinderpointvector_2.png" ;
3626 { icone = "diskwithhole_2.png" ;
3630 { icone = "pipe_2.png" ;
3634 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3636 return aResultSO._retn();
3638 //===========================================================================
3639 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3640 SALOMEDS::SObject_var aResultSO,
3641 const char* name, const char* comment, const char* icone, const char* ior)
3643 MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3644 // MESSAGE("icone = "<<icone);
3645 // MESSAGE("ior = "<<ior);
3646 SALOMEDS::GenericAttribute_var anAttr ;
3650 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3651 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3652 aNameAttrib->SetValue(name);
3655 // Ajout du commentaire
3656 if ( comment != NULL )
3658 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3659 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3660 aCommentAttrib->SetValue(comment);
3664 if ( icone != NULL )
3666 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3667 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3668 aPixmap->SetPixMap(icone);
3674 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3675 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3676 anIOR->SetValue(ior);
3680 //=====================================================================================
3681 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3683 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3685 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3686 ASSERT(!CORBA::is_nil(myCase));
3687 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3688 ASSERT(!CORBA::is_nil(aCaseSO));
3690 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3691 ASSERT(!CORBA::is_nil(myBoundary));
3692 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3693 ASSERT(!CORBA::is_nil(aBoundarySO));
3695 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3697 aStudyBuilder->NewCommand();
3699 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3700 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3701 // aStudyBuilder->RemoveReference(aSubSO);
3703 aStudyBuilder->CommitCommand();
3706 //=====================================================================================
3707 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3709 MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3711 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3712 ASSERT(!CORBA::is_nil(myYACS));
3713 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3714 ASSERT(!CORBA::is_nil(aYACSSO));
3716 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3717 ASSERT(!CORBA::is_nil(myCase));
3718 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3719 ASSERT(!CORBA::is_nil(aCaseSO));
3721 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3723 aStudyBuilder->NewCommand();
3725 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3726 aStudyBuilder->Addreference(aSubSO, aCaseSO);
3728 aStudyBuilder->CommitCommand();
3731 //=============================================================================
3732 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3733 // Option = 0 : fichier issu d'une importation
3734 // Option = 1 : fichier issu d'une execution HOMARD
3736 MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3737 if (CORBA::is_nil(myCurrentStudy))
3739 SALOME::ExceptionStruct es;
3740 es.type = SALOME::BAD_PARAM;
3741 es.text = "Invalid study context";
3742 throw SALOME::SALOME_Exception(es);
3746 // Le module SMESH est-il actif ?
3747 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3749 if (!CORBA::is_nil(aSmeshSO))
3751 // On verifie que le fichier n est pas deja publie
3752 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3753 for (; aIter->More(); aIter->Next())
3755 SALOMEDS::SObject_var aSO = aIter->Value();
3756 SALOMEDS::GenericAttribute_var aGAttr;
3757 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3759 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3760 CORBA::String_var value=anAttr->Value();
3761 if (strcmp((const char*)value,NomFich) == 0)
3763 MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3764 // Pour un fichier importe, on ne republie pas
3765 if ( Option == 0 ) { return; }
3766 // Pour un fichier calcule, on commence par faire la depublication
3769 MESSAGE ( "PublishResultInSmesh : depublication" );
3770 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3771 CORBA::String_var value2=anAttr2->Value();
3772 std::string MeshName = string(value2) ;
3773 MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3774 DeleteResultInSmesh(NomFich, MeshName) ;
3781 // On enregistre le fichier
3782 MESSAGE( "Enregistrement du fichier");
3783 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
3784 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
3785 ASSERT(!CORBA::is_nil(aSmeshEngine));
3786 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
3787 SMESH::DriverMED_ReadStatus theStatus;
3788 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3790 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
3791 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3792 for (int i = 0; i < mesMaillages->length(); i++)
3794 MESSAGE( ". Mise a jour des attributs du maillage");
3795 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
3796 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
3797 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3798 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
3799 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3800 anAttr->SetValue(NomFich);
3801 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
3802 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
3804 if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
3805 else { icone = "mesh_tree_mesh.png" ; }
3806 anAttr2->SetPixMap( icone );
3810 //=============================================================================
3811 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
3813 MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
3814 if (CORBA::is_nil(myCurrentStudy))
3816 SALOME::ExceptionStruct es;
3817 es.type = SALOME::BAD_PARAM;
3818 es.text = "Invalid study context";
3819 throw SALOME::SALOME_Exception(es);
3823 // Le module SMESH est-il actif ?
3824 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3826 if (CORBA::is_nil(aSmeshSO))
3830 // On verifie que le fichier est deja publie
3831 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
3832 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3833 for (; aIter->More(); aIter->Next())
3835 SALOMEDS::SObject_var aSO = aIter->Value();
3836 SALOMEDS::GenericAttribute_var aGAttr;
3837 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3839 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3840 CORBA::String_var value=anAttr->Value();
3841 if (strcmp((const char*)value,NomFich.c_str()) == 0)
3843 if (aSO->FindAttribute(aGAttr,"AttributeName"))
3845 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3846 CORBA::String_var value2=anAttr2->Value();
3847 if (strcmp((const char*)value2,MeshName.c_str()) == 0)
3849 myBuilder->RemoveObjectWithChildren( aSO ) ;
3857 //=============================================================================
3858 void HOMARD_Gen_i::PublishMeshIterInSmesh(const char* NomIter)
3860 MESSAGE( "PublishMeshIterInSmesh " << NomIter);
3861 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3863 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3864 if (CORBA::is_nil(myIteration))
3866 SALOME::ExceptionStruct es;
3867 es.type = SALOME::BAD_PARAM;
3868 es.text = "Invalid iterationStudy Object";
3869 throw SALOME::SALOME_Exception(es);
3872 const char* MeshFile = myIteration->GetMeshFile() ;
3873 const char* MeshName = myIteration->GetMeshName() ;
3874 CORBA::Long Option = -1 ;
3875 int etat = myIteration->GetState();
3876 // Iteration initiale
3877 if ( etat <= 0 ) { Option = 0 ; }
3878 // ou iteration calculee
3879 else if ( etat == 2 ) { Option = 1 ; }
3880 // Publication effective apres menage eventuel
3883 DeleteResultInSmesh(MeshFile, MeshName) ;
3884 PublishResultInSmesh(MeshFile, Option) ;
3888 //=============================================================================
3889 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
3891 // MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3892 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3894 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3895 if (CORBA::is_nil(myIteration))
3897 SALOME::ExceptionStruct es;
3898 es.type = SALOME::BAD_PARAM;
3899 es.text = "Invalid iterationStudy Object";
3900 throw SALOME::SALOME_Exception(es);
3904 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3906 aStudyBuilder->NewCommand();
3908 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
3909 // Pour les fichiers med, on affiche une icone de maillage
3910 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
3911 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
3913 std::string ior = " " ;
3914 if ( Commentaire[0] == 'M' )
3915 { icone = "med.png" ; }
3917 { icone = "texte_2.png" ; }
3918 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3920 aStudyBuilder->CommitCommand();
3923 //=============================================================================
3924 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
3926 // MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3927 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3929 SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3930 if (CORBA::is_nil(myYACS))
3932 SALOME::ExceptionStruct es;
3933 es.type = SALOME::BAD_PARAM;
3934 es.text = "Invalid YACSStudy Object";
3935 throw SALOME::SALOME_Exception(es);
3939 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3941 aStudyBuilder->NewCommand();
3943 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3944 std::string icone = "texte_2.png" ;
3945 std::string ior = " " ;
3946 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3948 aStudyBuilder->CommitCommand();
3951 //=============================================================================
3952 //=============================================================================
3954 //=============================================================================
3955 //=============================================================================
3956 //=============================================================================
3957 // Creation d'un schema YACS
3958 // nomCas : nom du cas a traiter
3959 // FileName : nom du fichier contenant le script de lancement du calcul
3960 // DirName : le repertoire de lancement des calculs du schéma
3961 //=============================================================================
3962 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
3964 INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
3965 INFOS ( ". nomCas : " << nomCas);
3966 INFOS ( ". ScriptFile : " << ScriptFile);
3967 INFOS ( ". DirName : " << DirName);
3968 INFOS ( ". MeshFile : " << MeshFile);
3970 // A. Controle du nom :
3971 if ((myContextMap[GetCurrentStudyID()]._mesYACSs).find(nomYACS) != (myContextMap[GetCurrentStudyID()]._mesYACSs).end())
3973 SALOME::ExceptionStruct es;
3974 es.type = SALOME::BAD_PARAM;
3975 es.text = "This schema YACS has already been defined.";
3976 throw SALOME::SALOME_Exception(es);
3980 // B. Creation de l'objet
3981 HOMARD::HOMARD_YACS_var myYACS = newYACS();
3982 if (CORBA::is_nil(myYACS))
3984 SALOME::ExceptionStruct es;
3985 es.type = SALOME::BAD_PARAM;
3986 es.text = "Unable to create the schema YACS";
3987 throw SALOME::SALOME_Exception(es);
3990 myYACS->SetName( nomYACS ) ;
3992 // C. Enregistrement
3993 myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS] = myYACS;
3995 SALOMEDS::SObject_var aSO;
3996 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myYACS, nomYACS);
3998 PublishCaseUnderYACS(nomYACS, nomCas);
4000 // D. Caracterisation
4002 myYACS->SetDirName( DirName ) ;
4003 myYACS->SetMeshFile( MeshFile ) ;
4004 myYACS->SetScriptFile( ScriptFile ) ;
4005 myYACS->SetCaseName( nomCas ) ;
4008 // D.2.1. Type constant
4009 myYACS->SetType( 1 ) ;
4010 // D.2.2. Convergence
4011 defaut_i = GetYACSMaxIter() ;
4012 myYACS->SetMaxIter( defaut_i ) ;
4013 defaut_i = GetYACSMaxNode() ;
4014 myYACS->SetMaxNode( defaut_i ) ;
4015 defaut_i = GetYACSMaxElem() ;
4016 myYACS->SetMaxElem( defaut_i ) ;
4017 // D.3. Fichier de sauvegarde dans le repertoire du cas
4018 HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
4019 std::string dirnamecase = caseyacs->GetDirName() ;
4020 std::string XMLFile ;
4021 XMLFile = dirnamecase + "/schema.xml" ;
4022 myYACS->SetXMLFile( XMLFile.c_str() ) ;
4024 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
4026 //=============================================================================
4027 // Ecriture d'un schema YACS
4028 //=============================================================================
4029 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
4031 INFOS ( "YACSWrite : Ecriture de " << nomYACS );
4032 // Le repertoire du cas
4033 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4034 ASSERT(!CORBA::is_nil(myYACS));
4035 // Le nom du fichier du schema
4036 std::string XMLFile ;
4037 XMLFile = myYACS->GetXMLFile() ;
4039 int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
4043 //=============================================================================
4044 // Ecriture d'un schema YACS sur un fichier donne
4045 //=============================================================================
4046 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
4048 INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
4055 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4056 ASSERT(!CORBA::is_nil(myYACS));
4057 // B.2. Les caracteristiques
4058 std::string DirName = myYACS->GetDirName() ;
4059 std::string MeshFile = myYACS->GetMeshFile() ;
4060 std::string ScriptFile = myYACS->GetScriptFile() ;
4061 // B.3. Les caracteristiques de convergence
4062 int MaxIter = myYACS->GetMaxIter() ;
4063 int MaxNode = myYACS->GetMaxNode() ;
4064 int MaxElem = myYACS->GetMaxElem() ;
4068 const char* nomCas = myYACS->GetCaseName();
4069 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
4070 ASSERT(!CORBA::is_nil(myCase));
4071 // C.2. Les instructions python associees au cas
4072 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4073 std::string pythonCas = dumpCorbaCase.in();
4074 MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
4076 // D. Les iterations
4077 // D.1. L'iteration initiale
4078 HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
4079 std::string Iter0Name = myCase->GetIter0Name() ;
4080 MESSAGE (". Iter0Name = " << Iter0Name);
4081 std::string MeshName = Iter0->GetMeshName();
4082 MESSAGE (". MeshName = " << MeshName);
4083 // D.2. L'iteration numero 1
4084 HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
4085 int numberOfIter = maListe->length();
4086 if ( numberOfIter > 1 )
4088 MESSAGE (". numberOfIter = " << numberOfIter);
4089 SALOME::ExceptionStruct es ;
4090 es.type = SALOME::BAD_PARAM;
4091 std::string text = "Une seule iteration est permise." ;
4092 es.text = CORBA::string_dup(text.c_str());
4093 throw SALOME::SALOME_Exception(es);
4096 std::string Iter1Name = std::string((*maListe)[0]);
4097 MESSAGE ("... Iter1Name = " << Iter1Name);
4098 HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
4099 // D.3. Les instructions python associees a l'iteration
4100 CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
4101 std::string pythonIter = dumpCorbaIter.in();
4102 MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
4104 // E. L'hypothese pour passer de l'iteration initiale a la suivante
4105 // E.1. La structure
4106 std::string nomHypo = Iter1->GetHypoName();
4107 MESSAGE (". nomHypo = " << nomHypo);
4108 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
4109 ASSERT(!CORBA::is_nil(myHypo));
4110 // E.2. Les caracteristiques de l'adaptation
4111 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
4112 ASSERT(ListTypes->length() == 3);
4113 int TypeAdap = (*ListTypes)[0];
4114 // int TypeRaff = (*ListTypes)[1];
4115 // int TypeDera = (*ListTypes)[2];
4116 // E.3. Les instructions python associees a l'hypothese
4117 CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
4118 std::string pythonHypo = dumpCorbaHypo.in();
4119 MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
4121 // F. Le fichier du schema de reference
4122 // HOMARD_ROOT_DIR : repertoire ou se trouve le module HOMARD
4123 std::string XMLFile_base ;
4124 if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
4127 SALOME::ExceptionStruct es ;
4128 es.type = SALOME::BAD_PARAM;
4129 std::string text = "HOMARD_ROOT_DIR est inconnu." ;
4130 es.text = CORBA::string_dup(text.c_str());
4131 throw SALOME::SALOME_Exception(es);
4134 XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
4136 MESSAGE("XMLFile_base ="<<XMLFile_base);
4138 // G. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4139 YACSDriver* myDriver = new YACSDriver(XMLFile, DirName);
4140 std::ifstream fichier( XMLFile_base.c_str() );
4141 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
4143 // G.1. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4144 std::string ligne; // variable contenant chaque ligne lue
4145 std::string mot_cle;
4146 while ( std::getline( fichier, ligne ) )
4148 // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
4149 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
4150 ligne_bis >> mot_cle ;
4151 // G.1.2. Le maillage initial
4152 if ( mot_cle == "DataInit_MeshFile" )
4153 { myDriver->Texte_DataInit_MeshFile(MeshFile); }
4154 // G.1.3. Le script de lancement
4155 else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
4156 { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
4157 // G.1.4. Les options du cas
4158 else if ( mot_cle == "Iter_1_Case_Options" )
4159 { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
4160 // G.1.5. Execution de HOMARD : le repertoire du cas
4161 else if ( mot_cle == "HOMARD_Exec_DirName" )
4162 { myDriver->Texte_HOMARD_Exec_DirName(); }
4163 // G.1.6. Execution de HOMARD : le nom du maillage
4164 else if ( mot_cle == "HOMARD_Exec_MeshName" )
4166 myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
4167 std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
4168 myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
4170 // G.1.7. Execution de HOMARD : les options de l'hypothese
4171 else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
4172 { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ; }
4173 // G.1.8. Execution de HOMARD : les options de l'iteration
4174 else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
4175 { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ; }
4176 // G.1.9. a. Creation eventuelles des zones et frontieres
4178 else if ( mot_cle == "Iter_1" )
4180 std::string texte_control = "" ;
4181 if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
4182 texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
4183 texte_control += myDriver->Texte_Iter_1_control() ;
4184 myDriver->TexteAdd(texte_control);
4186 // G.1.10. Les tests de convergence
4187 else if ( mot_cle == "Analyse_Test_Convergence" )
4188 { myDriver->TexteAnalyse_Test_Convergence(MaxIter, MaxNode, MaxElem); }
4189 // G.1.11. Les parametres
4190 else if ( mot_cle == "PARAMETRES" )
4191 { myDriver->TexteAddParametres(); }
4192 // G.1.n. La ligne est recopiee telle quelle
4193 else { myDriver->TexteAdd(ligne); }
4195 // G.2. Ecriture du texte dans le fichier
4197 { myDriver->CreeFichier(); }
4201 SALOME::ExceptionStruct es;
4202 es.type = SALOME::BAD_PARAM;
4203 std::string text = "The reference file for the YACS schema cannot be read." ;
4204 es.text = CORBA::string_dup(text.c_str());
4205 throw SALOME::SALOME_Exception(es);
4210 // H. Publication du fichier dans l'arbre
4212 std::string Commentaire = "xml" ;
4213 PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
4217 //=============================================================================
4218 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
4219 //=============================================================================
4220 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
4222 MESSAGE ( "YACSDriverTexteZone" );
4223 // A. Les zones associees a cette hypothese
4224 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
4225 int numberOfZonesx2 = ListZone->length();
4227 // B. Parcours des zones
4228 std::string texte_control ;
4229 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
4231 // 1. Reperage de la zone
4232 std::string ZoneName = std::string((*ListZone)[iaux]);
4233 MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
4234 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
4235 ASSERT(!CORBA::is_nil(myZone));
4236 // 2. Les instructions python associees a la zone
4237 // La premiere ligne est un commentaire a eliminer
4238 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4239 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4240 std::string pythonStructure_0 = dumpCorbaZone.in();
4241 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4242 std::istringstream tout (pythonStructure_0) ;
4244 std::string pythonStructure ;
4245 while ( std::getline( tout, ligne ) )
4246 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4247 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4248 // 3. Decodage du nom du service
4249 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4250 MESSAGE ( "... methode = " << methode);
4251 // 4. Mise en place des instructions
4252 int ZoneType = myZone->GetType();
4253 MESSAGE ( "... ZoneType = " << ZoneType);
4254 std::string texte_control_0 ;
4255 texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
4256 texte_control += texte_control_0 ;
4261 return texte_control ;
4263 //=============================================================================
4264 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4265 //=============================================================================
4266 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4268 MESSAGE ( "YACSDriverTexteBoundary" );
4269 // A. Les frontieres associees au cas
4270 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4271 int numberOfitems = ListBoundaryGroupType->length();
4273 // B. Parcours des frontieres
4274 std::string texte_control ;
4275 std::list<std::string> ListeBoundaryTraitees ;
4276 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4278 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4279 MESSAGE ( "... BoundaryName = " << BoundaryName);
4280 // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4281 // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4283 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4284 while (it != ListeBoundaryTraitees.end())
4286 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4287 if ( BoundaryName == *it ) { A_faire = 0 ; }
4292 // 1. Caracteristiques de la frontiere
4293 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
4294 ASSERT(!CORBA::is_nil(myBoundary));
4295 // 2. Les instructions python associees a la frontiere
4296 // La premiere ligne est un commentaire a eliminer
4297 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4298 CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4299 std::string pythonStructure_0 = dumpCorbaBoundary.in();
4300 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4301 std::istringstream tout (pythonStructure_0) ;
4303 std::string pythonStructure ;
4304 while ( std::getline( tout, ligne ) )
4305 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4306 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4307 // 3. Decodage du nom du service
4308 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4309 MESSAGE ( "... methode = " << methode);
4310 // 4. Mise en place des instructions
4311 int BoundaryType = myBoundary->GetType();
4312 MESSAGE ( "... BoundaryType = " << BoundaryType);
4313 const char* MeshName ;
4314 const char* MeshFile ;
4315 if (BoundaryType == 0)
4317 MeshName = myBoundary->GetMeshName() ;
4318 MESSAGE ( ". MeshName = " << MeshName );
4319 MeshFile = myBoundary->GetMeshFile() ;
4320 MESSAGE ( ". MeshFile = " << MeshFile );
4322 std::string texte_control_0 ;
4323 texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName, MeshName, MeshFile );
4324 texte_control += texte_control_0 ;
4325 // 5. Memorisation du traitement
4326 ListeBoundaryTraitees.push_back( BoundaryName );
4330 return texte_control ;
4333 //=============================================================================
4334 //=============================================================================
4335 // Next functions are inherited from SALOMEDS::Driver interface
4336 //=============================================================================
4337 //=============================================================================
4338 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4340 CORBA::Boolean isMultiFile)
4342 MESSAGE ("Save for theURL = "<< theURL);
4343 SALOMEDS::TMPFile_var aStreamFile;
4345 // get temporary directory name
4346 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4348 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4349 StudyContext& context = myContextMap[ aStudy->StudyId() ];
4351 // HOMARD data file name
4352 std::string aFileName = "";
4354 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4355 aFileName += "_HOMARD.dat";
4357 // initialize sequence of file names
4358 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
4359 aFileSeq->length(1);
4360 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
4362 // get full path to the data file
4363 aFileName = tmpDir + aFileName;
4367 std::ofstream f(aFileName.c_str());
4369 // clear temporary id map
4370 context._idmap.clear();
4375 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4376 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4377 HOMARD::HOMARD_Cas_var aCas = it_case->second;
4378 PortableServer::ServantBase_var aServant = GetServant(aCas);
4379 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4381 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4382 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4386 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4387 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4388 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4389 PortableServer::ServantBase_var aServant = GetServant(aZone);
4390 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4392 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4393 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4396 // -> save hypotheses
4397 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4398 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4399 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4400 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4401 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4403 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4404 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4407 // -> save iterations
4408 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4409 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4410 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4411 PortableServer::ServantBase_var aServant = GetServant(aIter);
4412 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4414 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4415 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4418 // -> save boundaries
4419 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4420 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4421 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4422 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4423 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4424 if (aBoundaryServant) {
4425 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4426 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4430 MESSAGE ("close file");
4433 // put temporary files to the stream
4434 MESSAGE ("put temporary files to the stream");
4435 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
4437 // remove temporary files
4438 MESSAGE ("remove temporary files");
4439 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4441 // return data stream
4442 MESSAGE ("return data stream");
4443 return aStreamFile._retn();
4446 //===========================================================================
4447 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4449 CORBA::Boolean isMultiFile)
4451 // No specific ASCII persistence
4452 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4453 return aStreamFile._retn();
4456 //===========================================================================
4457 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4458 const SALOMEDS::TMPFile& theStream,
4460 CORBA::Boolean isMultiFile)
4462 MESSAGE ("Load pour theURL = "<< theURL);
4463 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4465 // set current study
4466 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
4467 SetCurrentStudy(aStudy);
4469 // get temporary directory name
4470 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4472 // Convert the stream into sequence of files to process
4473 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4476 // HOMARD data file name
4477 std::string aFileName = "";
4479 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4480 aFileName = tmpDir + aFileName + "_HOMARD.dat";
4482 StudyContext& context = myContextMap[ aStudy->StudyId() ];
4486 std::ifstream f(aFileName.c_str());
4489 context._mesCas.clear();
4490 context._mesHypotheses.clear();
4491 context._mesIterations.clear();
4492 context._mesZones.clear();
4493 context._mesBoundarys.clear();
4494 context._idmap.clear();
4500 std::getline(f, line);
4501 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4502 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4503 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4504 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4505 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4506 std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4507 if (line.substr(0, bounSignature.size()) == bounSignature) {
4508 // re-create boundary
4509 MESSAGE ("Recreation de la frontiere" );
4510 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4511 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4512 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4513 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4514 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4515 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4518 else if (line.substr(0, caseSignature.size()) == caseSignature) {
4520 MESSAGE ("Recreation du cas" );
4521 HOMARD::HOMARD_Cas_var aCase = newCase();
4522 PortableServer::ServantBase_var aServant = GetServant(aCase);
4523 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4524 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4525 context._mesCas[aCase->GetName()] = aCase;
4526 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4529 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4530 // re-create hypothesis
4531 MESSAGE ("Recreation de l hypothese" );
4532 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4533 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4534 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4535 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4536 context._mesHypotheses[aHypo->GetName()] = aHypo;
4537 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4540 else if (line.substr(0, iterSignature.size()) == iterSignature) {
4541 // re-create iteration
4542 MESSAGE ("Recreation de l'iteration" );
4543 HOMARD::HOMARD_Iteration_var aIter = newIteration();
4544 PortableServer::ServantBase_var aServant = GetServant(aIter);
4545 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4546 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4547 context._mesIterations[aIter->GetName()] = aIter;
4548 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4551 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4552 MESSAGE ("Recreation de la zone" );
4554 HOMARD::HOMARD_Zone_var aZone = newZone();
4555 PortableServer::ServantBase_var aServant = GetServant(aZone);
4556 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4557 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4558 context._mesZones[aZone->GetName()] = aZone;
4559 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4562 else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4563 MESSAGE ("Recreation du schema YACS" );
4565 HOMARD::HOMARD_YACS_var aYACS = newYACS();
4566 PortableServer::ServantBase_var aServant = GetServant(aYACS);
4567 HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4568 if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4569 context._mesYACSs[aYACS->GetName()] = aYACS;
4570 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4579 // Remove temporary files created from the stream
4581 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4586 //===========================================================================
4587 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4588 const SALOMEDS::TMPFile& theStream,
4590 CORBA::Boolean isMultiFile)
4592 // No specific ASCII persistence
4593 return Load(theComponent, theStream, theURL, isMultiFile);
4596 //===========================================================================
4597 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4599 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
4600 // clearing study context should be done here:
4601 // - destroy all servants and related CORBA objects
4603 // - remove context from myContextMap
4604 myContextMap.erase(theComponent->GetStudy()->StudyId());
4605 // - nullify myCurrentStudy
4606 myCurrentStudy = SALOMEDS::Study::_nil();
4610 //===========================================================================
4611 char* HOMARD_Gen_i::ComponentDataType()
4613 return CORBA::string_dup("HOMARD");
4616 //===========================================================================
4617 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4618 const char* IORString,
4619 CORBA::Boolean isMultiFile,
4620 CORBA::Boolean isASCII)
4622 CORBA::String_var aString("");
4623 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4624 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4625 CORBA::Object_var anObj = _orb->string_to_object(IORString);
4626 if (!CORBA::is_nil(anObj)) {
4627 PortableServer::ServantBase_var aServant = GetServant(anObj);
4628 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4630 std::map<int, PortableServer::ServantBase*>::const_iterator it;
4631 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4632 if (it->second == aStorable) {
4633 std::stringstream os;
4635 aString = CORBA::string_dup(os.str().c_str());
4641 return aString._retn();
4644 //===========================================================================
4645 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4646 const char* aLocalPersistentID,
4647 CORBA::Boolean isMultiFile,
4648 CORBA::Boolean isASCII)
4650 CORBA::String_var aString("");
4651 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4652 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4653 int id = atoi(aLocalPersistentID);
4654 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4655 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4656 if (!CORBA::is_nil(object)) {
4657 aString = _orb->object_to_string(object);
4661 return aString._retn();
4664 //===========================================================================
4665 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4667 if(CORBA::is_nil(myCurrentStudy))
4670 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4671 if(!aCas->_is_nil())
4674 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4675 if(!aHypo->_is_nil())
4678 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4679 if(!aZone->_is_nil())
4682 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4683 if(!aBoundary->_is_nil())
4686 /* Iteration is not published directly
4687 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4688 if(!aIter->_is_nil())
4694 //===========================================================================
4695 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4697 // No Copy/Paste support
4701 //===========================================================================
4702 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4703 CORBA::Long& theObjectID)
4705 // No Copy/Paste support
4706 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4707 return aStreamFile._retn();
4710 //===========================================================================
4711 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
4712 CORBA::Long theObjectID)
4714 // No Copy/Paste support
4718 //===========================================================================
4719 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4720 CORBA::Long theObjectID,
4721 SALOMEDS::SObject_ptr theSObject)
4723 // No Copy/Paste support
4724 SALOMEDS::SObject_var aResultSO;
4725 return aResultSO._retn();
4728 //===========================================================================
4729 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4731 PortableServer::Servant aServant = 0;
4732 if (!CORBA::is_nil(theObject)) {
4734 aServant = _poa->reference_to_servant(theObject);
4742 //==========================================================================
4743 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4744 CORBA::Boolean isPublished,
4745 CORBA::Boolean isMultiFile,
4746 CORBA::Boolean& isValidScript)
4748 MESSAGE ("Entree dans DumpPython");
4750 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
4751 if(CORBA::is_nil(aStudy))
4752 return new Engines::TMPFile(0);
4754 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
4755 if(CORBA::is_nil(aSO))
4756 return new Engines::TMPFile(0);
4758 std::string aScript = "\"\"\"\n";
4759 aScript += "Python script for HOMARD\n";
4760 aScript += "Copyright 1996, 2011, 2015 EDF\n";
4761 aScript += "\"\"\"\n";
4762 aScript += "__revision__ = \"V1.2\"\n";
4763 aScript += "import HOMARD\n";
4765 aScript += "import salome\n";
4766 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4768 aScript += "def RebuildData(theStudy):\n";
4769 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
4772 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
4773 MESSAGE (". Au depart \n"<<aScript);
4776 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
4778 MESSAGE (". Ecritures des frontieres");
4779 aScript += "#\n# Creation of the boundaries";
4780 aScript += "\n# ==========================";
4782 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4783 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
4784 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
4786 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4787 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4788 std::string dumpBoundary = dumpCorbaBoundary.in();
4789 MESSAGE (dumpBoundary<<"\n");
4790 aScript += dumpBoundary;
4794 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
4796 MESSAGE (". Ecritures des zones");
4797 aScript += "#\n# Creation of the zones";
4798 aScript += "\n# =====================";
4800 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4801 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
4802 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
4804 HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
4805 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4806 std::string dumpZone = dumpCorbaZone.in();
4807 MESSAGE (dumpZone<<"\n");
4808 aScript += dumpZone;
4812 if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
4814 MESSAGE (". Ecritures des hypotheses");
4815 aScript += "#\n# Creation of the hypotheses";
4816 aScript += "\n# ==========================";
4818 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4819 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
4820 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
4822 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
4823 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
4824 std::string dumpHypo = dumpCorbaHypo.in();
4825 MESSAGE (dumpHypo<<"\n");
4826 aScript += dumpHypo;
4830 if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
4832 MESSAGE (". Ecritures des cas");
4833 aScript += "#\n# Creation of the cases";
4834 aScript += "\n# =====================";
4836 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
4837 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4838 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
4840 std::string nomCas = (*it_cas).first;
4841 std::string dumpCas = std::string("\n# Creation of the case ") ;
4842 dumpCas += nomCas + std::string("\n");
4843 dumpCas += std::string("\t") + nomCas;
4844 dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
4846 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
4847 CORBA::String_var cIter0= myCase->GetIter0Name();
4848 std::string iter0 = cIter0.in();
4850 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
4851 CORBA::String_var cMesh0= myIteration->GetMeshFile();
4852 std::string mesh0 = cMesh0.in();
4853 CORBA::String_var cMeshName0= myIteration->GetMeshName();
4854 std::string meshName0 = cMeshName0.in();
4855 dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
4856 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4857 std::string dumpCas2= dumpCorbaCase.in();
4859 MESSAGE (dumpCas<<dumpCas2<<"\n");
4860 aScript += dumpCas + dumpCas2;
4864 if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
4866 MESSAGE (". Ecritures des iterations");
4867 aScript += "#\n# Creation of the iterations" ;
4868 aScript += "\n# ==========================";
4870 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4871 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
4872 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
4874 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
4875 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
4876 std::string dumpIter = dumpCorbaIter.in();
4877 MESSAGE (dumpIter<<"\n");
4878 aScript += dumpIter;
4882 if (myContextMap[GetCurrentStudyID()]._mesYACSs.size() > 0)
4884 MESSAGE (". Ecritures des schemas YACS");
4885 aScript += "#\n# Creation of the schemas YACS";
4886 aScript += "\n# ============================";
4888 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
4889 for ( it_yacs = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
4890 it_yacs != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); ++it_yacs)
4892 HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
4893 CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
4894 std::string dumpYACS = dumpCorbaYACS.in();
4895 MESSAGE (dumpYACS<<"\n");
4896 aScript += dumpYACS;
4899 MESSAGE (". Ecritures finales");
4901 aScript += "\n\tpass";
4904 if( !isMultiFile ) // remove unnecessary tabulation
4905 aScript = RemoveTabulation( aScript );
4907 // MESSAGE ("A ecrire \n"<<aScript);
4908 const size_t aLen = strlen(aScript.c_str());
4909 char* aBuffer = new char[aLen+1];
4910 strcpy(aBuffer, aScript.c_str());
4912 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
4913 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
4915 MESSAGE ("Sortie de DumpPython");
4916 return aStreamFile._retn();
4920 //=============================================================================
4921 //=============================================================================
4923 //=============================================================================
4924 //=============================================================================
4925 void HOMARD_Gen_i::IsValidStudy( )
4927 // MESSAGE( "IsValidStudy" );
4928 if (CORBA::is_nil(myCurrentStudy))
4930 SALOME::ExceptionStruct es;
4931 es.type = SALOME::BAD_PARAM;
4932 es.text = "Invalid study context";
4933 throw SALOME::SALOME_Exception(es);
4938 //=============================================================================
4939 char* HOMARD_Gen_i::VerifieDir(const char* nomDir)
4941 std::string casename = std::string("") ;
4942 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
4943 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4944 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
4946 if (std::string(nomDir) == std::string(it->second->GetDirName()))
4948 casename = std::string(it->second->GetName()) ;
4952 return CORBA::string_dup( casename.c_str() );
4954 /*//=============================================================================
4955 void SALOMEException( std::string message )
4957 SALOME::ExceptionStruct es;
4958 es.type = SALOME::BAD_PARAM;
4960 throw SALOME::SALOME_Exception(es);
4963 //=============================================================================
4964 char* HOMARD_Gen_i::getVersion()
4966 #if HOMARD_DEVELOPMENT
4967 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
4969 return CORBA::string_dup(HOMARD_VERSION_STR);
4972 //===============================================================================
4973 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un caractere
4974 // ligne : la ligne a manipuler
4975 // caractere : le caractere a reperer
4976 // option : 0 : la chaine avant la premiere apparition du caractere
4977 // 1 : la chaine apres la premiere apparition du caractere
4978 // 2 : la chaine avant la derniere apparition du caractere
4979 // 3 : la chaine apres la derniere apparition du caractere
4980 // Si le caractere est absent, on retourne la chaine totale
4981 //===============================================================================
4982 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string caractere, int option )
4984 // MESSAGE("GetStringInTexte, recherche de '"<<caractere<<"' dans '"<<ligne<<"'"<<", option = "<<option);
4986 std::string chaine = ligne ;
4988 if ( option < 2 ) { position = ligne.find_first_of( caractere ) ; }
4989 else { position = ligne.find_last_of( caractere ) ; }
4990 // MESSAGE("position = "<<position);
4991 // MESSAGE("a = "<<ligne.substr( 0, position ).c_str());
4992 // MESSAGE("b = "<<ligne.substr( position+1 ).c_str());
4994 if ( position != std::string::npos )
4996 if ( ( option == 0 ) || ( option == 2 ) ) { chaine = ligne.substr( 0, position ) ; }
4997 else { chaine = ligne.substr( position+1 ) ; }
5002 //=============================================================================
5003 //=============================================================================
5004 // Gestion des preferences
5005 //=============================================================================
5006 //=============================================================================
5007 // Decodage du fichier d'arcihvage des preferences
5009 void HOMARD_Gen_i::SetPreferences( )
5011 MESSAGE ( "SetPreferences" );
5013 std::string ligne, mot_cle, salome_version ;
5016 // A. Les valeurs par defaut ; elles doivent etre coherentes
5017 std::string LanguageShort = "en" ;
5018 int PublisMeshIN = 0 ;
5019 int PublisMeshOUT = 0 ;
5020 int YACSMaxIter = 0 ;
5021 int YACSMaxNode = 0 ;
5022 int YACSMaxElem = 0 ;
5023 std::string YACSTypeTestchaine = "None" ;
5025 // B. La version de salome
5026 // Cela se presente sous la forme :
5027 // [SALOME KERNEL] : 7.3.0
5029 File = getenv("KERNEL_ROOT_DIR") ;
5030 File += "/bin/salome/VERSION" ;
5031 MESSAGE ( "File = "<<File ) ;
5032 std::ifstream fichier0( File.c_str() ) ;
5033 if ( fichier0 ) // ce test échoue si le fichier n'est pas ouvert
5035 std::string ligne; // variable contenant chaque ligne lue
5036 while ( std::getline( fichier0, ligne ) )
5038 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5039 ligne_bis >> mot_cle ;
5040 if ( mot_cle == "[SALOME" )
5042 salome_version = GetStringInTexte ( ligne, " ", 3 ) ;
5043 // MESSAGE ( "salome_version = "<<salome_version<<"|||");
5048 else { ok = false ; }
5050 // B. Decodage du fichier de preferences
5053 std::string PrefFile ;
5054 PrefFile = getenv("HOME") ;
5055 PrefFile += "/.config/salome/SalomeApprc." + salome_version ;
5056 MESSAGE ( "PrefFile = "<<PrefFile ) ;
5058 std::ifstream fichier( PrefFile.c_str() );
5059 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
5061 bool section_langue = false ;
5062 bool section_homard = false ;
5063 while ( std::getline( fichier, ligne ) )
5065 std::string chaine ;
5066 // 1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
5067 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5068 ligne_bis >> mot_cle ;
5071 // 2.1. Debut d'une section
5072 // MESSAGE(mot_cle);
5073 if ( mot_cle == "<section" )
5074 { /*MESSAGE ( "Debut de la section : "<< ligne);*/
5075 ligne_bis >> mot_cle ;
5076 chaine = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5077 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5078 if ( chaine == "language" ) { section_langue = true ; }
5079 if ( chaine == "HOMARD" ) { section_homard = true ; }
5080 // MESSAGE ( "section_langue = "<<section_langue<<", section_homard = "<<section_homard);
5082 // 2.2. Fin d'une section
5083 else if ( mot_cle == "</section>" )
5084 { /*MESSAGE ( "Fin de la section : "<< ligne<<", section_langue = "<<section_langue<<", section_homard = "<<section_homard);*/
5085 section_langue = false ;
5086 section_homard = false ; }
5090 else if ( section_langue || section_homard )
5091 { MESSAGE ( "a decoder : "<< ligne);
5092 // La valeur : entre les deux premieres quotes
5093 chaine = GetStringInTexte ( ligne, "\"", 1 ) ;
5094 // MESSAGE("chaine 1 = |"<<chaine<<"|");
5095 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5096 // MESSAGE("chaine = |"<<chaine<<"|");
5097 // Le mot_cle : entre les deux dernieres quotes
5098 std::string chaine2 = GetStringInTexte ( ligne, "\"", 2 ) ;
5099 // MESSAGE("chaine2 1 = |"<<chaine2<<"|");
5100 chaine2 = GetStringInTexte ( chaine2, "\"", 3 ) ;
5101 // MESSAGE("chaine2 = |"<<chaine2<<"|");
5103 if ( section_langue )
5104 { if ( chaine2 == "language" ) { LanguageShort = chaine ; } }
5106 if ( section_homard )
5108 std::istringstream chainebis( chaine ) ;
5109 // 3.2.1. Les publications
5110 if ( chaine2 == "publish_mesh_in" ) { chainebis >> PublisMeshIN ; }
5111 if ( chaine2 == "publish_mesh_out" ) { chainebis >> PublisMeshOUT ; }
5112 // 3.2.2. Les maximum pour YACS
5113 if ( chaine2 == "yacs_max_iter" ) { chainebis >> YACSMaxIter ; }
5114 if ( chaine2 == "yacs_max_node" ) { chainebis >> YACSMaxNode ; }
5115 if ( chaine2 == "yacs_max_elem" ) { chainebis >> YACSMaxElem ; }
5116 if ( chaine2 == "yacs_type_test" ) { YACSTypeTestchaine = chaine ; }
5123 // C. Enregistrements
5124 MESSAGE ("Enregistrement de LanguageShort = " << LanguageShort );
5125 SetLanguageShort( LanguageShort.c_str() ) ;
5127 MESSAGE ("Enregistrement de PublisMeshIN = " << PublisMeshIN<<", PublisMeshOUT = "<< PublisMeshOUT);
5128 SetPublisMesh(PublisMeshIN, PublisMeshOUT) ;
5130 MESSAGE ("Enregistrement de YACSMaxIter = " << YACSMaxIter<<", YACSMaxNode = "<< YACSMaxNode<<", YACSMaxElem = "<< YACSMaxElem);
5131 SetYACSMaximum(YACSMaxIter, YACSMaxNode, YACSMaxElem) ;
5133 MESSAGE ("Enregistrement de TypeTest = " << YACSTypeTestchaine.c_str() );
5135 if ( ( YACSTypeTestchaine == "VTest > VRef" ) || ( YACSTypeTestchaine == "VTest > VRef" ) ) { YACSTypeTest = 1 ; }
5136 else if ( ( YACSTypeTestchaine == "VTest < VRef" ) || ( YACSTypeTestchaine == "VTest < VRef" ) ) { YACSTypeTest = 2 ; }
5137 else { YACSTypeTest = 0 ; }
5138 MESSAGE ("==> TypeTest = " << YACSTypeTest );
5139 SetYACSConvergenceType( YACSTypeTest ) ;
5143 //===============================================================================
5145 //===============================================================================
5146 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
5148 // MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
5149 _LangueShort = LanguageShort ;
5150 if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
5151 else { _Langue = "English" ; }
5154 char* HOMARD_Gen_i::GetLanguageShort()
5156 // MESSAGE ("GetLanguageShort");
5157 return CORBA::string_dup( _LangueShort.c_str() );
5159 //===============================================================================
5160 // Options de publications
5161 //===============================================================================
5162 void HOMARD_Gen_i::SetPublisMesh(CORBA::Long PublisMeshIN, CORBA::Long PublisMeshOUT)
5164 _PublisMeshIN = PublisMeshIN ;
5165 _PublisMeshOUT = PublisMeshOUT ;
5168 CORBA::Long HOMARD_Gen_i::GetPublisMeshIN()
5170 return _PublisMeshIN ;
5172 CORBA::Long HOMARD_Gen_i::GetPublisMeshOUT()
5174 return _PublisMeshOUT ;
5176 //===============================================================================
5177 // YACS - test de convergence
5178 //===============================================================================
5179 void HOMARD_Gen_i::SetYACSMaximum(CORBA::Long YACSMaxIter, CORBA::Long YACSMaxNode, CORBA::Long YACSMaxElem)
5181 _YACSMaxIter = YACSMaxIter ;
5182 _YACSMaxNode = YACSMaxNode ;
5183 _YACSMaxElem = YACSMaxElem ;
5186 CORBA::Long HOMARD_Gen_i::GetYACSMaxIter()
5188 return _YACSMaxIter ;
5190 CORBA::Long HOMARD_Gen_i::GetYACSMaxNode()
5192 return _YACSMaxNode ;
5194 CORBA::Long HOMARD_Gen_i::GetYACSMaxElem()
5196 return _YACSMaxElem ;
5198 void HOMARD_Gen_i::SetYACSConvergenceType(CORBA::Long YACSTypeTest)
5200 _YACSTypeTest = YACSTypeTest ;
5203 CORBA::Long HOMARD_Gen_i::GetYACSConvergenceType()
5205 return _YACSTypeTest ;
5208 //=============================================================================
5212 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
5213 PortableServer::POA_ptr poa,
5214 PortableServer::ObjectId* contId,
5215 const char* instanceName,
5216 const char* interfaceName)
5218 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
5219 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
5220 return myHOMARD_Gen->getId();