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 "Basics_Utils.hxx"
37 #include "Utils_SINGLETON.hxx"
38 #include "Utils_CorbaException.hxx"
39 #include "SALOMEDS_Tool.hxx"
40 #include "SALOME_LifeCycleCORBA.hxx"
41 #include "SALOMEconfig.h"
42 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
43 #include CORBA_CLIENT_HEADER(SMESH_Gen)
66 //=============================================================================
68 //=============================================================================
69 std::string RemoveTabulation( std::string theScript )
71 std::string::size_type aPos = 0;
72 while( aPos < theScript.length() )
74 aPos = theScript.find( "\n\t", aPos );
75 if( aPos == std::string::npos )
77 theScript.replace( aPos, 2, "\n" );
82 //=============================================================================
84 * standard constructor
86 //=============================================================================
87 HOMARD_Gen_i::HOMARD_Gen_i( CORBA::ORB_ptr orb,
88 PortableServer::POA_ptr poa,
89 PortableServer::ObjectId * contId,
90 const char *instanceName,
91 const char *interfaceName) :
92 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
94 MESSAGE("constructor");
96 _id = _poa->activate_object(_thisObj);
98 myHomard = new ::HOMARD_Gen();
99 _NS = SINGLETON_<SALOME_NamingService>::Instance();
100 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
111 //=================================
113 * standard destructor
115 //================================
116 HOMARD_Gen_i::~HOMARD_Gen_i()
119 //=============================================================================
120 //=============================================================================
121 // Utilitaires pour l'étude
122 //=============================================================================
123 //=============================================================================
124 void HOMARD_Gen_i::addInStudy(SALOMEDS::Study_ptr theStudy)
126 ASSERT(!CORBA::is_nil(theStudy));
127 MESSAGE("addInStudy: ajout eventuel du composant HOMARD dans current study ID = " << GetCurrentStudyID()) ;
128 SALOMEDS::StudyBuilder_var myBuilder = theStudy->NewBuilder();
130 // Create SComponent labelled 'homard' if it doesn't already exit
131 SALOMEDS::SComponent_var homardFather = theStudy->FindComponent(ComponentDataType());
132 if (CORBA::is_nil(homardFather))
134 myBuilder->NewCommand();
135 MESSAGE("Add Component HOMARD");
137 bool aLocked = theStudy->GetProperties()->IsLocked();
138 if (aLocked) theStudy->GetProperties()->SetLocked(false);
140 homardFather = myBuilder->NewComponent(ComponentDataType());
141 SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
142 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
143 CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
144 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
145 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
146 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
147 if (!Comp->_is_nil())
149 aName->SetValue(ComponentDataType());
152 anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributePixMap");
153 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
154 aPixmap->SetPixMap("HOMARD_2.png");
155 myBuilder->DefineComponentInstance(homardFather, HOMARD_Gen::_this());
157 if (aLocked) theStudy->GetProperties()->SetLocked(true);
158 myBuilder->CommitCommand();
161 //=============================================================================
162 void HOMARD_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy)
164 MESSAGE("SetCurrentStudy: current study Id = " << GetCurrentStudyID());
165 myCurrentStudy = SALOMEDS::Study::_duplicate(theStudy);
166 this->addInStudy(myCurrentStudy);
168 //=============================================================================
169 SALOMEDS::Study_ptr HOMARD_Gen_i::GetCurrentStudy()
170 //=============================================================================
172 MESSAGE("GetCurrentStudy: study Id = " << GetCurrentStudyID());
173 return SALOMEDS::Study::_duplicate(myCurrentStudy);
175 //=============================================================================
176 CORBA::Long HOMARD_Gen_i::GetCurrentStudyID()
177 //=============================================================================
179 return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId();
181 //=============================================================================
182 //=============================================================================
184 //=============================================================================
185 //=============================================================================
186 // Utilitaires pour l'iteration
187 //=============================================================================
188 //=============================================================================
189 void HOMARD_Gen_i::SetEtatIter(const char* nomIter, const CORBA::Long Etat)
190 //=====================================================================================
192 MESSAGE( "SetEtatIter : affectation de l'etat " << Etat << " a l'iteration " << nomIter );
193 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
194 if (CORBA::is_nil(myIteration))
196 SALOME::ExceptionStruct es;
197 es.type = SALOME::BAD_PARAM;
198 es.text = "Invalid iteration";
199 throw SALOME::SALOME_Exception(es);
203 myIteration->SetState(Etat);
205 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
206 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
210 icone = "iter0.png" ;
211 else if ( Etat == 2 )
212 icone = "iter_calculee.png" ;
214 icone = "iter_non_calculee.png" ;
215 PublishInStudyAttr(aStudyBuilder, aIterSO, NULL , NULL, icone.c_str(), NULL) ;
217 aStudyBuilder->CommitCommand();
220 //=============================================================================
221 //=============================================================================
223 //=============================================================================
224 //=============================================================================
225 // Destruction des structures identifiees par leurs noms
226 //=============================================================================
227 //=============================================================================
228 CORBA::Long HOMARD_Gen_i::DeleteBoundary(const char* BoundaryName)
230 MESSAGE ( "DeleteBoundary : BoundaryName = " << BoundaryName );
231 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
232 if (CORBA::is_nil(myBoundary))
234 SALOME::ExceptionStruct es;
235 es.type = SALOME::BAD_PARAM;
236 es.text = "Invalid boundary";
237 throw SALOME::SALOME_Exception(es);
241 // On verifie que la frontiere n'est plus utilisee
242 HOMARD::listeCases* maListe = GetAllCasesName();
243 int numberOfCases = maListe->length();
244 MESSAGE ( ".. Nombre de cas = " << numberOfCases );
245 std::string CaseName ;
246 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType ;
248 HOMARD::HOMARD_Cas_var myCase ;
249 for (int NumeCas = 0; NumeCas< numberOfCases; NumeCas++)
251 CaseName = std::string((*maListe)[NumeCas]);
252 MESSAGE ( "... Examen du cas = " << CaseName.c_str() );
253 myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
254 ASSERT(!CORBA::is_nil(myCase));
255 ListBoundaryGroupType = myCase->GetBoundaryGroup();
256 numberOfitems = ListBoundaryGroupType->length();
257 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
258 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
260 if ( std::string((*ListBoundaryGroupType)[NumBoundary]) == BoundaryName )
262 SALOME::ExceptionStruct es;
263 es.type = SALOME::BAD_PARAM;
264 es.text = "This boundary is used in a case and cannot be deleted.";
265 throw SALOME::SALOME_Exception(es);
271 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
272 myContextMap[GetCurrentStudyID()]._mesBoundarys.erase(BoundaryName);
273 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(BoundaryName, ComponentDataType());
274 SALOMEDS::SObject_var aSO =listSO[0];
275 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
276 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
280 //=============================================================================
281 CORBA::Long HOMARD_Gen_i::DeleteCase(const char* nomCas, CORBA::Long Option)
283 // Pour detruire un cas
284 MESSAGE ( "DeleteCase : nomCas = " << nomCas << ", avec option = " << Option );
285 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
286 if (CORBA::is_nil(myCase))
288 SALOME::ExceptionStruct es;
289 es.type = SALOME::BAD_PARAM;
290 es.text = "Invalid case context";
291 throw SALOME::SALOME_Exception(es);
294 // On commence par detruire toutes les iterations en partant de l'initiale et y compris elle
295 CORBA::String_var nomIter = myCase->GetIter0Name();
296 CORBA::Long Option1 = 0 ;
297 if ( DeleteIterationOption(nomIter, Option1, Option) != 0 )
302 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
303 myContextMap[GetCurrentStudyID()]._mesCas.erase(nomCas);
304 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomCas, ComponentDataType());
305 SALOMEDS::SObject_var aSO =listSO[0];
306 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
307 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
311 //=============================================================================
312 CORBA::Long HOMARD_Gen_i::DeleteHypo(const char* nomHypo)
314 MESSAGE ( "DeleteHypo : nomHypo = " << nomHypo );
315 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
316 if (CORBA::is_nil(myHypo))
318 SALOME::ExceptionStruct es;
319 es.type = SALOME::BAD_PARAM;
320 es.text = "Invalid hypothesis";
321 throw SALOME::SALOME_Exception(es);
325 // On verifie que l'hypothese n'est plus utilisee
326 HOMARD::listeIters* maListeIter = myHypo->GetIterations();
327 int numberOfIter = maListeIter->length();
328 if ( numberOfIter > 0 )
330 SALOME::ExceptionStruct es;
331 es.type = SALOME::BAD_PARAM;
332 es.text = "This hypothesis is used in an iteration and cannot be deleted.";
333 throw SALOME::SALOME_Exception(es);
337 // suppression du lien avec les zones eventuelles
338 HOMARD::listeZonesHypo* maListe = myHypo->GetZones();
339 int numberOfZones = maListe->length();
340 MESSAGE ( ".. Nombre de zones = " << numberOfZones );
341 for (int NumeZone = 0; NumeZone< numberOfZones; NumeZone++)
343 std::string ZoneName = std::string((*maListe)[NumeZone]);
344 MESSAGE ( ".. suppression du lien avec la zone = " << ZoneName.c_str() );
345 DissociateHypoZone(nomHypo, ZoneName.c_str()) ;
349 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
350 myContextMap[GetCurrentStudyID()]._mesHypotheses.erase(nomHypo);
351 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomHypo, ComponentDataType());
352 SALOMEDS::SObject_var aSO =listSO[0];
353 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
354 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
358 //=============================================================================
359 CORBA::Long HOMARD_Gen_i::DeleteIteration(const char* nomIter, CORBA::Long Option)
361 // Option = 0 : On ne supprime pas le fichier du maillage associe
362 // Option = 1 : On supprime le fichier du maillage associe
363 // Pour detruire une iteration courante
364 MESSAGE ( "DeleteIteration : nomIter = " << nomIter << ", avec option = " << Option );
365 CORBA::Long Option1 = 1 ;
366 return DeleteIterationOption(nomIter, Option1, Option);
368 //=============================================================================
369 CORBA::Long HOMARD_Gen_i::DeleteIterationOption(const char* nomIter, CORBA::Long Option1, CORBA::Long Option2)
371 // Option1 = 0 : On autorise la destruction de l'iteration 0
372 // Option1 = 1 : On interdit la destruction de l'iteration 0
374 // Option2 = 0 : On ne supprime pas le fichier du maillage associe
375 // Option2 = 1 : On supprime le fichier du maillage associe
376 MESSAGE ( "DeleteIterationOption : nomIter = " << nomIter << ", avec options = " << Option1<< ", " << Option2 );
377 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
378 if (CORBA::is_nil(myIteration))
380 SALOME::ExceptionStruct es;
381 es.type = SALOME::BAD_PARAM;
382 es.text = "Invalid iteration";
383 throw SALOME::SALOME_Exception(es);
387 int numero = myIteration->GetNumber();
388 MESSAGE ( "DeleteIterationOption : numero = " << numero );
389 if ( numero == 0 && Option1 == 1 )
391 SALOME::ExceptionStruct es;
392 es.type = SALOME::BAD_PARAM;
393 es.text = "This iteration cannot be deleted.";
394 throw SALOME::SALOME_Exception(es);
398 // On detruit recursivement toutes les filles
399 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
400 int numberOfIter = maListe->length();
401 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
403 std::string nomIterFille = std::string((*maListe)[NumeIter]);
404 MESSAGE ( ".. appel recursif de DeleteIterationOption pour nomIter = " << nomIterFille.c_str() );
405 DeleteIterationOption(nomIterFille.c_str(), Option1, Option2);
408 // On arrive ici pour une iteration sans fille
409 MESSAGE ( "Destruction effective de " << nomIter );
410 // On commence par invalider l'iteration pour faire le menage des dependances
411 // et eventuellement du maillage associe
413 if ( numero == 0 ) { option = 0 ; }
414 else { option = Option2 ; }
415 InvalideIterOption(nomIter, option) ;
417 // Retrait dans la descendance de l'iteration parent
420 std::string nomIterationParent = myIteration->GetIterParentName();
421 MESSAGE ( "Retrait dans la descendance de nomIterationParent " << nomIterationParent );
422 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
423 if (CORBA::is_nil(myIterationParent))
425 SALOME::ExceptionStruct es;
426 es.type = SALOME::BAD_PARAM;
427 es.text = "Invalid iteration";
428 throw SALOME::SALOME_Exception(es);
431 myIterationParent->UnLinkNextIteration(nomIter);
434 // suppression du lien avec l'hypothese
437 std::string nomHypo = myIteration->GetHypoName();
438 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
439 ASSERT(!CORBA::is_nil(myHypo));
440 myHypo->UnLinkIteration(nomIter);
443 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
444 myContextMap[GetCurrentStudyID()]._mesIterations.erase(nomIter);
445 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomIter, ComponentDataType());
446 SALOMEDS::SObject_var aSO =listSO[0];
447 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
448 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
449 // on peut aussi faire RemoveObject
450 // MESSAGE ( "Au final" );
451 // HOMARD::listeIterations* Liste = GetAllIterationsName() ;
452 // numberOfIter = Liste->length();
453 // for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
455 // std::string nomIterFille = std::string((*Liste)[NumeIter]);
456 // MESSAGE ( ".. nomIter = " << nomIterFille.c_str() );
461 //=============================================================================
462 CORBA::Long HOMARD_Gen_i::DeleteYACS(const char* nomYACS, CORBA::Long Option)
464 // Option = 0 : On ne supprime pas le fichier du schema associe
465 // Option = 1 : On supprime le fichier du schema associe
466 MESSAGE ( "DeleteYACS : nomYACS = " << nomYACS << ", avec option = " << Option );
467 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
468 if (CORBA::is_nil(myYACS))
470 SALOME::ExceptionStruct es;
471 es.type = SALOME::BAD_PARAM;
472 es.text = "Invalid schema YACS";
473 throw SALOME::SALOME_Exception(es);
476 // Suppression eventuelle du fichier XML
479 std::string nomFichier = myYACS->GetXMLFile();
480 std::string commande = "rm -rf " + nomFichier ;
481 MESSAGE ( "commande = " << commande );
482 if ((system(commande.c_str())) != 0)
484 SALOME::ExceptionStruct es;
485 es.type = SALOME::BAD_PARAM;
486 es.text = "The xml file for the schema YACS cannot be removed." ;
487 throw SALOME::SALOME_Exception(es);
491 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
492 myContextMap[GetCurrentStudyID()]._mesYACSs.erase(nomYACS);
493 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomYACS, ComponentDataType());
494 SALOMEDS::SObject_var aSO =listSO[0];
495 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
496 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
500 //=============================================================================
501 CORBA::Long HOMARD_Gen_i::DeleteZone(const char* nomZone)
503 MESSAGE ( "DeleteZone : nomZone = " << nomZone );
504 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[nomZone];
505 if (CORBA::is_nil(myZone))
507 SALOME::ExceptionStruct es;
508 es.type = SALOME::BAD_PARAM;
509 es.text = "Invalid zone";
510 throw SALOME::SALOME_Exception(es);
514 // On verifie que la zone n'est plus utilisee
515 HOMARD::listeHypo* maListe = myZone->GetHypo();
516 int numberOfHypo = maListe->length();
517 MESSAGE ( ".. Nombre d'hypotheses = " << numberOfHypo );
518 if ( numberOfHypo > 0 )
520 SALOME::ExceptionStruct es;
521 es.type = SALOME::BAD_PARAM;
522 es.text = "This zone is used in an hypothesis and cannot be deleted.";
523 throw SALOME::SALOME_Exception(es);
527 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
528 myContextMap[GetCurrentStudyID()]._mesZones.erase(nomZone);
529 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomZone, ComponentDataType());
530 SALOMEDS::SObject_var aSO =listSO[0];
531 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
532 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
536 //=============================================================================
537 //=============================================================================
539 //=============================================================================
540 //=============================================================================
541 // Invalidation des structures identifiees par leurs noms
542 //=============================================================================
543 //=============================================================================
544 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
546 MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName );
547 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
548 if (CORBA::is_nil(myBoundary))
550 SALOME::ExceptionStruct es;
551 es.type = SALOME::BAD_PARAM;
552 es.text = "Invalid boundary";
553 throw SALOME::SALOME_Exception(es);
558 SALOME::ExceptionStruct es;
559 es.type = SALOME::BAD_PARAM;
560 es.text = "No change is allowed in a boundary. Ask for evolution.";
561 throw SALOME::SALOME_Exception(es);
565 //=============================================================================
566 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
568 MESSAGE( "InvalideHypo : nomHypo = " << nomHypo );
569 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
570 if (CORBA::is_nil(myHypo))
572 SALOME::ExceptionStruct es;
573 es.type = SALOME::BAD_PARAM;
574 es.text = "Invalid hypothesis";
575 throw SALOME::SALOME_Exception(es);
579 HOMARD::listeIters* maListe = myHypo->GetIterations();
580 int numberOfIter = maListe->length();
581 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
583 std::string nomIter = std::string((*maListe)[NumeIter]);
584 MESSAGE( ".. nomIter = " << nomIter );
585 InvalideIter(nomIter.c_str());
588 //=============================================================================
589 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
591 MESSAGE("InvalideIter : nomIter = " << nomIter);
592 // Pour invalider totalement une iteration courante
593 CORBA::Long Option = 1 ;
594 return InvalideIterOption(nomIter, Option);
596 //=============================================================================
597 void HOMARD_Gen_i::InvalideIterOption(const char* nomIter, CORBA::Long Option)
599 // Option = 0 : On ne supprime pas le fichier du maillage associe
600 // Option = 1 : On supprime le fichier du maillage associe
601 MESSAGE ( "InvalideIterOption : nomIter = " << nomIter << ", avec option = " << Option );
602 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
603 if (CORBA::is_nil(myIteration))
605 SALOME::ExceptionStruct es;
606 es.type = SALOME::BAD_PARAM;
607 es.text = "Invalid iteration";
608 throw SALOME::SALOME_Exception(es);
612 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
613 int numberOfIter = maListe->length();
614 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
616 std::string nomIterFille = std::string((*maListe)[NumeIter]);
617 MESSAGE ( ".. appel recursif de InvalideIter pour nomIter = " << nomIterFille.c_str() );
618 InvalideIter(nomIterFille.c_str());
621 // On arrive ici pour une iteration sans fille
622 MESSAGE ( "Invalidation effective de " << nomIter );
623 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
624 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
625 for (; aIter->More(); aIter->Next())
627 SALOMEDS::SObject_var so = aIter->Value();
628 SALOMEDS::GenericAttribute_var anAttr;
629 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
630 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
631 std::string value (aCommentAttr->Value());
632 if(value == std::string("IterationHomard")) continue;
633 if(value == std::string("HypoHomard")) continue;
634 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
635 aStudyBuilder->RemoveObject(so);
638 int etat = myIteration->GetState();
641 SetEtatIter(nomIter,1);
642 const char * nomCas = myIteration->GetCaseName();
643 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
644 if (CORBA::is_nil(myCase))
646 SALOME::ExceptionStruct es;
647 es.type = SALOME::BAD_PARAM;
648 es.text = "Invalid case context";
649 throw SALOME::SALOME_Exception(es);
652 std::string nomDir = myIteration->GetDirName();
653 std::string nomFichier = myIteration->GetMeshFile();
654 std::string commande = "rm -rf " + std::string(nomDir);
655 if ( Option == 1 ) { commande = commande + ";rm -rf " + std::string(nomFichier) ; }
656 MESSAGE ( "commande = " << commande );
657 if ((system(commande.c_str())) != 0)
659 SALOME::ExceptionStruct es;
660 es.type = SALOME::BAD_PARAM;
661 es.text = "The directory for the calculation cannot be cleared." ;
662 throw SALOME::SALOME_Exception(es);
665 // Suppression du maillage publie dans SMESH
666 std::string MeshName = myIteration->GetMeshName() ;
667 DeleteResultInSmesh(nomFichier, MeshName) ;
671 //=============================================================================
672 void HOMARD_Gen_i::InvalideIterInfo(const char* nomIter)
674 MESSAGE("InvalideIterInfo : nomIter = " << nomIter);
675 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
676 if (CORBA::is_nil(myIteration))
678 SALOME::ExceptionStruct es;
679 es.type = SALOME::BAD_PARAM;
680 es.text = "Invalid iteration";
681 throw SALOME::SALOME_Exception(es);
685 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
686 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
687 for (; aIter->More(); aIter->Next())
689 SALOMEDS::SObject_var so = aIter->Value();
690 SALOMEDS::GenericAttribute_var anAttr;
691 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
692 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
693 std::string value (aCommentAttr->Value());
694 /* MESSAGE("... value = " << value);*/
695 if( (value == std::string("logInfo")) || ( value == std::string("SummaryInfo")) )
697 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
698 aStudyBuilder->RemoveObject(so);
702 const char * nomCas = myIteration->GetCaseName();
703 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
704 if (CORBA::is_nil(myCase))
706 SALOME::ExceptionStruct es;
707 es.type = SALOME::BAD_PARAM;
708 es.text = "Invalid case context";
709 throw SALOME::SALOME_Exception(es);
712 const char* nomDir = myIteration->GetDirName();
713 std::string commande = "rm -f " + std::string(nomDir) + "/info* " ;
714 commande += std::string(nomDir) + "/Liste.*info" ;
715 /* MESSAGE ( "commande = " << commande );*/
716 if ((system(commande.c_str())) != 0)
718 SALOME::ExceptionStruct es;
719 es.type = SALOME::BAD_PARAM;
720 es.text = "The directory for the calculation cannot be cleared." ;
721 throw SALOME::SALOME_Exception(es);
725 //=============================================================================
726 void HOMARD_Gen_i::InvalideYACS(const char* YACSName)
728 MESSAGE( "InvalideYACS : YACSName = " << YACSName );
729 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[YACSName];
730 if (CORBA::is_nil(myYACS))
732 SALOME::ExceptionStruct es;
733 es.type = SALOME::BAD_PARAM;
734 es.text = "Invalid schema YACS";
735 throw SALOME::SALOME_Exception(es);
739 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
740 SALOMEDS::ChildIterator_var aYACS = myCurrentStudy->NewChildIterator(aYACSSO);
741 for (; aYACS->More(); aYACS->Next())
743 SALOMEDS::SObject_var so = aYACS->Value();
744 SALOMEDS::GenericAttribute_var anAttr;
745 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
746 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
747 std::string value (aCommentAttr->Value());
748 if( value == std::string("xml") )
750 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
751 aStudyBuilder->RemoveObject(so);
754 std::string nomFichier = myYACS->GetXMLFile();
755 std::string commande = "rm -rf " + std::string(nomFichier) ;
756 MESSAGE ( "commande = " << commande );
757 if ((system(commande.c_str())) != 0)
759 SALOME::ExceptionStruct es;
760 es.type = SALOME::BAD_PARAM;
761 es.text = "The XML file for the schema YACS cannot be removed." ;
762 throw SALOME::SALOME_Exception(es);
766 //=============================================================================
767 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
769 MESSAGE( "InvalideZone : ZoneName = " << ZoneName );
770 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
771 if (CORBA::is_nil(myZone))
773 SALOME::ExceptionStruct es;
774 es.type = SALOME::BAD_PARAM;
775 es.text = "Invalid zone";
776 throw SALOME::SALOME_Exception(es);
779 HOMARD::listeHypo* maListe = myZone->GetHypo();
780 int numberOfHypo = maListe->length();
781 MESSAGE( ".. numberOfHypo = " << numberOfHypo );
782 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
784 std::string nomHypo = std::string((*maListe)[NumeHypo]);
785 MESSAGE( ".. nomHypo = " << nomHypo );
786 InvalideHypo(nomHypo.c_str());
789 //=============================================================================
790 //=============================================================================
792 //=============================================================================
793 //=============================================================================
794 // Association de lien entre des structures identifiees par leurs noms
795 //=============================================================================
796 //=============================================================================
797 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
799 MESSAGE( "AssociateCaseIter : " << nomCas << ", " << nomIter << ", " << labelIter );
801 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
802 if (CORBA::is_nil(myCase))
804 SALOME::ExceptionStruct es;
805 es.type = SALOME::BAD_PARAM;
806 es.text = "Invalid case";
807 throw SALOME::SALOME_Exception(es);
811 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
812 if (CORBA::is_nil(myIteration))
814 SALOME::ExceptionStruct es;
815 es.type = SALOME::BAD_PARAM;
816 es.text = "Invalid iteration";
817 throw SALOME::SALOME_Exception(es);
821 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
822 SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
823 if (CORBA::is_nil(aCasSO))
825 SALOME::ExceptionStruct es;
826 es.type = SALOME::BAD_PARAM;
827 es.text = "Invalid case";
828 throw SALOME::SALOME_Exception(es);
832 aStudyBuilder->NewCommand();
833 SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
834 PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
835 "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
836 aStudyBuilder->CommitCommand();
838 myCase->AddIteration(nomIter);
839 myIteration->SetCaseName(nomCas);
841 //=====================================================================================
842 void HOMARD_Gen_i::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
844 MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
846 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
847 ASSERT(!CORBA::is_nil(myHypo));
848 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
849 ASSERT(!CORBA::is_nil(aHypoSO));
851 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
852 ASSERT(!CORBA::is_nil(myZone));
853 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
854 ASSERT(!CORBA::is_nil(aZoneSO));
856 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
858 aStudyBuilder->NewCommand();
860 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
861 aStudyBuilder->Addreference(aSubSO, aZoneSO);
863 aStudyBuilder->CommitCommand();
865 myZone->AddHypo(nomHypothesis);
866 myHypo->AddZone0(ZoneName, TypeUse);
868 //=============================================================================
869 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
871 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
873 // Verification de l'existence de l'hypothese
874 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
875 ASSERT(!CORBA::is_nil(myHypo));
876 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
877 ASSERT(!CORBA::is_nil(aHypoSO));
879 // Verification de l'existence de l'iteration
880 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
881 ASSERT(!CORBA::is_nil(myIteration));
882 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
883 ASSERT(!CORBA::is_nil(aIterSO));
885 // Gestion de l'arbre d'etudes
886 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
887 aStudyBuilder->NewCommand();
888 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
889 aStudyBuilder->Addreference(aSubSO, aHypoSO);
890 aStudyBuilder->CommitCommand();
893 myIteration->SetHypoName(nomHypo);
894 myHypo->LinkIteration(nomIter);
896 // On stocke les noms des champ a interpoler pour le futur controle de la donnee des pas de temps
897 myIteration->SupprFieldInterps() ;
898 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
899 int numberOfFieldsx2 = ListField->length();
900 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
902 std::string FieldName = std::string((*ListField)[iaux]) ;
903 myIteration->SetFieldInterp(FieldName.c_str()) ;
907 //=============================================================================
908 //=============================================================================
910 //=============================================================================
911 //=============================================================================
912 // Dissociation de lien entre des structures identifiees par leurs noms
913 //=============================================================================
914 //=============================================================================
915 void HOMARD_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
917 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
919 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
920 ASSERT(!CORBA::is_nil(myHypo));
921 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
922 ASSERT(!CORBA::is_nil(aHypoSO));
924 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
925 ASSERT(!CORBA::is_nil(myZone));
926 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
927 ASSERT(!CORBA::is_nil(aZoneSO));
929 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
931 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator(aHypoSO);
932 for (; it->More(); it->Next())
934 SALOMEDS::SObject_var aHypObj = it->Value();
935 SALOMEDS::SObject_var ptrObj;
936 if (aHypObj->ReferencedObject(ptrObj))
938 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
940 aStudyBuilder->NewCommand();
941 aStudyBuilder->RemoveObject(aHypObj);
942 aStudyBuilder->CommitCommand();
948 myZone->SupprHypo(nomHypothesis);
949 myHypo->SupprZone(ZoneName);
951 //=============================================================================
952 //=============================================================================
955 //=============================================================================
956 //=============================================================================
957 // Recuperation des listes
958 //=============================================================================
959 //=============================================================================
960 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
962 MESSAGE("GetAllBoundarysName");
965 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
966 ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
967 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
969 for (it = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
970 it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
972 ret[i++] = CORBA::string_dup((*it).first.c_str());
977 //=============================================================================
978 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
980 MESSAGE("GetAllCasesName");
983 HOMARD::listeCases_var ret = new HOMARD::listeCases;
984 ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
985 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
987 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
988 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
990 ret[i++] = CORBA::string_dup((*it).first.c_str());
995 //=============================================================================
996 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
998 MESSAGE("GetAllHypothesesName");
1001 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
1002 ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
1003 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
1005 for (it = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
1006 it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
1008 ret[i++] = CORBA::string_dup((*it).first.c_str());
1013 //=============================================================================
1014 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
1016 MESSAGE("GetAllIterationsName");
1019 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
1020 ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
1021 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
1023 for (it = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
1024 it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
1026 ret[i++] = CORBA::string_dup((*it).first.c_str());
1031 //=============================================================================
1032 HOMARD::listeYACSs* HOMARD_Gen_i::GetAllYACSsName()
1034 MESSAGE("GetAllYACSsName");
1037 HOMARD::listeYACSs_var ret = new HOMARD::listeYACSs;
1038 ret->length(myContextMap[GetCurrentStudyID()]._mesYACSs.size());
1039 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it;
1041 for (it = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
1042 it != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); it++)
1044 ret[i++] = CORBA::string_dup((*it).first.c_str());
1049 //=============================================================================
1050 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
1052 MESSAGE("GetAllZonesName");
1055 HOMARD::listeZones_var ret = new HOMARD::listeZones;
1056 ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
1057 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
1059 for (it = myContextMap[GetCurrentStudyID()]._mesZones.begin();
1060 it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
1062 ret[i++] = CORBA::string_dup((*it).first.c_str());
1067 //=============================================================================
1068 //=============================================================================
1070 //=============================================================================
1071 //=============================================================================
1072 // Recuperation des structures identifiees par leurs noms
1073 //=============================================================================
1074 //=============================================================================
1075 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
1077 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
1078 ASSERT(!CORBA::is_nil(myBoundary));
1079 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1081 //=============================================================================
1082 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
1084 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1085 ASSERT(!CORBA::is_nil(myCase));
1086 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1088 //=============================================================================
1089 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
1091 HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
1092 ASSERT(!CORBA::is_nil(myHypothesis));
1093 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1095 //=============================================================================
1096 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* NomIterationation)
1098 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIterationation];
1099 ASSERT(!CORBA::is_nil(myIteration));
1100 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1102 //=============================================================================
1103 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::GetYACS(const char* nomYACS)
1105 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
1106 ASSERT(!CORBA::is_nil(myYACS));
1107 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
1109 //=============================================================================
1110 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
1112 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1113 ASSERT(!CORBA::is_nil(myZone));
1114 return HOMARD::HOMARD_Zone::_duplicate(myZone);
1116 //=============================================================================
1117 //=============================================================================
1119 //=============================================================================
1120 //=============================================================================
1122 //=============================================================================
1123 //=============================================================================
1124 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)
1126 INFOS ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1127 INFOS ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte );
1132 if ( _PublisMeshIN != 0 ) option = 2 ;
1133 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, 0, option) ;
1134 myCase->SetDirName(DirName) ;
1136 myCase->MeshInfo(Qual, Diam, Conn, Tail, Inte) ;
1140 //=============================================================================
1141 //=============================================================================
1143 //=============================================================================
1144 //=============================================================================
1145 // Recuperation des structures par le contexte
1146 //=============================================================================
1147 //=============================================================================
1148 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::LastIteration(const char* nomCas)
1150 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1151 ASSERT(!CORBA::is_nil(myCase));
1153 HOMARD::HOMARD_Iteration_var myIteration = myCase->LastIteration();
1154 ASSERT(!CORBA::is_nil(myIteration));
1156 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1158 //=============================================================================
1159 //=============================================================================
1161 //=============================================================================
1162 //=============================================================================
1163 // Nouvelles structures
1164 //=============================================================================
1165 //=============================================================================
1166 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1168 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1169 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
1170 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
1171 return aCase._retn();
1173 //=============================================================================
1174 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
1176 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1177 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
1178 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
1179 return aHypo._retn();
1181 //=============================================================================
1182 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
1184 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1185 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
1186 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
1187 return aIter._retn();
1189 //=============================================================================
1190 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1192 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1193 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
1194 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1195 return aBoundary._retn();
1197 //=============================================================================
1198 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
1200 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1201 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
1202 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
1203 return aZone._retn();
1205 //=============================================================================
1206 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::newYACS()
1208 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1209 HOMARD_YACS_i* aServant = new HOMARD_YACS_i(_orb, engine);
1210 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(aServant->_this());
1211 return aYACS._retn();
1213 //=============================================================================
1214 //=============================================================================
1216 //=============================================================================
1217 //=============================================================================
1218 // Creation des structures identifiees par leurs noms
1219 //=============================================================================
1220 //=============================================================================
1221 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
1223 // Creation d'un cas initial
1224 // nomCas : nom du cas a creer
1225 // MeshName, MeshFile : nom et fichier du maillage correspondant
1228 INFOS ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1231 if ( _PublisMeshIN != 0 ) option = 2 ;
1232 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 0, 0, option) ;
1234 // Valeurs par defaut des filtrages
1235 myCase->SetPyram(0);
1237 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1239 //=============================================================================
1240 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromIteration(const char* nomCas, const char* DirNameStart)
1242 // nomCas : nom du cas a creer
1243 // DirNameStart : nom du repertoire contenant l'iteration de reprise
1246 INFOS ( "CreateCaseFromIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1247 std::string nomDirWork = getenv("PWD") ;
1250 // A. Decodage du point de reprise
1251 // A.1. Controle du repertoire de depart de l'iteration
1252 codret = CHDIR(DirNameStart) ;
1255 SALOME::ExceptionStruct es;
1256 es.type = SALOME::BAD_PARAM;
1257 es.text = "The directory of the iteration does not exist.";
1258 throw SALOME::SALOME_Exception(es);
1261 // A.2. Reperage des fichiers du repertoire de reprise
1262 std::string file_configuration = "" ;
1263 std::string file_maillage_homard = "" ;
1267 struct dirent *dirp;
1268 dp = opendir(DirNameStart);
1269 while ( (dirp = readdir(dp)) != NULL )
1271 std::string file_name(dirp->d_name);
1272 // MESSAGE ( file_name );
1273 bilan = file_name.find("HOMARD.Configuration.") ;
1274 if ( bilan != string::npos ) { file_configuration = file_name ; }
1275 bilan = file_name.find("maill.") ;
1276 if ( bilan != string::npos )
1278 bilan = file_name.find(".hom.med") ;
1279 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1284 HANDLE hFind = INVALID_HANDLE_VALUE;
1285 WIN32_FIND_DATA ffd;
1286 hFind = FindFirstFile(DirNameStart, &ffd);
1287 if (INVALID_HANDLE_VALUE != hFind) {
1288 while (FindNextFile(hFind, &ffd) != 0) {
1289 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1290 std::string file_name(ffd.cFileName);
1291 bilan = file_name.find("HOMARD.Configuration.") ;
1292 if ( bilan != string::npos ) { file_configuration = file_name ; }
1293 bilan = file_name.find("maill.") ;
1294 if ( bilan != string::npos )
1296 bilan = file_name.find(".hom.med") ;
1297 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1303 MESSAGE ( "==> file_configuration : " << file_configuration ) ;
1304 MESSAGE ( "==> file_maillage_homard : " << file_maillage_homard ) ;
1306 if ( ( file_configuration == "" ) || ( file_maillage_homard == "" ) )
1308 SALOME::ExceptionStruct es;
1309 es.type = SALOME::BAD_PARAM;
1311 if ( file_configuration == "" ) { text = "The configuration file cannot be found." ; }
1312 else { text = "The HOMARD mesh file cannot be found." ; }
1313 es.text = CORBA::string_dup(text.c_str());
1314 throw SALOME::SALOME_Exception(es);
1317 // B. Lecture du fichier de configuration
1318 // ATTENTION : on doit veiller a la coherence entre HomardDriver et CreateCaseFromIteration
1325 // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1326 std::ifstream fichier( file_configuration.c_str() );
1327 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1329 std::string ligne; // variable contenant chaque ligne lue
1330 std::string mot_cle;
1331 std::string argument;
1333 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1334 while ( std::getline( fichier, ligne ) )
1336 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1337 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1338 ligne_bis >> mot_cle ;
1339 // B.2. Des valeurs entieres : le second bloc de la ligne
1340 if ( mot_cle == "NumeIter" )
1342 ligne_bis >> NumeIter ;
1345 // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1346 else if ( ( mot_cle == "TypeConf" ) || ( mot_cle == "TypeElem" ) )
1348 ligne_bis >> argument ;
1350 if ( mot_cle == "TypeConf" )
1352 if ( argument == "conforme" ) { TypeConf = 1 ; }
1353 else if ( argument == "non_conforme_1_noeud" ) { TypeConf = 2 ; }
1354 else if ( argument == "non_conforme_1_arete" ) { TypeConf = 3 ; }
1355 else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1357 else if ( mot_cle == "TypeElem" )
1359 if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1360 else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1363 // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1364 // il faut les supprimer
1365 else if ( ( mot_cle == "CCNoMNP1" ) || ( mot_cle == "CCMaiNP1" ) )
1367 ligne_bis >> argument ;
1368 if ( argument[0] == '"' ) { decalage = 1 ; }
1369 else { decalage = 0 ; }
1370 size_t size = argument.size() + 1 - 2*decalage ;
1372 if ( mot_cle == "CCNoMNP1" )
1374 MeshName = new char[ size ];
1375 strncpy( MeshName, argument.c_str()+decalage, size );
1376 MeshName[size-1] = '\0' ;
1378 else if ( mot_cle == "CCMaiNP1" )
1380 MeshFile = new char[ size ];
1381 strncpy( MeshFile, argument.c_str()+decalage, size );
1382 MeshFile[size-1] = '\0' ;
1386 MESSAGE ( "==> TypeConf : " << TypeConf ) ;
1387 MESSAGE ( "==> MeshName : " << MeshName ) ;
1388 MESSAGE ( "==> MeshFile : " << MeshFile ) ;
1389 MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1390 MESSAGE ( "==> Pyram : " << Pyram ) ;
1394 SALOME::ExceptionStruct es;
1395 es.type = SALOME::BAD_PARAM;
1396 std::string text = "The configuration file cannot be read." ;
1397 es.text = CORBA::string_dup(text.c_str());
1398 throw SALOME::SALOME_Exception(es);
1401 // C. Creation effective du cas
1404 if ( _PublisMeshIN != 0 ) option = 2 ;
1405 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, option) ;
1407 // D. Parametrages lus dans le fichier de configuration
1409 myCase->SetConfType (TypeConf) ;
1410 myCase->SetExtType (TypeExt) ;
1411 myCase->SetPyram (Pyram) ;
1413 // E. Copie du fichier de maillage homard
1414 // E.1. Repertoire associe au cas
1415 char* nomDirCase = myCase->GetDirName() ;
1416 // E.2. Repertoire associe a l'iteration de ce cas
1418 IterName = myCase->GetIter0Name() ;
1419 HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1420 char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1421 Iter->SetDirNameLoc(nomDirIter);
1422 std::string nomDirIterTotal ;
1423 nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1425 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1427 if (_mkdir(nomDirIterTotal.c_str()) != 0)
1430 MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1431 SALOME::ExceptionStruct es;
1432 es.type = SALOME::BAD_PARAM;
1433 std::string text = "The directory for the computation cannot be created." ;
1434 es.text = CORBA::string_dup(text.c_str());
1435 throw SALOME::SALOME_Exception(es);
1437 // E.3. Copie du maillage HOMARD au format MED
1438 codret = CHDIR(DirNameStart) ;
1439 std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1440 MESSAGE ( "commande : " << commande ) ;
1441 codret = system(commande.c_str()) ;
1442 MESSAGE ( "codret : " << codret ) ;
1445 SALOME::ExceptionStruct es;
1446 es.type = SALOME::BAD_PARAM;
1447 es.text = "The starting point for the case cannot be copied into the working directory.";
1448 throw SALOME::SALOME_Exception(es);
1457 CHDIR(nomDirWork.c_str());
1458 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1460 //=============================================================================
1461 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1463 // nomCas : nom du cas a creer
1464 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1467 INFOS ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1469 std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1471 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1472 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1474 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1476 //=============================================================================
1477 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1479 // nomCas : nom du cas a creer
1480 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1481 // Number : numero de l'iteration de depart
1484 INFOS ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1487 SALOME::ExceptionStruct es;
1488 es.type = SALOME::BAD_PARAM;
1489 es.text = "The number of iteration must be positive.";
1490 throw SALOME::SALOME_Exception(es);
1494 std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1496 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1497 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1499 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1501 //=============================================================================
1502 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1504 // Retourne le nom du repertoire ou se trouve l'iteration voulue.
1505 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1506 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1509 MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1510 std::string nomDirWork = getenv("PWD") ;
1511 std::string DirNameStartIter ;
1513 int NumeIterMax = -1 ;
1515 // A.1. Controle du repertoire de depart du cas
1516 codret = CHDIR(DirNameStart) ;
1519 SALOME::ExceptionStruct es;
1520 es.type = SALOME::BAD_PARAM;
1521 es.text = "The directory of the case for the pursuit does not exist.";
1522 throw SALOME::SALOME_Exception(es);
1525 // A.2. Reperage des sous-repertoire du repertoire de reprise
1526 bool existe = false ;
1529 struct dirent *dirp;
1530 dp = opendir(DirNameStart);
1531 while ( (dirp = readdir(dp)) != NULL ) {
1532 std::string DirName_1(dirp->d_name);
1534 HANDLE hFind = INVALID_HANDLE_VALUE;
1535 WIN32_FIND_DATA ffd;
1536 hFind = FindFirstFile(DirNameStart, &ffd);
1537 if (INVALID_HANDLE_VALUE != hFind) {
1538 while (FindNextFile(hFind, &ffd) != 0) {
1539 std::string DirName_1 = "";
1540 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1541 DirName_1 = std::string(ffd.cFileName);
1544 if ( ( DirName_1 != "." ) && ( DirName_1 != ".." ) )
1546 if ( CHDIR(DirName_1.c_str()) == 0 )
1548 // On cherche le fichier de configuration dans ce sous-repertoire
1549 codret = CHDIR(DirNameStart);
1552 struct dirent *dirp_1;
1553 dp_1 = opendir(DirName_1.c_str()) ;
1554 while ( (dirp_1 = readdir(dp_1)) != NULL )
1556 std::string file_name_1(dirp_1->d_name);
1558 HANDLE hFind1 = INVALID_HANDLE_VALUE;
1559 WIN32_FIND_DATA ffd1;
1560 hFind1 = FindFirstFile(DirName_1.c_str(), &ffd1);
1561 while (FindNextFile(hFind1, &ffd1) != 0)
1563 if (ffd1.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1564 std::string file_name_1(ffd1.cFileName);
1566 int bilan = file_name_1.find("HOMARD.Configuration.") ;
1567 if ( bilan != string::npos )
1569 // Decodage du fichier pour trouver le numero d'iteration
1570 CHDIR(DirName_1.c_str()) ;
1572 std::ifstream fichier( file_name_1.c_str() );
1573 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1576 std::string ligne; // variable contenant chaque ligne lue
1577 std::string mot_cle;
1578 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1579 while ( std::getline( fichier, ligne ) )
1581 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1582 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1583 ligne_bis >> mot_cle ;
1584 if ( mot_cle == "NumeIter" )
1586 ligne_bis >> NumeIter ;
1588 // MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1589 if ( Number == - 1 )
1591 if ( NumeIter >= NumeIterMax )
1593 NumeIterMax = NumeIter ;
1594 DirNameStartIter = DirName_1 ;
1599 if ( NumeIter == Number )
1601 DirNameStartIter = DirName_1 ;
1611 SALOME::ExceptionStruct es;
1612 es.type = SALOME::BAD_PARAM;
1613 std::string text = "The configuration file cannot be read." ;
1614 es.text = CORBA::string_dup(text.c_str());
1615 throw SALOME::SALOME_Exception(es);
1617 CHDIR(DirNameStart) ;
1619 if ( existe ) { break ; }
1626 if ( existe ) { break ; }
1635 CHDIR(nomDirWork.c_str());
1637 if ( ( Number >= 0 && ( !existe ) ) || ( Number < 0 && ( NumeIterMax == -1 ) ) )
1639 SALOME::ExceptionStruct es;
1640 es.type = SALOME::BAD_PARAM;
1641 es.text = "The directory of the iteration does not exist.";
1642 throw SALOME::SALOME_Exception(es);
1646 return DirNameStartIter ;
1648 //=============================================================================
1649 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)
1651 // nomCas : nom du cas a creer
1652 // MeshName, MeshFile : nom et fichier du maillage correspondant
1653 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1654 // 1 : le maillage fourni peut ne pas exister ==> on continue si absent
1655 // -1 : le maillage n'est pas fourni
1656 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1657 // Option : multiple de nombres premiers
1658 // 1 : aucune option
1659 // x2 : publication du maillage dans SMESH
1661 MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1662 MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1663 MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1669 // A.2. Controle du nom :
1670 if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
1672 SALOME::ExceptionStruct es;
1673 es.type = SALOME::BAD_PARAM;
1674 es.text = "This case has already been defined.";
1675 throw SALOME::SALOME_Exception(es);
1679 // A.3. Controle du fichier du maillage
1680 int existeMeshFile ;
1681 if ( MeshOption >= 0 )
1683 existeMeshFile = MEDFileExist ( MeshFile ) ;
1684 MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1685 if ( ( existeMeshFile == 0 ) && ( MeshOption == 0 ) )
1687 SALOME::ExceptionStruct es;
1688 es.type = SALOME::BAD_PARAM;
1689 es.text = "The mesh file does not exist.";
1690 throw SALOME::SALOME_Exception(es);
1694 else { existeMeshFile = 0 ; }
1696 // B. Creation de l'objet cas et publication
1697 // MESSAGE ( "CreateCase0 : Creation de l'objet" );
1698 HOMARD::HOMARD_Cas_var myCase = newCase();
1699 myCase->SetName(nomCas);
1700 SALOMEDS::SObject_var aSO;
1701 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
1702 myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
1704 // C. Caracteristiques du maillage
1705 if ( existeMeshFile != 0 )
1707 // Les valeurs extremes des coordonnees
1708 // MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnees" );
1709 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1710 HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1711 if (LesExtremes.size()!=10) { return 0; }
1713 for (int i =0 ; i< LesExtremes.size() ; i++)
1714 aSeq[i]=LesExtremes[i] ;
1715 myCase->SetBoundingBox(aSeq) ;
1717 // MESSAGE ( "CreateCase0 : Les groupes" );
1718 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile) ;
1719 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1720 aSeqGroupe->length(LesGroupes.size());
1721 std::set<std::string>::const_iterator it ;
1723 for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1724 aSeqGroupe[i++]=(*it).c_str() ;
1725 myCase->SetGroups(aSeqGroupe) ;
1728 // D. L'iteration initiale du cas
1729 MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1730 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1731 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1733 std::string NomIteration = std::string(MeshName) ;
1734 while ( (myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()) )
1736 std::ostringstream nom;
1737 nom << MeshName << monNum;
1738 NomIteration = nom.str();
1741 MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1743 // D.2. Creation de l'iteration
1744 HOMARD::HOMARD_Iteration_var anIter = newIteration();
1745 myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration] = anIter;
1746 anIter->SetName(NomIteration.c_str());
1747 AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1749 // D.4. Maillage correspondant
1750 if ( existeMeshFile != 0 )
1752 anIter->SetMeshFile(MeshFile);
1753 if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1755 anIter->SetMeshName(MeshName);
1757 // D.5. Numero d'iteration
1758 anIter->SetNumber(NumeIter);
1761 SetEtatIter(NomIteration.c_str(), -NumeIter);
1764 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1766 //=============================================================================
1767 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1769 INFOS ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1772 // A. Controle du nom :
1773 if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
1775 SALOME::ExceptionStruct es;
1776 es.type = SALOME::BAD_PARAM;
1777 es.text = "This hypothesis has already been defined.";
1778 throw SALOME::SALOME_Exception(es);
1782 // B. Creation de l'objet
1783 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1784 if (CORBA::is_nil(myHypothesis))
1786 SALOME::ExceptionStruct es;
1787 es.type = SALOME::BAD_PARAM;
1788 es.text = "Unable to create the hypothesis";
1789 throw SALOME::SALOME_Exception(es);
1792 myHypothesis->SetName(nomHypothesis);
1794 // C. Enregistrement
1795 myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
1797 SALOMEDS::SObject_var aSO;
1798 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
1800 // D. Valeurs par defaut des options avancees
1801 myHypothesis->SetNivMax(-1);
1802 myHypothesis->SetDiamMin(-1.0);
1803 myHypothesis->SetAdapInit(0);
1804 myHypothesis->SetExtraOutput(1);
1806 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1809 //=============================================================================
1810 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1811 //=============================================================================
1813 INFOS ("CreateIteration : NomIteration = " << NomIteration << ", nomIterParent = " << nomIterParent);
1816 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
1817 if (CORBA::is_nil(myIterationParent))
1819 SALOME::ExceptionStruct es;
1820 es.type = SALOME::BAD_PARAM;
1821 es.text = "The parent iteration is not defined.";
1822 throw SALOME::SALOME_Exception(es);
1826 const char* nomCas = myIterationParent->GetCaseName();
1827 MESSAGE ("CreateIteration : nomCas = " << nomCas);
1828 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1829 if (CORBA::is_nil(myCase))
1831 SALOME::ExceptionStruct es;
1832 es.type = SALOME::BAD_PARAM;
1833 es.text = "Invalid case context";
1834 throw SALOME::SALOME_Exception(es);
1837 const char* nomDirCase = myCase->GetDirName();
1839 // Controle du nom :
1840 if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
1842 SALOME::ExceptionStruct es;
1843 es.type = SALOME::BAD_PARAM;
1844 es.text = "This iteration has already been defined.";
1845 throw SALOME::SALOME_Exception(es);
1849 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1850 if (CORBA::is_nil(myIteration))
1852 SALOME::ExceptionStruct es;
1853 es.type = SALOME::BAD_PARAM;
1854 es.text = "Unable to create the iteration";
1855 throw SALOME::SALOME_Exception(es);
1858 myContextMap[GetCurrentStudyID()]._mesIterations[std::string(NomIteration)] = myIteration;
1859 // Nom de l'iteration et du maillage
1860 myIteration->SetName(NomIteration);
1861 myIteration->SetMeshName(NomIteration);
1862 myIteration->SetState(1);
1864 int numero = myIterationParent->GetNumber() + 1;
1865 myIteration->SetNumber(numero);
1867 // Nombre d'iterations deja connues pour le cas, permettant
1868 // la creation d'un sous-repertoire unique
1869 int nbitercase = myCase->GetNumberofIter();
1870 char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1871 myIteration->SetDirNameLoc(nomDirIter);
1873 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1874 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1875 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1876 // situation la plus frequente.
1877 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1878 // le nombre d'iterations du cas permet d'eviter les collisions.
1880 if ( nbitercase < 100 ) { jaux = 2 ; }
1881 else if ( nbitercase < 1000 ) { jaux = 3 ; }
1882 else if ( nbitercase < 10000 ) { jaux = 4 ; }
1883 else if ( nbitercase < 100000 ) { jaux = 5 ; }
1885 std::ostringstream iaux ;
1886 iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1887 std::stringstream MeshFile;
1888 MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1889 myIteration->SetMeshFile(MeshFile.str().c_str());
1891 // Association avec le cas
1892 std::string label = "IterationHomard_" + std::string(nomIterParent);
1893 AssociateCaseIter(nomCas, NomIteration, label.c_str());
1894 // Lien avec l'iteration precedente
1895 myIterationParent->LinkNextIteration(NomIteration);
1896 myIteration->SetIterParentName(nomIterParent);
1897 // Gestion de l'arbre d'etudes
1898 SALOMEDS::SObject_var aIterSOParent = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIterationParent)));
1899 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
1900 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1901 aStudyBuilder->NewCommand();
1902 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
1903 aStudyBuilder->Addreference(aSubSO, aIterSOParent);
1904 aStudyBuilder->CommitCommand();
1906 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1908 //=============================================================================
1909 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1911 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1914 // Controle du nom :
1915 if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
1917 MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1918 SALOME::ExceptionStruct es;
1919 es.type = SALOME::BAD_PARAM;
1920 es.text = "This boundary has already been defined";
1921 throw SALOME::SALOME_Exception(es);
1925 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1926 myBoundary->SetName(BoundaryName);
1927 myBoundary->SetType(BoundaryType);
1929 myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
1931 SALOMEDS::SObject_var aSO;
1932 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
1934 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1936 //=============================================================================
1937 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1939 INFOS ("CreateBoundaryDi : BoundaryName = " << BoundaryName << ", MeshName = " << MeshName );
1940 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1941 myBoundary->SetMeshFile( MeshFile ) ;
1942 myBoundary->SetMeshName( MeshName ) ;
1944 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1946 //=============================================================================
1947 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1948 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1949 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1950 CORBA::Double Rayon)
1952 INFOS ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
1954 SALOME::ExceptionStruct es;
1957 { es.text = "The radius must be positive." ;
1959 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1960 if ( daux < 0.0000001 )
1961 { es.text = "The axis must be a non 0 vector." ;
1965 es.type = SALOME::BAD_PARAM;
1966 throw SALOME::SALOME_Exception(es);
1970 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1971 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1973 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1975 //=============================================================================
1976 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1977 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1978 CORBA::Double Rayon)
1980 INFOS ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
1982 SALOME::ExceptionStruct es;
1985 { es.text = "The radius must be positive." ;
1989 es.type = SALOME::BAD_PARAM;
1990 throw SALOME::SALOME_Exception(es);
1994 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1995 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1997 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1999 //=============================================================================
2000 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
2001 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
2002 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
2004 INFOS ("CreateBoundaryConeA : BoundaryName = " << BoundaryName ) ;
2006 SALOME::ExceptionStruct es;
2008 if ( Angle <= 0.0 || Angle >= 90.0 )
2009 { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
2011 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2012 if ( daux < 0.0000001 )
2013 { es.text = "The axis must be a non 0 vector." ;
2017 es.type = SALOME::BAD_PARAM;
2018 throw SALOME::SALOME_Exception(es);
2022 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
2023 myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
2025 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2027 //=============================================================================
2028 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
2029 CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
2030 CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
2032 INFOS ("CreateBoundaryConeR : BoundaryName = " << BoundaryName ) ;
2034 SALOME::ExceptionStruct es;
2036 if ( Rayon1 < 0.0 || Rayon2 < 0.0 )
2037 { es.text = "The radius must be positive." ;
2039 double daux = fabs(Rayon2-Rayon1) ;
2040 if ( daux < 0.0000001 )
2041 { es.text = "The radius must be different." ;
2043 daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
2044 if ( daux < 0.0000001 )
2045 { es.text = "The centers must be different." ;
2049 es.type = SALOME::BAD_PARAM;
2050 throw SALOME::SALOME_Exception(es);
2054 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
2055 myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
2057 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2059 //=============================================================================
2060 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryTorus(const char* BoundaryName,
2061 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2062 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2063 CORBA::Double RayonRev, CORBA::Double RayonPri)
2065 INFOS ("CreateBoundaryTorus : BoundaryName = " << BoundaryName ) ;
2067 SALOME::ExceptionStruct es;
2069 if ( ( RayonRev <= 0.0 ) || ( RayonPri <= 0.0 ) )
2070 { es.text = "The radius must be positive." ;
2072 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2073 if ( daux < 0.0000001 )
2074 { es.text = "The axis must be a non 0 vector." ;
2078 es.type = SALOME::BAD_PARAM;
2079 throw SALOME::SALOME_Exception(es);
2083 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 5) ;
2084 myBoundary->SetTorus( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, RayonRev, RayonPri ) ;
2086 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2088 //=============================================================================
2089 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
2091 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
2094 // Controle du nom :
2095 if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
2097 SALOME::ExceptionStruct es;
2098 es.type = SALOME::BAD_PARAM;
2099 es.text = "This zone has already been defined";
2100 throw SALOME::SALOME_Exception(es);
2104 HOMARD::HOMARD_Zone_var myZone = newZone();
2105 myZone->SetName(ZoneName);
2106 myZone->SetType(ZoneType);
2108 myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
2110 SALOMEDS::SObject_var aSO;
2111 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
2113 return HOMARD::HOMARD_Zone::_duplicate(myZone);
2115 //=============================================================================
2116 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
2117 CORBA::Double Xmini, CORBA::Double Xmaxi,
2118 CORBA::Double Ymini, CORBA::Double Ymaxi,
2119 CORBA::Double Zmini, CORBA::Double Zmaxi)
2121 INFOS ("CreateZoneBox : ZoneName = " << ZoneName ) ;
2123 SALOME::ExceptionStruct es;
2125 if ( Xmini > Xmaxi )
2126 { es.text = "The X coordinates are not coherent." ;
2128 if ( Ymini > Ymaxi )
2129 { es.text = "The Y coordinates are not coherent." ;
2131 if ( Zmini > Zmaxi )
2132 { es.text = "The Z coordinates are not coherent." ;
2136 es.type = SALOME::BAD_PARAM;
2137 throw SALOME::SALOME_Exception(es);
2141 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
2142 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2144 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2146 //=============================================================================
2147 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
2148 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
2150 INFOS ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
2152 SALOME::ExceptionStruct es;
2155 { es.text = "The radius must be positive." ;
2159 es.type = SALOME::BAD_PARAM;
2160 throw SALOME::SALOME_Exception(es);
2164 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
2165 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2167 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2169 //=============================================================================
2170 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
2171 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2172 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2173 CORBA::Double Rayon, CORBA::Double Haut)
2175 INFOS ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
2177 SALOME::ExceptionStruct es;
2180 { es.text = "The radius must be positive." ;
2182 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2183 if ( daux < 0.0000001 )
2184 { es.text = "The axis must be a non 0 vector." ;
2187 { es.text = "The height must be positive." ;
2191 es.type = SALOME::BAD_PARAM;
2192 throw SALOME::SALOME_Exception(es);
2196 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
2197 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
2199 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2201 //=============================================================================
2202 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
2203 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2204 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2205 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
2207 INFOS ("CreateZonePipe : ZoneName = " << ZoneName ) ;
2209 SALOME::ExceptionStruct es;
2211 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2212 { es.text = "The radius must be positive." ;
2214 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2215 if ( daux < 0.0000001 )
2216 { es.text = "The axis must be a non 0 vector." ;
2219 { es.text = "The height must be positive." ;
2221 if ( Rayon <= Rayonint )
2222 { es.text = "The external radius must be higher than the internal radius." ;
2226 es.type = SALOME::BAD_PARAM;
2227 throw SALOME::SALOME_Exception(es);
2231 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
2232 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
2234 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2236 //=============================================================================
2237 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
2238 CORBA::Double Umini, CORBA::Double Umaxi,
2239 CORBA::Double Vmini, CORBA::Double Vmaxi,
2242 INFOS ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
2243 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
2244 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
2245 // MESSAGE ("Orient = " << Orient ) ;
2247 SALOME::ExceptionStruct es;
2249 if ( Umini > Umaxi )
2250 { es.text = "The first coordinates are not coherent." ;
2252 if ( Vmini > Vmaxi )
2253 { es.text = "The second coordinates are not coherent." ;
2255 if ( Orient < 1 || Orient > 3 )
2256 { es.text = "The orientation must be 1, 2 or 3." ;
2260 es.type = SALOME::BAD_PARAM;
2261 throw SALOME::SALOME_Exception(es);
2265 double Xmini, Xmaxi ;
2266 double Ymini, Ymaxi ;
2267 double Zmini, Zmaxi ;
2275 else if ( Orient == 2 )
2282 else if ( Orient == 3 )
2289 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2291 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2292 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2294 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2296 //=============================================================================
2297 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2298 CORBA::Double Ucentre, CORBA::Double Vcentre,
2299 CORBA::Double Rayon,
2302 INFOS ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
2304 SALOME::ExceptionStruct es;
2307 { es.text = "The radius must be positive." ;
2309 if ( Orient < 1 || Orient > 3 )
2310 { es.text = "The orientation must be 1, 2 or 3." ;
2314 es.type = SALOME::BAD_PARAM;
2315 throw SALOME::SALOME_Exception(es);
2323 { Xcentre = Ucentre ;
2326 else if ( Orient == 2 )
2329 Zcentre = Vcentre ; }
2330 else if ( Orient == 3 )
2331 { Xcentre = Vcentre ;
2333 Zcentre = Ucentre ; }
2334 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2336 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2337 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2339 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2341 //=============================================================================
2342 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2343 CORBA::Double Ucentre, CORBA::Double Vcentre,
2344 CORBA::Double Rayon, CORBA::Double Rayonint,
2347 INFOS ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
2349 SALOME::ExceptionStruct es;
2351 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2352 { es.text = "The radius must be positive." ;
2354 if ( Orient < 1 || Orient > 3 )
2355 { es.text = "The orientation must be 1, 2 or 3." ;
2357 if ( Rayon <= Rayonint )
2358 { es.text = "The external radius must be higher than the internal radius." ;
2362 es.type = SALOME::BAD_PARAM;
2363 throw SALOME::SALOME_Exception(es);
2371 { Xcentre = Ucentre ;
2374 else if ( Orient == 2 )
2377 Zcentre = Vcentre ; }
2378 else if ( Orient == 3 )
2379 { Xcentre = Vcentre ;
2381 Zcentre = Ucentre ; }
2382 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2384 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2385 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2387 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2389 //=============================================================================
2390 //=============================================================================
2395 //=============================================================================
2396 //=============================================================================
2397 // Traitement d'une iteration
2398 // etatMenage = 1 : destruction du repertoire d'execution
2399 // modeHOMARD = 1 : adaptation
2400 // != 1 : information avec les options modeHOMARD
2401 // Option1 >0 : appel depuis python
2402 // <0 : appel depuis GUI
2403 // Option2 : multiple de nombres premiers
2404 // 1 : aucune option
2405 // x2 : publication du maillage dans SMESH
2406 //=============================================================================
2407 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2409 INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2414 // A.1. L'objet iteration
2415 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
2416 ASSERT(!CORBA::is_nil(myIteration));
2418 // A.2. Controle de la possibilite d'agir
2419 // A.2.1. Etat de l'iteration
2420 int etat = myIteration->GetState();
2421 MESSAGE ( "etat = "<<etat );
2422 // A.2.2. On ne calcule pas l'iteration initiale, ni une iteration deja calculee
2423 if ( modeHOMARD == 1 )
2427 SALOME::ExceptionStruct es;
2428 es.type = SALOME::BAD_PARAM;
2429 es.text = "This iteration is the first of the case and cannot be computed.";
2430 throw SALOME::SALOME_Exception(es);
2433 else if ( ( etat == 2 ) & ( modeHOMARD == 1 ) )
2435 SALOME::ExceptionStruct es;
2436 es.type = SALOME::BAD_PARAM;
2437 es.text = "This iteration is already computed.";
2438 throw SALOME::SALOME_Exception(es);
2442 // A.2.3. On n'analyse pas une iteration non calculee
2447 SALOME::ExceptionStruct es;
2448 es.type = SALOME::BAD_PARAM;
2449 es.text = "This iteration is not computed.";
2450 throw SALOME::SALOME_Exception(es);
2455 // A.3. Numero de l'iteration
2456 // siterp1 : numero de l'iteration a traiter
2458 // siter : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2459 // Ou si information :
2461 int NumeIter = myIteration->GetNumber();
2462 std::string siterp1 ;
2463 std::stringstream saux1 ;
2465 siterp1 = saux1.str() ;
2466 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2469 if ( modeHOMARD==1 )
2471 std::stringstream saux0 ;
2472 int iaux = max(0, NumeIter-1) ;
2474 siter = saux0.str() ;
2475 if (NumeIter < 11) { siter = "0" + siter ; }
2478 { siter = siterp1 ; }
2481 const char* nomCas = myIteration->GetCaseName();
2482 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
2483 ASSERT(!CORBA::is_nil(myCase));
2485 // B. Les repertoires
2486 // B.1. Le repertoire courant
2487 std::string nomDirWork = getenv("PWD") ;
2488 // B.2. Le sous-repertoire de l'iteration a traiter
2489 char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2490 MESSAGE( ". DirCompute = " << DirCompute );
2492 // C. Le fichier des messages
2493 // C.1. Le deroulement de l'execution de HOMARD
2494 std::string LogFile = DirCompute ;
2495 LogFile += "/Liste" ;
2496 if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2498 MESSAGE (". LogFile = " << LogFile);
2499 if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2500 // C.2. Le bilan de l'analyse du maillage
2501 std::string FileInfo = DirCompute ;
2503 if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2505 { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2506 else { FileInfo += "info_ap" ; }
2508 FileInfo += "." + siterp1 + ".bilan" ;
2509 myIteration->SetFileInfo(FileInfo.c_str());
2511 // D. On passe dans le repertoire de l'iteration a calculer
2512 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2515 // E. Les donnees de l'execution HOMARD
2516 // E.1. L'objet du texte du fichier de configuration
2517 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2518 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2520 // E.2. Le maillage associe a l'iteration
2521 const char* NomMesh = myIteration->GetMeshName();
2522 MESSAGE ( ". NomMesh = " << NomMesh );
2523 const char* MeshFile = myIteration->GetMeshFile();
2524 MESSAGE ( ". MeshFile = " << MeshFile );
2526 // E.3. Les donnees du traitement HOMARD
2528 if ( modeHOMARD == 1 )
2531 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2532 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2533 codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2537 InvalideIterInfo(NomIteration);
2538 myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2540 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2541 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2542 myDriver->CreeFichierDonn();
2545 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2546 DriverTexteBoundary(myCase, myDriver) ;
2548 // E.5. Ecriture du texte dans le fichier
2549 MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2551 { myDriver->CreeFichier(); }
2555 int codretexec = 12 ;
2558 codretexec = myDriver->ExecuteHomard(Option1);
2560 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2561 // En mode adaptation, on ajuste l'etat de l'iteration
2562 if ( modeHOMARD == 1 )
2564 if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2565 else { SetEtatIter(NomIteration,1); }
2566 // GERALD -- QMESSAGE BOX
2570 // H. Gestion des resultats
2573 std::string Commentaire ;
2574 // H.1. Le fichier des messages, dans tous les cas
2575 Commentaire = "log" ;
2576 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2577 else { Commentaire += "Info" ; }
2578 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2580 // H.2. Si tout s'est bien passe :
2581 if (codretexec == 0)
2583 // H.2.1. Le fichier de bilan
2584 Commentaire = "Summary" ;
2585 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2586 else { Commentaire += "Info" ; }
2587 PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2588 // H.2.2. Le fichier de maillage obtenu
2589 if ( modeHOMARD == 1 )
2591 std::stringstream saux0 ;
2592 Commentaire = "Mesh" ;
2593 Commentaire += " " + siterp1 ;
2594 PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2595 if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2598 // H.3 Message d'erreur
2599 if (codretexec != 0)
2601 std::string text = "" ;
2602 // Message d'erreur en cas de probleme en adaptation
2603 if ( modeHOMARD == 1 )
2605 text = "Error during the adaptation.\n" ;
2606 bool stopvu = false ;
2607 std::ifstream fichier( LogFile.c_str() );
2608 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
2610 std::string ligne; // variable contenant chaque ligne lue
2611 while ( std::getline( fichier, ligne ) )
2615 { text += ligne+ "\n"; }
2618 int position = ligne.find( "===== HOMARD ===== STOP =====" ) ;
2619 if ( position > 0 ) { stopvu = true ; }
2624 text += "\n\nSee the file " + LogFile + "\n" ;
2626 SALOME::ExceptionStruct es;
2627 es.type = SALOME::BAD_PARAM;
2628 es.text = CORBA::string_dup(text.c_str());
2629 throw SALOME::SALOME_Exception(es);
2631 // En mode information, on force le succes pour pouvoir consulter le fichier log
2632 if ( modeHOMARD != 1 ) { codretexec = 0 ; }
2636 // I. Menage et retour dans le repertoire du cas
2640 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2642 CHDIR(nomDirWork.c_str());
2647 //=============================================================================
2648 // Calcul d'une iteration : partie specifique a l'adaptation
2649 //=============================================================================
2650 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)
2652 MESSAGE ( "ComputeAdap" );
2657 // Numero de l'iteration
2658 int NumeIter = myIteration->GetNumber();
2659 std::stringstream saux0 ;
2660 saux0 << NumeIter-1 ;
2661 std::string siter = saux0.str() ;
2662 if (NumeIter < 11) { siter = "0" + siter ; }
2664 // A.2. On verifie qu il y a une hypothese (erreur improbable);
2665 const char* nomHypo = myIteration->GetHypoName();
2666 if (std::string(nomHypo) == std::string(""))
2668 SALOME::ExceptionStruct es;
2669 es.type = SALOME::BAD_PARAM;
2670 es.text = "This iteration does not have any associated hypothesis.";
2671 throw SALOME::SALOME_Exception(es);
2674 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
2675 ASSERT(!CORBA::is_nil(myHypo));
2677 // B. L'iteration parent
2678 const char* nomIterationParent = myIteration->GetIterParentName();
2679 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2680 ASSERT(!CORBA::is_nil(myIterationParent));
2681 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2682 if ( myIterationParent->GetState() == 1 )
2685 int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2688 // GERALD -- QMESSAGE BOX
2689 VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2693 // C. Le sous-repertoire de l'iteration precedente
2694 char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2695 MESSAGE( ". DirComputePa = " << DirComputePa );
2697 // D. Les donnees de l'adaptation HOMARD
2698 // D.1. Le type de conformite
2699 int ConfType = myCase->GetConfType();
2700 MESSAGE ( ". ConfType = " << ConfType );
2702 // D.1. Le type externe
2703 int ExtType = myCase->GetExtType();
2704 MESSAGE ( ". ExtType = " << ExtType );
2706 // D.3. Le maillage de depart
2707 const char* NomMeshParent = myIterationParent->GetMeshName();
2708 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2709 const char* MeshFileParent = myIterationParent->GetMeshFile();
2710 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2712 // D.4. Le maillage associe a l'iteration
2713 const char* MeshFile = myIteration->GetMeshFile();
2714 MESSAGE ( ". MeshFile = " << MeshFile );
2715 FILE *file = fopen(MeshFile,"r");
2719 if (etatMenage == 0)
2721 SALOME::ExceptionStruct es;
2722 es.type = SALOME::BAD_PARAM;
2723 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2724 es.text = CORBA::string_dup(text.c_str());
2725 throw SALOME::SALOME_Exception(es);
2730 std::string commande = "rm -f " + std::string(MeshFile);
2731 codret = system(commande.c_str());
2734 SALOME::ExceptionStruct es;
2735 es.type = SALOME::BAD_PARAM;
2736 es.text = "The mesh file cannot be deleted.";
2737 throw SALOME::SALOME_Exception(es);
2743 // D.5. Les types de raffinement et de deraffinement
2744 // Les appels corba sont lourds, il vaut mieux les grouper
2745 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2746 ASSERT(ListTypes->length() == 3);
2747 int TypeAdap = (*ListTypes)[0];
2748 int TypeRaff = (*ListTypes)[1];
2749 int TypeDera = (*ListTypes)[2];
2750 // MESSAGE ( ". TypeAdap = " << TypeAdap << ", TypeRaff = " << TypeRaff << ", TypeDera = " << TypeDera );
2752 // E. Texte du fichier de configuration
2753 // E.1. Incontournables du texte
2754 myDriver->TexteAdap(ExtType);
2756 myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2757 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2758 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2760 // E.2. Ajout des informations liees aux zones eventuelles
2761 if ( TypeAdap == 0 )
2762 { DriverTexteZone(myHypo, myDriver) ; }
2764 // E.3. Ajout des informations liees aux champs eventuels
2765 if ( TypeAdap == 1 )
2766 { DriverTexteField(myIteration, myHypo, myDriver) ; }
2768 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2769 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2770 int numberOfGroups = listeGroupes->length();
2771 MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2772 if (numberOfGroups > 0)
2774 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2776 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2777 MESSAGE( "... GroupName = " << GroupName );
2778 myDriver->TexteGroup(GroupName);
2782 // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2783 DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2785 // E.6. Ajout des options avancees
2786 int Pyram = myCase->GetPyram();
2787 MESSAGE ( ". Pyram = " << Pyram );
2788 int NivMax = myHypo->GetNivMax();
2789 MESSAGE ( ". NivMax = " << NivMax );
2790 double DiamMin = myHypo->GetDiamMin() ;
2791 MESSAGE ( ". DiamMin = " << DiamMin );
2792 int AdapInit = myHypo->GetAdapInit();
2793 MESSAGE ( ". AdapInit = " << AdapInit );
2794 int ExtraOutput = myHypo->GetExtraOutput();
2795 MESSAGE ( ". ExtraOutput = " << ExtraOutput );
2796 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, ExtraOutput);
2798 // E.7. Ajout des informations sur le deroulement de l'execution
2799 int MessInfo = myIteration->GetInfoCompute();
2800 MESSAGE ( ". MessInfo = " << MessInfo );
2801 myDriver->TexteInfoCompute(MessInfo);
2805 //=============================================================================
2806 // Creation d'un nom de sous-repertoire pour l'iteration au sein d'un repertoire parent
2807 // nomrep : nom du repertoire parent
2808 // num : le nom du sous-repertoire est sous la forme 'In', n est >= num
2809 //=============================================================================
2810 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
2812 MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2813 // On verifie que le repertoire parent existe
2814 int codret = CHDIR(nomrep) ;
2817 SALOME::ExceptionStruct es;
2818 es.type = SALOME::BAD_PARAM;
2819 es.text = "The directory of the case does not exist.";
2820 throw SALOME::SALOME_Exception(es);
2823 std::string nomDirActuel = getenv("PWD") ;
2824 std::string DirName ;
2825 // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un repertoire inconnu
2826 bool a_chercher = true ;
2827 while ( a_chercher )
2829 // On passe dans le repertoire parent
2832 // On recherche un nom sous la forme Iabc, avec abc representant le numero
2834 if ( num < 100 ) { jaux = 2 ; }
2835 else if ( num < 1000 ) { jaux = 3 ; }
2836 else if ( num < 10000 ) { jaux = 4 ; }
2837 else if ( num < 100000 ) { jaux = 5 ; }
2839 std::ostringstream iaux ;
2840 iaux << std::setw(jaux) << std::setfill('0') << num ;
2841 std::ostringstream DirNameA ;
2842 DirNameA << "I" << iaux.str();
2843 // Si on ne pas peut entrer dans le repertoire, on doit verifier
2844 // que c'est bien un probleme d'absence
2845 if ( CHDIR(DirNameA.str().c_str()) != 0 )
2847 bool existe = false ;
2850 struct dirent *dirp;
2851 dp = opendir(nomrep);
2852 while ( (dirp = readdir(dp)) != NULL )
2854 std::string file_name(dirp->d_name);
2856 HANDLE hFind = INVALID_HANDLE_VALUE;
2857 WIN32_FIND_DATA ffd;
2858 hFind = FindFirstFile(nomrep, &ffd);
2859 if (INVALID_HANDLE_VALUE != hFind) {
2860 while (FindNextFile(hFind, &ffd) != 0) {
2861 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2862 std::string file_name(ffd.cFileName);
2864 if ( file_name == DirNameA.str() ) { existe = true ; }
2873 DirName = DirNameA.str() ;
2874 a_chercher = false ;
2881 MESSAGE ( "==> DirName = " << DirName);
2882 MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
2883 CHDIR(nomDirActuel.c_str());
2884 return CORBA::string_dup( DirName.c_str() );
2886 //=============================================================================
2887 // Calcul d'une iteration : gestion du repertoire de calcul
2888 // Si le sous-repertoire existe :
2889 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
2890 // etatMenage = 1 : on fait le menage du repertoire
2891 // etatMenage = -1 : on ne fait rien
2892 //=============================================================================
2893 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
2895 MESSAGE ( "ComputeDirManagement : repertoires pour le calcul" );
2896 // B.2. Le repertoire du cas
2897 const char* nomDirCase = myCase->GetDirName();
2898 MESSAGE ( ". nomDirCase = " << nomDirCase );
2900 // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
2901 // B.3.1. Le nom du sous-repertoire
2902 const char* nomDirIt = myIteration->GetDirNameLoc();
2904 // B.3.2. Le nom complet du sous-repertoire
2905 std::stringstream DirCompute ;
2906 DirCompute << nomDirCase << "/" << nomDirIt;
2907 MESSAGE (". DirCompute = " << DirCompute.str() );
2909 // B.3.3. Si le sous-repertoire n'existe pas, on le cree
2910 if (CHDIR(DirCompute.str().c_str()) != 0)
2913 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2915 if (_mkdir(DirCompute.str().c_str()) != 0)
2918 // GERALD -- QMESSAGE BOX
2919 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
2920 VERIFICATION("Pb a la creation du repertoire" == 0);
2925 // Le repertoire existe
2926 // On demande de faire le menage de son contenu :
2927 if (etatMenage == 1)
2929 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
2930 std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
2931 int codret = system(commande.c_str());
2934 // GERALD -- QMESSAGE BOX
2935 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
2936 VERIFICATION("Pb au menage du repertoire de calcul" == 0);
2939 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2942 if (etatMenage == 0)
2946 struct dirent *dirp;
2947 dp = opendir(DirCompute.str().c_str());
2949 while ((dirp = readdir(dp)) != NULL && result )
2951 std::string file_name(dirp->d_name);
2952 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2956 HANDLE hFind = INVALID_HANDLE_VALUE;
2957 WIN32_FIND_DATA ffd;
2958 hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
2960 if (INVALID_HANDLE_VALUE != hFind) {
2961 while (FindNextFile(hFind, &ffd) != 0) {
2962 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2963 std::string file_name(ffd.cFileName);
2964 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2969 if ( result == false)
2971 SALOME::ExceptionStruct es;
2972 es.type = SALOME::BAD_PARAM;
2973 std::string text = "Directory : " + DirCompute.str() + " is not empty";
2974 es.text = CORBA::string_dup(text.c_str());
2975 throw SALOME::SALOME_Exception(es);
2976 VERIFICATION("Directory is not empty" == 0);
2982 return CORBA::string_dup( DirCompute.str().c_str() );
2984 //=============================================================================
2985 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
2986 //=============================================================================
2987 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
2989 MESSAGE ( "ComputeDirPaManagement : repertoires pour le calcul" );
2990 // Le repertoire du cas
2991 const char* nomDirCase = myCase->GetDirName();
2992 MESSAGE ( ". nomDirCase = " << nomDirCase );
2994 // Le sous-repertoire de l'iteration precedente
2996 const char* nomIterationParent = myIteration->GetIterParentName();
2997 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2998 const char* nomDirItPa = myIterationParent->GetDirNameLoc();
2999 std::stringstream DirComputePa ;
3000 DirComputePa << nomDirCase << "/" << nomDirItPa;
3001 MESSAGE( ". nomDirItPa = " << nomDirItPa);
3002 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
3004 return CORBA::string_dup( DirComputePa.str().c_str() );
3006 //=============================================================================
3007 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
3008 //=============================================================================
3009 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3011 MESSAGE ( "... DriverTexteZone" );
3012 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3013 int numberOfZonesx2 = ListZone->length();
3016 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3018 std::string ZoneName = std::string((*ListZone)[iaux]);
3019 MESSAGE ( "... ZoneName = " << ZoneName);
3020 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
3021 ASSERT(!CORBA::is_nil(myZone));
3023 int ZoneType = myZone->GetType();
3024 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
3025 int TypeUse = atoi( TypeUsestr.c_str() );
3026 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
3027 NumZone = iaux/2 + 1 ;
3028 HOMARD::double_array* zone = myZone->GetCoords();
3029 if ( ZoneType == 2 || ( ZoneType>=11 && ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
3030 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
3031 else if ( ZoneType == 4 ) // Cas d une sphere
3032 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
3033 else if ( ZoneType == 5 || ( ZoneType>=31 && ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
3034 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
3035 else if ( ZoneType == 7 || ( ZoneType>=61 && ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
3036 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
3037 else { VERIFICATION("ZoneType est incorrect." == 0) ; }
3042 //=============================================================================
3043 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
3044 //=============================================================================
3045 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3047 MESSAGE ( "... DriverTexteField" );
3048 // Le fichier du champ
3049 char* FieldFile = myIteration->GetFieldFile();
3050 MESSAGE ( ". FieldFile = " << FieldFile );
3051 if (strlen(FieldFile) == 0)
3053 // GERALD -- QMESSAGE BOX
3054 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
3055 VERIFICATION("The file for the field is not given." == 0);
3057 // Les caracteristiques d'instants du champ de pilotage
3058 int TimeStep = myIteration->GetTimeStep();
3059 MESSAGE( ". TimeStep = " << TimeStep );
3060 int Rank = myIteration->GetRank();
3061 MESSAGE( ". Rank = " << Rank );
3062 // Les informations sur les champs
3063 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
3065 const char* FieldName = aInfosHypo->FieldName;
3067 int TypeThR = aInfosHypo->TypeThR;
3068 double ThreshR = aInfosHypo->ThreshR;
3069 int TypeThC = aInfosHypo->TypeThC;
3070 double ThreshC = aInfosHypo->ThreshC;
3071 // Saut entre mailles ou non ?
3072 int UsField = aInfosHypo->UsField;
3073 MESSAGE( ". UsField = " << UsField );
3074 // L'usage des composantes
3075 int UsCmpI = aInfosHypo->UsCmpI;
3076 MESSAGE( ". UsCmpI = " << UsCmpI );
3078 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
3081 HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
3082 int numberOfCompos = mescompo->length();
3083 MESSAGE( ". numberOfCompos = " << numberOfCompos );
3084 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
3086 std::string nomCompo = std::string((*mescompo)[NumeComp]);
3087 if ((system(nomCompo.c_str())) != 0)
3089 MESSAGE( "... nomCompo = " << nomCompo );
3090 myDriver->TexteCompo(NumeComp, nomCompo);
3095 //=============================================================================
3096 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
3097 // On ecrit dans l'ordre :
3098 // 1. la definition des frontieres
3099 // 2. les liens avec les groupes
3100 // 3. un entier resumant le type de comportement pour les frontieres
3101 //=============================================================================
3102 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
3104 MESSAGE ( "... DriverTexteBoundary" );
3105 // 1. Recuperation des frontieres
3106 std::list<std::string> ListeBoundaryTraitees ;
3107 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3108 int numberOfitems = ListBoundaryGroupType->length();
3109 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
3110 int BoundaryOption = 1 ;
3111 // 2. Parcours des frontieres pour ecrire leur description
3112 int NumBoundaryAnalytical = 0 ;
3113 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3115 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3116 MESSAGE ( "... BoundaryName = " << BoundaryName);
3117 // 2.1. La frontiere a-t-elle deja ete ecrite ?
3118 // Cela arrive quand elle est liee a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
3120 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3121 while (it != ListeBoundaryTraitees.end())
3123 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3124 if ( BoundaryName == *it ) { A_faire = 0 ; }
3127 // 2.2. Ecriture de la frontiere
3130 // 2.2.1. Caracteristiques de la frontiere
3131 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3132 ASSERT(!CORBA::is_nil(myBoundary));
3133 int BoundaryType = myBoundary->GetType();
3134 MESSAGE ( "... BoundaryType = " << BoundaryType );
3135 // 2.2.2. Ecriture selon le type
3136 // 2.2.2.1. Cas d une frontiere discrete
3137 if (BoundaryType == 0)
3139 const char* MeshName = myBoundary->GetMeshName() ;
3140 MESSAGE ( ". MeshName = " << MeshName );
3141 const char* MeshFile = myBoundary->GetMeshFile() ;
3142 MESSAGE ( ". MeshFile = " << MeshFile );
3143 myDriver->TexteBoundaryDi( MeshName, MeshFile);
3144 if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
3146 // 2.2.2.1. Cas d une frontiere analytique
3149 NumBoundaryAnalytical++ ;
3150 HOMARD::double_array* coor = myBoundary->GetCoords();
3151 if (BoundaryType == 1) // Cas d un cylindre
3153 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3154 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3156 else if (BoundaryType == 2) // Cas d une sphere
3158 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
3159 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3161 else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
3163 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3164 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3166 else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
3168 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3169 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3171 else if (BoundaryType == 5) // Cas d un tore
3173 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3174 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3177 // 2.2.3. Memorisation du traitement
3178 ListeBoundaryTraitees.push_back( BoundaryName );
3181 // 3. Parcours des frontieres pour ecrire les liens avec les groupes
3182 NumBoundaryAnalytical = 0 ;
3183 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3185 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3186 MESSAGE ( "... BoundaryName = " << BoundaryName);
3187 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3188 ASSERT(!CORBA::is_nil(myBoundary));
3189 int BoundaryType = myBoundary->GetType();
3190 MESSAGE ( "... BoundaryType = " << BoundaryType );
3191 // 3.1. Recuperation du nom du groupe
3192 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
3193 MESSAGE ( "... GroupName = " << GroupName);
3194 // 3.2. Cas d une frontiere discrete
3195 if ( BoundaryType == 0 )
3197 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
3199 // 3.3. Cas d une frontiere analytique
3202 NumBoundaryAnalytical++ ;
3203 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
3206 // 4. Ecriture de l'option finale
3207 myDriver->TexteBoundaryOption(BoundaryOption);
3211 //=============================================================================
3212 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3213 //=============================================================================
3214 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3216 MESSAGE ( "... DriverTexteFieldInterp" );
3217 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3218 MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3219 if (TypeFieldInterp != 0)
3221 // Le fichier des champs
3222 char* FieldFile = myIteration->GetFieldFile();
3223 MESSAGE ( ". FieldFile = " << FieldFile );
3224 if (strlen(FieldFile) == 0)
3226 // GERALD -- QMESSAGE BOX
3227 VERIFICATION("The file for the field is not given." == 0);
3230 const char* MeshFile = myIteration->GetMeshFile();
3231 myDriver->TexteFieldInterp(FieldFile, MeshFile);
3234 // Interpolation de tous les champs
3235 if ( TypeFieldInterp == 1 )
3237 myDriver->TexteFieldInterpAll();
3239 // Interpolation de certains champs
3240 else if (TypeFieldInterp == 2)
3242 // Les champs et leurs instants pour l'iteration
3243 HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3244 int numberOfFieldsx3 = ListFieldTSR->length();
3245 MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3246 // Les champs pour l'hypothese
3247 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3248 int numberOfFieldsx2 = ListField->length();
3249 MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3250 // On parcourt tous les champs de l'hypothese
3252 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3255 std::string FieldName = std::string((*ListField)[iaux]) ;
3256 // Le type d'interpolation
3257 std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3258 MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3259 // On cherche à savoir si des instants ont été précisés pour cette itération
3261 for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3264 std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3265 MESSAGE( "..... FieldName2 = " << FieldName2 );
3266 // Quand c'est le bon champ, on ecrit le pas de temps
3267 if ( FieldName == FieldName2 )
3271 std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3272 // Le numero d'ordre
3273 std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3274 MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3276 int TimeStep = atoi( TimeStepstr.c_str() );
3277 int Rank = atoi( Rankstr.c_str() );
3278 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3282 // Si aucun instant n'a été défini
3286 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3294 //===========================================================================
3295 //===========================================================================
3298 //===========================================================================
3299 //===========================================================================
3301 //===========================================================================
3302 //===========================================================================
3303 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
3304 SALOMEDS::SObject_ptr theSObject,
3305 CORBA::Object_ptr theObject,
3306 const char* theName)
3308 MESSAGE("PublishInStudy pour " << theName);
3309 SALOMEDS::SObject_var aResultSO;
3310 if (CORBA::is_nil(theStudy))
3312 SALOME::ExceptionStruct es;
3313 es.type = SALOME::BAD_PARAM;
3314 es.text = "Invalid study context";
3315 throw SALOME::SALOME_Exception(es);
3319 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3320 // Rq : Iteration est publiee ailleurs
3321 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3322 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
3323 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3324 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3325 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3327 addInStudy(theStudy);
3329 // Controle de la non publication d'un objet de meme nom
3330 if ( (!aBoundary->_is_nil()) || (!aHypo->_is_nil()) || (!aYACS->_is_nil()) || (!aZone->_is_nil()) )
3332 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
3333 if (listSO->length() >= 1)
3335 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3336 aResultSO = listSO[0];
3337 return aResultSO._retn();
3341 // Caracteristiques de l'etude
3342 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
3343 aStudyBuilder->NewCommand();
3344 if(!aBoundary->_is_nil())
3345 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
3346 else if(!aCase->_is_nil())
3347 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
3348 else if(!aHypo->_is_nil())
3349 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
3350 else if(!aYACS->_is_nil())
3351 aResultSO = PublishYACSInStudy(theStudy, aStudyBuilder, aYACS, theName);
3352 else if(!aZone->_is_nil())
3353 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
3355 aStudyBuilder->CommitCommand();
3357 return aResultSO._retn();
3359 //=============================================================================
3360 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3361 SALOMEDS::StudyBuilder_var aStudyBuilder,
3362 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3364 MESSAGE("PublishBoundaryStudy pour "<<theName);
3365 SALOMEDS::SObject_var aResultSO;
3367 // Caracteristique de la Boundary
3368 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3370 // On recupere le module pere dans l etude
3371 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3372 if (theFatherHomard->_is_nil())
3374 MESSAGE("theFatherHomard->_is_nil()");
3375 return aResultSO._retn();
3378 // On ajoute la categorie des boundarys dans l etude si necessaire
3379 if ( _tag_boun == 0 )
3382 _tag_boun = _tag_gene ;
3384 MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3385 SALOMEDS::SObject_var aSObject;
3386 if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3388 MESSAGE("Ajout de la categorie des boundarys");
3389 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3390 PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3392 else { MESSAGE("La categorie des boundarys existe deja."); }
3394 CORBA::Long BoundaryType = myBoundary->GetType();
3395 // MESSAGE("BoundaryType : "<<BoundaryType);
3398 switch (BoundaryType)
3401 { value = "BoundaryDiHomard" ;
3402 icone = "mesh_tree_mesh.png" ;
3406 { value = "BoundaryAnHomard" ;
3407 icone = "cylinderpointvector_2.png" ;
3411 { value = "BoundaryAnHomard" ;
3412 icone = "spherepoint_2.png" ;
3416 { value = "BoundaryAnHomard" ;
3417 icone = "conepointvector.png" ;
3421 { value = "BoundaryAnHomard" ;
3422 icone = "conedxyz.png" ;
3426 { value = "BoundaryAnHomard" ;
3427 icone = "toruspointvector.png" ;
3431 aResultSO = aStudyBuilder->NewObject(aSObject);
3432 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3433 return aResultSO._retn();
3435 //=============================================================================
3436 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
3437 SALOMEDS::StudyBuilder_var aStudyBuilder,
3438 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3440 MESSAGE("PublishCaseInStudy pour "<<theName);
3441 SALOMEDS::SObject_var aResultSO;
3443 if (CORBA::is_nil(theObject)) {
3444 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3445 return aResultSO._retn();
3447 if (theStudy->_is_nil()) {
3448 MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
3449 return aResultSO._retn();
3452 // On recupere le module pere dans l etude
3453 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3454 if (theFatherHomard->_is_nil())
3456 MESSAGE("theFatherHomard->_is_nil()");
3457 return aResultSO._retn();
3461 MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3462 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3463 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3464 _orb->object_to_string(theObject) ) ;
3466 return aResultSO._retn();
3468 //=============================================================================
3469 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3470 SALOMEDS::StudyBuilder_var aStudyBuilder,
3471 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3473 MESSAGE("PublishHypotheseInStudy pour "<<theName);
3474 SALOMEDS::SObject_var aResultSO;
3476 // On recupere le module pere dans l etude
3477 // On ajoute la categorie des hypotheses dans l etude si necessaire
3478 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3479 if (theFatherHomard->_is_nil())
3481 MESSAGE("theFatherHomard->_is_nil()");
3482 return aResultSO._retn();
3485 // On ajoute la categorie des hypotheses dans l etude si necessaire
3486 SALOMEDS::SObject_var aSObject;
3487 if ( _tag_hypo == 0 )
3490 _tag_hypo = _tag_gene ;
3492 MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3493 if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3495 MESSAGE("Ajout de la categorie des hypotheses");
3496 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3497 PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3499 else { MESSAGE("La categorie des hypotheses existe deja."); }
3501 // Creation du resultat dans l'etude
3502 aResultSO = aStudyBuilder->NewObject(aSObject);
3503 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3505 return aResultSO._retn();
3507 //=============================================================================
3508 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::Study_ptr theStudy,
3509 SALOMEDS::StudyBuilder_var aStudyBuilder,
3510 HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3512 MESSAGE("PublishYACSInStudy pour "<<theName);
3513 SALOMEDS::SObject_var aResultSO;
3515 // On recupere le module pere dans l etude
3516 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3517 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3518 if (theFatherHomard->_is_nil())
3520 MESSAGE("theFatherHomard->_is_nil()");
3521 return aResultSO._retn();
3523 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3524 if ( _tag_yacs == 0 )
3527 _tag_yacs = _tag_gene ;
3529 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3530 SALOMEDS::SObject_var aSObject;
3531 if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3533 MESSAGE("Ajout de la categorie des schemas YACS");
3534 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3535 PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3537 else { MESSAGE("La categorie des schemas YACS existe deja."); }
3539 // Creation du resultat dans l'etude
3540 aResultSO = aStudyBuilder->NewObject(aSObject);
3541 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3543 return aResultSO._retn();
3546 //=============================================================================
3547 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
3548 SALOMEDS::StudyBuilder_var aStudyBuilder,
3549 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3551 MESSAGE("PublishZoneStudy pour "<<theName);
3552 SALOMEDS::SObject_var aResultSO;
3553 if (CORBA::is_nil(theObject))
3555 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3556 return aResultSO._retn();
3558 if (theStudy->_is_nil())
3560 MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3561 return aResultSO._retn();
3563 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3564 if (theFatherHomard->_is_nil())
3566 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3567 return aResultSO._retn();
3570 // Caracteristique de la zone
3571 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3572 CORBA::Long ZoneType = myZone->GetType();
3574 // On ajoute la categorie des zones dans l etude si necessaire
3575 if ( _tag_zone == 0 )
3578 _tag_zone = _tag_gene ;
3580 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3581 SALOMEDS::SObject_var aSObject;
3582 if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3584 MESSAGE("Ajout de la categorie des zones");
3585 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3586 PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3588 else { MESSAGE("La categorie des zones existe deja."); }
3590 aResultSO = aStudyBuilder->NewObject(aSObject);
3599 { icone = "boxdxy_2.png" ;
3603 { icone = "boxdxyz_2.png" ;
3611 { icone = "disk_2.png" ;
3615 { icone = "spherepoint_2.png" ;
3619 { icone = "cylinderpointvector_2.png" ;
3627 { icone = "diskwithhole_2.png" ;
3631 { icone = "pipe_2.png" ;
3635 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3637 return aResultSO._retn();
3639 //===========================================================================
3640 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3641 SALOMEDS::SObject_var aResultSO,
3642 const char* name, const char* comment, const char* icone, const char* ior)
3644 MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3645 // MESSAGE("icone = "<<icone);
3646 // MESSAGE("ior = "<<ior);
3647 SALOMEDS::GenericAttribute_var anAttr ;
3651 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3652 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3653 aNameAttrib->SetValue(name);
3656 // Ajout du commentaire
3657 if ( comment != NULL )
3659 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3660 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3661 aCommentAttrib->SetValue(comment);
3665 if ( icone != NULL )
3667 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3668 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3669 aPixmap->SetPixMap(icone);
3675 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3676 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3677 anIOR->SetValue(ior);
3681 //=====================================================================================
3682 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3684 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3686 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3687 ASSERT(!CORBA::is_nil(myCase));
3688 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3689 ASSERT(!CORBA::is_nil(aCaseSO));
3691 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3692 ASSERT(!CORBA::is_nil(myBoundary));
3693 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3694 ASSERT(!CORBA::is_nil(aBoundarySO));
3696 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3698 aStudyBuilder->NewCommand();
3700 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3701 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3702 // aStudyBuilder->RemoveReference(aSubSO);
3704 aStudyBuilder->CommitCommand();
3707 //=====================================================================================
3708 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3710 MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3712 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3713 ASSERT(!CORBA::is_nil(myYACS));
3714 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3715 ASSERT(!CORBA::is_nil(aYACSSO));
3717 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3718 ASSERT(!CORBA::is_nil(myCase));
3719 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3720 ASSERT(!CORBA::is_nil(aCaseSO));
3722 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3724 aStudyBuilder->NewCommand();
3726 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3727 aStudyBuilder->Addreference(aSubSO, aCaseSO);
3729 aStudyBuilder->CommitCommand();
3732 //=============================================================================
3733 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3734 // Option = 0 : fichier issu d'une importation
3735 // Option = 1 : fichier issu d'une execution HOMARD
3737 MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3738 if (CORBA::is_nil(myCurrentStudy))
3740 SALOME::ExceptionStruct es;
3741 es.type = SALOME::BAD_PARAM;
3742 es.text = "Invalid study context";
3743 throw SALOME::SALOME_Exception(es);
3747 // Le module SMESH est-il actif ?
3748 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3750 if (!CORBA::is_nil(aSmeshSO))
3752 // On verifie que le fichier n est pas deja publie
3753 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3754 for (; aIter->More(); aIter->Next())
3756 SALOMEDS::SObject_var aSO = aIter->Value();
3757 SALOMEDS::GenericAttribute_var aGAttr;
3758 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3760 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3761 CORBA::String_var value=anAttr->Value();
3762 if (strcmp((const char*)value,NomFich) == 0)
3764 MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3765 // Pour un fichier importe, on ne republie pas
3766 if ( Option == 0 ) { return; }
3767 // Pour un fichier calcule, on commence par faire la depublication
3770 MESSAGE ( "PublishResultInSmesh : depublication" );
3771 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3772 CORBA::String_var value2=anAttr2->Value();
3773 std::string MeshName = string(value2) ;
3774 MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3775 DeleteResultInSmesh(NomFich, MeshName) ;
3782 // On enregistre le fichier
3783 MESSAGE( "Enregistrement du fichier");
3784 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
3785 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
3786 ASSERT(!CORBA::is_nil(aSmeshEngine));
3787 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
3788 SMESH::DriverMED_ReadStatus theStatus;
3789 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3791 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
3792 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3793 for (int i = 0; i < mesMaillages->length(); i++)
3795 MESSAGE( ". Mise a jour des attributs du maillage");
3796 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
3797 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
3798 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3799 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
3800 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3801 anAttr->SetValue(NomFich);
3802 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
3803 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
3805 if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
3806 else { icone = "mesh_tree_mesh.png" ; }
3807 anAttr2->SetPixMap( icone );
3811 //=============================================================================
3812 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
3814 MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
3815 if (CORBA::is_nil(myCurrentStudy))
3817 SALOME::ExceptionStruct es;
3818 es.type = SALOME::BAD_PARAM;
3819 es.text = "Invalid study context";
3820 throw SALOME::SALOME_Exception(es);
3824 // Le module SMESH est-il actif ?
3825 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3827 if (CORBA::is_nil(aSmeshSO))
3831 // On verifie que le fichier est deja publie
3832 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
3833 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3834 for (; aIter->More(); aIter->Next())
3836 SALOMEDS::SObject_var aSO = aIter->Value();
3837 SALOMEDS::GenericAttribute_var aGAttr;
3838 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3840 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3841 CORBA::String_var value=anAttr->Value();
3842 if (strcmp((const char*)value,NomFich.c_str()) == 0)
3844 if (aSO->FindAttribute(aGAttr,"AttributeName"))
3846 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3847 CORBA::String_var value2=anAttr2->Value();
3848 if (strcmp((const char*)value2,MeshName.c_str()) == 0)
3850 myBuilder->RemoveObjectWithChildren( aSO ) ;
3858 //=============================================================================
3859 void HOMARD_Gen_i::PublishMeshIterInSmesh(const char* NomIter)
3861 MESSAGE( "PublishMeshIterInSmesh " << NomIter);
3862 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3864 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3865 if (CORBA::is_nil(myIteration))
3867 SALOME::ExceptionStruct es;
3868 es.type = SALOME::BAD_PARAM;
3869 es.text = "Invalid iterationStudy Object";
3870 throw SALOME::SALOME_Exception(es);
3873 const char* MeshFile = myIteration->GetMeshFile() ;
3874 const char* MeshName = myIteration->GetMeshName() ;
3875 CORBA::Long Option = -1 ;
3876 int etat = myIteration->GetState();
3877 // Iteration initiale
3878 if ( etat <= 0 ) { Option = 0 ; }
3879 // ou iteration calculee
3880 else if ( etat == 2 ) { Option = 1 ; }
3881 // Publication effective apres menage eventuel
3884 DeleteResultInSmesh(MeshFile, MeshName) ;
3885 PublishResultInSmesh(MeshFile, Option) ;
3889 //=============================================================================
3890 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
3892 // MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3893 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3895 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3896 if (CORBA::is_nil(myIteration))
3898 SALOME::ExceptionStruct es;
3899 es.type = SALOME::BAD_PARAM;
3900 es.text = "Invalid iterationStudy Object";
3901 throw SALOME::SALOME_Exception(es);
3905 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3907 aStudyBuilder->NewCommand();
3909 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
3910 // Pour les fichiers med, on affiche une icone de maillage
3911 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
3912 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
3914 std::string ior = " " ;
3915 if ( Commentaire[0] == 'M' )
3916 { icone = "med.png" ; }
3918 { icone = "texte_2.png" ; }
3919 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3921 aStudyBuilder->CommitCommand();
3924 //=============================================================================
3925 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
3927 // MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3928 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3930 SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3931 if (CORBA::is_nil(myYACS))
3933 SALOME::ExceptionStruct es;
3934 es.type = SALOME::BAD_PARAM;
3935 es.text = "Invalid YACSStudy Object";
3936 throw SALOME::SALOME_Exception(es);
3940 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3942 aStudyBuilder->NewCommand();
3944 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3945 std::string icone = "texte_2.png" ;
3946 std::string ior = " " ;
3947 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3949 aStudyBuilder->CommitCommand();
3952 //=============================================================================
3953 //=============================================================================
3955 //=============================================================================
3956 //=============================================================================
3957 //=============================================================================
3958 // Creation d'un schema YACS
3959 // nomCas : nom du cas a traiter
3960 // FileName : nom du fichier contenant le script de lancement du calcul
3961 // DirName : le repertoire de lancement des calculs du schéma
3962 //=============================================================================
3963 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
3965 INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
3966 INFOS ( ". nomCas : " << nomCas);
3967 INFOS ( ". ScriptFile : " << ScriptFile);
3968 INFOS ( ". DirName : " << DirName);
3969 INFOS ( ". MeshFile : " << MeshFile);
3971 // A. Controle du nom :
3972 if ((myContextMap[GetCurrentStudyID()]._mesYACSs).find(nomYACS) != (myContextMap[GetCurrentStudyID()]._mesYACSs).end())
3974 SALOME::ExceptionStruct es;
3975 es.type = SALOME::BAD_PARAM;
3976 es.text = "This schema YACS has already been defined.";
3977 throw SALOME::SALOME_Exception(es);
3981 // B. Creation de l'objet
3982 HOMARD::HOMARD_YACS_var myYACS = newYACS();
3983 if (CORBA::is_nil(myYACS))
3985 SALOME::ExceptionStruct es;
3986 es.type = SALOME::BAD_PARAM;
3987 es.text = "Unable to create the schema YACS";
3988 throw SALOME::SALOME_Exception(es);
3991 myYACS->SetName( nomYACS ) ;
3993 // C. Enregistrement
3994 myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS] = myYACS;
3996 SALOMEDS::SObject_var aSO;
3997 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myYACS, nomYACS);
3999 PublishCaseUnderYACS(nomYACS, nomCas);
4001 // D. Caracterisation
4003 myYACS->SetDirName( DirName ) ;
4004 myYACS->SetMeshFile( MeshFile ) ;
4005 myYACS->SetScriptFile( ScriptFile ) ;
4006 myYACS->SetCaseName( nomCas ) ;
4009 // D.2.1. Type constant
4010 myYACS->SetType( 1 ) ;
4011 // D.2.2. Convergence
4012 defaut_i = GetYACSMaxIter() ;
4013 myYACS->SetMaxIter( defaut_i ) ;
4014 defaut_i = GetYACSMaxNode() ;
4015 myYACS->SetMaxNode( defaut_i ) ;
4016 defaut_i = GetYACSMaxElem() ;
4017 myYACS->SetMaxElem( defaut_i ) ;
4018 // D.3. Fichier de sauvegarde dans le repertoire du cas
4019 HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
4020 std::string dirnamecase = caseyacs->GetDirName() ;
4021 std::string XMLFile ;
4022 XMLFile = dirnamecase + "/schema.xml" ;
4023 myYACS->SetXMLFile( XMLFile.c_str() ) ;
4025 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
4027 //=============================================================================
4028 // Ecriture d'un schema YACS
4029 //=============================================================================
4030 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
4032 INFOS ( "YACSWrite : Ecriture de " << nomYACS );
4033 // Le repertoire du cas
4034 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4035 ASSERT(!CORBA::is_nil(myYACS));
4036 // Le nom du fichier du schema
4037 std::string XMLFile ;
4038 XMLFile = myYACS->GetXMLFile() ;
4040 int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
4044 //=============================================================================
4045 // Ecriture d'un schema YACS sur un fichier donne
4046 //=============================================================================
4047 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
4049 INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
4056 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4057 ASSERT(!CORBA::is_nil(myYACS));
4058 // B.2. Les caracteristiques
4059 std::string DirName = myYACS->GetDirName() ;
4060 std::string MeshFile = myYACS->GetMeshFile() ;
4061 std::string ScriptFile = myYACS->GetScriptFile() ;
4062 // B.3. Les caracteristiques de convergence
4063 int MaxIter = myYACS->GetMaxIter() ;
4064 int MaxNode = myYACS->GetMaxNode() ;
4065 int MaxElem = myYACS->GetMaxElem() ;
4069 const char* nomCas = myYACS->GetCaseName();
4070 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
4071 ASSERT(!CORBA::is_nil(myCase));
4072 // C.2. Les instructions python associees au cas
4073 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4074 std::string pythonCas = dumpCorbaCase.in();
4075 MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
4077 // D. Les iterations
4078 // D.1. L'iteration initiale
4079 HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
4080 std::string Iter0Name = myCase->GetIter0Name() ;
4081 MESSAGE (". Iter0Name = " << Iter0Name);
4082 std::string MeshName = Iter0->GetMeshName();
4083 MESSAGE (". MeshName = " << MeshName);
4084 // D.2. L'iteration numero 1
4085 HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
4086 int numberOfIter = maListe->length();
4087 if ( numberOfIter > 1 )
4089 MESSAGE (". numberOfIter = " << numberOfIter);
4090 SALOME::ExceptionStruct es ;
4091 es.type = SALOME::BAD_PARAM;
4092 std::string text = "Une seule iteration est permise." ;
4093 es.text = CORBA::string_dup(text.c_str());
4094 throw SALOME::SALOME_Exception(es);
4097 std::string Iter1Name = std::string((*maListe)[0]);
4098 MESSAGE ("... Iter1Name = " << Iter1Name);
4099 HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
4100 // D.3. Les instructions python associees a l'iteration
4101 CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
4102 std::string pythonIter = dumpCorbaIter.in();
4103 MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
4105 // E. L'hypothese pour passer de l'iteration initiale a la suivante
4106 // E.1. La structure
4107 std::string nomHypo = Iter1->GetHypoName();
4108 MESSAGE (". nomHypo = " << nomHypo);
4109 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
4110 ASSERT(!CORBA::is_nil(myHypo));
4111 // E.2. Les caracteristiques de l'adaptation
4112 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
4113 ASSERT(ListTypes->length() == 3);
4114 int TypeAdap = (*ListTypes)[0];
4115 // int TypeRaff = (*ListTypes)[1];
4116 // int TypeDera = (*ListTypes)[2];
4117 // E.3. Les instructions python associees a l'hypothese
4118 CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
4119 std::string pythonHypo = dumpCorbaHypo.in();
4120 MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
4122 // F. Le fichier du schema de reference
4123 // HOMARD_ROOT_DIR : repertoire ou se trouve le module HOMARD
4124 std::string XMLFile_base ;
4125 if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
4128 SALOME::ExceptionStruct es ;
4129 es.type = SALOME::BAD_PARAM;
4130 std::string text = "HOMARD_ROOT_DIR est inconnu." ;
4131 es.text = CORBA::string_dup(text.c_str());
4132 throw SALOME::SALOME_Exception(es);
4135 XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
4137 MESSAGE("XMLFile_base ="<<XMLFile_base);
4139 // G. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4140 YACSDriver* myDriver = new YACSDriver(XMLFile, DirName);
4141 std::ifstream fichier( XMLFile_base.c_str() );
4142 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
4144 // G.1. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4145 std::string ligne; // variable contenant chaque ligne lue
4146 std::string mot_cle;
4147 while ( std::getline( fichier, ligne ) )
4149 // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
4150 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
4151 ligne_bis >> mot_cle ;
4152 // G.1.2. Le maillage initial
4153 if ( mot_cle == "DataInit_MeshFile" )
4154 { myDriver->Texte_DataInit_MeshFile(MeshFile); }
4155 // G.1.3. Le script de lancement
4156 else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
4157 { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
4158 // G.1.4. Les options du cas
4159 else if ( mot_cle == "Iter_1_Case_Options" )
4160 { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
4161 // G.1.5. Execution de HOMARD : le repertoire du cas
4162 else if ( mot_cle == "HOMARD_Exec_DirName" )
4163 { myDriver->Texte_HOMARD_Exec_DirName(); }
4164 // G.1.6. Execution de HOMARD : le nom du maillage
4165 else if ( mot_cle == "HOMARD_Exec_MeshName" )
4167 myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
4168 std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
4169 myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
4171 // G.1.7. Execution de HOMARD : les options de l'hypothese
4172 else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
4173 { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ; }
4174 // G.1.8. Execution de HOMARD : les options de l'iteration
4175 else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
4176 { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ; }
4177 // G.1.9. a. Creation eventuelles des zones et frontieres
4179 else if ( mot_cle == "Iter_1" )
4181 std::string texte_control = "" ;
4182 if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
4183 texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
4184 texte_control += myDriver->Texte_Iter_1_control() ;
4185 myDriver->TexteAdd(texte_control);
4187 // G.1.10. Les tests de convergence
4188 else if ( mot_cle == "Analyse_Test_Convergence" )
4189 { myDriver->TexteAnalyse_Test_Convergence(MaxIter, MaxNode, MaxElem); }
4190 // G.1.11. Les parametres
4191 else if ( mot_cle == "PARAMETRES" )
4192 { myDriver->TexteAddParametres(); }
4193 // G.1.n. La ligne est recopiee telle quelle
4194 else { myDriver->TexteAdd(ligne); }
4196 // G.2. Ecriture du texte dans le fichier
4198 { myDriver->CreeFichier(); }
4202 SALOME::ExceptionStruct es;
4203 es.type = SALOME::BAD_PARAM;
4204 std::string text = "The reference file for the YACS schema cannot be read." ;
4205 es.text = CORBA::string_dup(text.c_str());
4206 throw SALOME::SALOME_Exception(es);
4211 // H. Publication du fichier dans l'arbre
4213 std::string Commentaire = "xml" ;
4214 PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
4218 //=============================================================================
4219 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
4220 //=============================================================================
4221 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
4223 MESSAGE ( "YACSDriverTexteZone" );
4224 // A. Les zones associees a cette hypothese
4225 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
4226 int numberOfZonesx2 = ListZone->length();
4228 // B. Parcours des zones
4229 std::string texte_control ;
4230 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
4232 // 1. Reperage de la zone
4233 std::string ZoneName = std::string((*ListZone)[iaux]);
4234 MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
4235 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
4236 ASSERT(!CORBA::is_nil(myZone));
4237 // 2. Les instructions python associees a la zone
4238 // La premiere ligne est un commentaire a eliminer
4239 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4240 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4241 std::string pythonStructure_0 = dumpCorbaZone.in();
4242 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4243 std::istringstream tout (pythonStructure_0) ;
4245 std::string pythonStructure ;
4246 while ( std::getline( tout, ligne ) )
4247 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4248 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4249 // 3. Decodage du nom du service
4250 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4251 MESSAGE ( "... methode = " << methode);
4252 // 4. Mise en place des instructions
4253 int ZoneType = myZone->GetType();
4254 MESSAGE ( "... ZoneType = " << ZoneType);
4255 std::string texte_control_0 ;
4256 texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
4257 texte_control += texte_control_0 ;
4262 return texte_control ;
4264 //=============================================================================
4265 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4266 //=============================================================================
4267 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4269 MESSAGE ( "YACSDriverTexteBoundary" );
4270 // A. Les frontieres associees au cas
4271 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4272 int numberOfitems = ListBoundaryGroupType->length();
4274 // B. Parcours des frontieres
4275 std::string texte_control ;
4276 std::list<std::string> ListeBoundaryTraitees ;
4277 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4279 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4280 MESSAGE ( "... BoundaryName = " << BoundaryName);
4281 // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4282 // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4284 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4285 while (it != ListeBoundaryTraitees.end())
4287 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4288 if ( BoundaryName == *it ) { A_faire = 0 ; }
4293 // 1. Caracteristiques de la frontiere
4294 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
4295 ASSERT(!CORBA::is_nil(myBoundary));
4296 // 2. Les instructions python associees a la frontiere
4297 // La premiere ligne est un commentaire a eliminer
4298 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4299 CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4300 std::string pythonStructure_0 = dumpCorbaBoundary.in();
4301 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4302 std::istringstream tout (pythonStructure_0) ;
4304 std::string pythonStructure ;
4305 while ( std::getline( tout, ligne ) )
4306 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4307 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4308 // 3. Decodage du nom du service
4309 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4310 MESSAGE ( "... methode = " << methode);
4311 // 4. Mise en place des instructions
4312 int BoundaryType = myBoundary->GetType();
4313 MESSAGE ( "... BoundaryType = " << BoundaryType);
4314 const char* MeshName ;
4315 const char* MeshFile ;
4316 if (BoundaryType == 0)
4318 MeshName = myBoundary->GetMeshName() ;
4319 MESSAGE ( ". MeshName = " << MeshName );
4320 MeshFile = myBoundary->GetMeshFile() ;
4321 MESSAGE ( ". MeshFile = " << MeshFile );
4323 std::string texte_control_0 ;
4324 texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName, MeshName, MeshFile );
4325 texte_control += texte_control_0 ;
4326 // 5. Memorisation du traitement
4327 ListeBoundaryTraitees.push_back( BoundaryName );
4331 return texte_control ;
4334 //=============================================================================
4335 //=============================================================================
4336 // Next functions are inherited from SALOMEDS::Driver interface
4337 //=============================================================================
4338 //=============================================================================
4339 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4341 CORBA::Boolean isMultiFile)
4343 MESSAGE ("Save for theURL = "<< theURL);
4344 SALOMEDS::TMPFile_var aStreamFile;
4346 // get temporary directory name
4347 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4349 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4350 StudyContext& context = myContextMap[ aStudy->StudyId() ];
4352 // HOMARD data file name
4353 std::string aFileName = "";
4355 aFileName = SALOMEDS_Tool::GetNameFromPath(Kernel_Utils::encode(aStudy->URL()));
4356 aFileName += "_HOMARD.dat";
4358 // initialize sequence of file names
4359 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
4360 aFileSeq->length(1);
4361 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
4363 // get full path to the data file
4364 aFileName = tmpDir + aFileName;
4368 std::ofstream f(aFileName.c_str());
4370 // clear temporary id map
4371 context._idmap.clear();
4376 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4377 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4378 HOMARD::HOMARD_Cas_var aCas = it_case->second;
4379 PortableServer::ServantBase_var aServant = GetServant(aCas);
4380 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4382 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4383 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4387 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4388 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4389 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4390 PortableServer::ServantBase_var aServant = GetServant(aZone);
4391 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4393 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4394 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4397 // -> save hypotheses
4398 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4399 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4400 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4401 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4402 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4404 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4405 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4408 // -> save iterations
4409 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4410 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4411 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4412 PortableServer::ServantBase_var aServant = GetServant(aIter);
4413 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4415 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4416 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4419 // -> save boundaries
4420 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4421 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4422 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4423 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4424 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4425 if (aBoundaryServant) {
4426 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4427 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4431 MESSAGE ("close file");
4434 // put temporary files to the stream
4435 MESSAGE ("put temporary files to the stream");
4436 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
4438 // remove temporary files
4439 MESSAGE ("remove temporary files");
4440 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4442 // return data stream
4443 MESSAGE ("return data stream");
4444 return aStreamFile._retn();
4447 //===========================================================================
4448 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4450 CORBA::Boolean isMultiFile)
4452 // No specific ASCII persistence
4453 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4454 return aStreamFile._retn();
4457 //===========================================================================
4458 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4459 const SALOMEDS::TMPFile& theStream,
4461 CORBA::Boolean isMultiFile)
4463 MESSAGE ("Load pour theURL = "<< theURL);
4464 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4466 // set current study
4467 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
4468 SetCurrentStudy(aStudy);
4470 // get temporary directory name
4471 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4473 // Convert the stream into sequence of files to process
4474 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4477 // HOMARD data file name
4478 std::string aFileName = "";
4480 aFileName = SALOMEDS_Tool::GetNameFromPath(Kernel_Utils::encode(aStudy->URL()));
4481 aFileName = tmpDir + aFileName + "_HOMARD.dat";
4483 StudyContext& context = myContextMap[ aStudy->StudyId() ];
4487 std::ifstream f(aFileName.c_str());
4490 context._mesCas.clear();
4491 context._mesHypotheses.clear();
4492 context._mesIterations.clear();
4493 context._mesZones.clear();
4494 context._mesBoundarys.clear();
4495 context._idmap.clear();
4501 std::getline(f, line);
4502 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4503 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4504 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4505 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4506 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4507 std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4508 if (line.substr(0, bounSignature.size()) == bounSignature) {
4509 // re-create boundary
4510 MESSAGE ("Recreation de la frontiere" );
4511 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4512 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4513 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4514 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4515 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4516 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4519 else if (line.substr(0, caseSignature.size()) == caseSignature) {
4521 MESSAGE ("Recreation du cas" );
4522 HOMARD::HOMARD_Cas_var aCase = newCase();
4523 PortableServer::ServantBase_var aServant = GetServant(aCase);
4524 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4525 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4526 context._mesCas[aCase->GetName()] = aCase;
4527 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4530 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4531 // re-create hypothesis
4532 MESSAGE ("Recreation de l hypothese" );
4533 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4534 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4535 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4536 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4537 context._mesHypotheses[aHypo->GetName()] = aHypo;
4538 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4541 else if (line.substr(0, iterSignature.size()) == iterSignature) {
4542 // re-create iteration
4543 MESSAGE ("Recreation de l'iteration" );
4544 HOMARD::HOMARD_Iteration_var aIter = newIteration();
4545 PortableServer::ServantBase_var aServant = GetServant(aIter);
4546 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4547 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4548 context._mesIterations[aIter->GetName()] = aIter;
4549 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4552 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4553 MESSAGE ("Recreation de la zone" );
4555 HOMARD::HOMARD_Zone_var aZone = newZone();
4556 PortableServer::ServantBase_var aServant = GetServant(aZone);
4557 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4558 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4559 context._mesZones[aZone->GetName()] = aZone;
4560 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4563 else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4564 MESSAGE ("Recreation du schema YACS" );
4566 HOMARD::HOMARD_YACS_var aYACS = newYACS();
4567 PortableServer::ServantBase_var aServant = GetServant(aYACS);
4568 HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4569 if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4570 context._mesYACSs[aYACS->GetName()] = aYACS;
4571 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4580 // Remove temporary files created from the stream
4582 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4587 //===========================================================================
4588 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4589 const SALOMEDS::TMPFile& theStream,
4591 CORBA::Boolean isMultiFile)
4593 // No specific ASCII persistence
4594 return Load(theComponent, theStream, theURL, isMultiFile);
4597 //===========================================================================
4598 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4600 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
4601 // clearing study context should be done here:
4602 // - destroy all servants and related CORBA objects
4604 // - remove context from myContextMap
4605 myContextMap.erase(theComponent->GetStudy()->StudyId());
4606 // - nullify myCurrentStudy
4607 myCurrentStudy = SALOMEDS::Study::_nil();
4611 //===========================================================================
4612 char* HOMARD_Gen_i::ComponentDataType()
4614 return CORBA::string_dup("HOMARD");
4617 //===========================================================================
4618 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4619 const char* IORString,
4620 CORBA::Boolean isMultiFile,
4621 CORBA::Boolean isASCII)
4623 CORBA::String_var aString("");
4624 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4625 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4626 CORBA::Object_var anObj = _orb->string_to_object(IORString);
4627 if (!CORBA::is_nil(anObj)) {
4628 PortableServer::ServantBase_var aServant = GetServant(anObj);
4629 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4631 std::map<int, PortableServer::ServantBase*>::const_iterator it;
4632 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4633 if (it->second == aStorable) {
4634 std::stringstream os;
4636 aString = CORBA::string_dup(os.str().c_str());
4642 return aString._retn();
4645 //===========================================================================
4646 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4647 const char* aLocalPersistentID,
4648 CORBA::Boolean isMultiFile,
4649 CORBA::Boolean isASCII)
4651 CORBA::String_var aString("");
4652 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4653 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4654 int id = atoi(aLocalPersistentID);
4655 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4656 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4657 if (!CORBA::is_nil(object)) {
4658 aString = _orb->object_to_string(object);
4662 return aString._retn();
4665 //===========================================================================
4666 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4668 if(CORBA::is_nil(myCurrentStudy))
4671 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4672 if(!aCas->_is_nil())
4675 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4676 if(!aHypo->_is_nil())
4679 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4680 if(!aZone->_is_nil())
4683 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4684 if(!aBoundary->_is_nil())
4687 /* Iteration is not published directly
4688 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4689 if(!aIter->_is_nil())
4695 //===========================================================================
4696 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4698 // No Copy/Paste support
4702 //===========================================================================
4703 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4704 CORBA::Long& theObjectID)
4706 // No Copy/Paste support
4707 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4708 return aStreamFile._retn();
4711 //===========================================================================
4712 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
4713 CORBA::Long theObjectID)
4715 // No Copy/Paste support
4719 //===========================================================================
4720 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4721 CORBA::Long theObjectID,
4722 SALOMEDS::SObject_ptr theSObject)
4724 // No Copy/Paste support
4725 SALOMEDS::SObject_var aResultSO;
4726 return aResultSO._retn();
4729 //===========================================================================
4730 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4732 PortableServer::Servant aServant = 0;
4733 if (!CORBA::is_nil(theObject)) {
4735 aServant = _poa->reference_to_servant(theObject);
4743 //==========================================================================
4744 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4745 CORBA::Boolean isPublished,
4746 CORBA::Boolean isMultiFile,
4747 CORBA::Boolean& isValidScript)
4749 MESSAGE ("Entree dans DumpPython");
4751 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
4752 if(CORBA::is_nil(aStudy))
4753 return new Engines::TMPFile(0);
4755 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
4756 if(CORBA::is_nil(aSO))
4757 return new Engines::TMPFile(0);
4759 std::string aScript = "\"\"\"\n";
4760 aScript += "Python script for HOMARD\n";
4761 aScript += "Copyright 1996, 2011, 2015 EDF\n";
4762 aScript += "\"\"\"\n";
4763 aScript += "__revision__ = \"V1.2\"\n";
4764 aScript += "import HOMARD\n";
4766 aScript += "import salome\n";
4767 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4769 aScript += "def RebuildData(theStudy):\n";
4770 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
4773 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
4774 MESSAGE (". Au depart \n"<<aScript);
4777 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
4779 MESSAGE (". Ecritures des frontieres");
4780 aScript += "#\n# Creation of the boundaries";
4781 aScript += "\n# ==========================";
4783 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4784 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
4785 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
4787 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4788 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4789 std::string dumpBoundary = dumpCorbaBoundary.in();
4790 MESSAGE (dumpBoundary<<"\n");
4791 aScript += dumpBoundary;
4795 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
4797 MESSAGE (". Ecritures des zones");
4798 aScript += "#\n# Creation of the zones";
4799 aScript += "\n# =====================";
4801 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4802 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
4803 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
4805 HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
4806 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4807 std::string dumpZone = dumpCorbaZone.in();
4808 MESSAGE (dumpZone<<"\n");
4809 aScript += dumpZone;
4813 if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
4815 MESSAGE (". Ecritures des hypotheses");
4816 aScript += "#\n# Creation of the hypotheses";
4817 aScript += "\n# ==========================";
4819 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4820 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
4821 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
4823 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
4824 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
4825 std::string dumpHypo = dumpCorbaHypo.in();
4826 MESSAGE (dumpHypo<<"\n");
4827 aScript += dumpHypo;
4831 if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
4833 MESSAGE (". Ecritures des cas");
4834 aScript += "#\n# Creation of the cases";
4835 aScript += "\n# =====================";
4837 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
4838 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4839 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
4841 std::string nomCas = (*it_cas).first;
4842 std::string dumpCas = std::string("\n# Creation of the case ") ;
4843 dumpCas += nomCas + std::string("\n");
4844 dumpCas += std::string("\t") + nomCas;
4845 dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
4847 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
4848 CORBA::String_var cIter0= myCase->GetIter0Name();
4849 std::string iter0 = cIter0.in();
4851 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
4852 CORBA::String_var cMesh0= myIteration->GetMeshFile();
4853 std::string mesh0 = cMesh0.in();
4854 CORBA::String_var cMeshName0= myIteration->GetMeshName();
4855 std::string meshName0 = cMeshName0.in();
4856 dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
4857 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4858 std::string dumpCas2= dumpCorbaCase.in();
4860 MESSAGE (dumpCas<<dumpCas2<<"\n");
4861 aScript += dumpCas + dumpCas2;
4865 if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
4867 MESSAGE (". Ecritures des iterations");
4868 aScript += "#\n# Creation of the iterations" ;
4869 aScript += "\n# ==========================";
4871 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4872 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
4873 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
4875 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
4876 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
4877 std::string dumpIter = dumpCorbaIter.in();
4878 MESSAGE (dumpIter<<"\n");
4879 aScript += dumpIter;
4883 if (myContextMap[GetCurrentStudyID()]._mesYACSs.size() > 0)
4885 MESSAGE (". Ecritures des schemas YACS");
4886 aScript += "#\n# Creation of the schemas YACS";
4887 aScript += "\n# ============================";
4889 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
4890 for ( it_yacs = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
4891 it_yacs != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); ++it_yacs)
4893 HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
4894 CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
4895 std::string dumpYACS = dumpCorbaYACS.in();
4896 MESSAGE (dumpYACS<<"\n");
4897 aScript += dumpYACS;
4900 MESSAGE (". Ecritures finales");
4902 aScript += "\n\tpass";
4905 if( !isMultiFile ) // remove unnecessary tabulation
4906 aScript = RemoveTabulation( aScript );
4908 // MESSAGE ("A ecrire \n"<<aScript);
4909 const size_t aLen = strlen(aScript.c_str());
4910 char* aBuffer = new char[aLen+1];
4911 strcpy(aBuffer, aScript.c_str());
4913 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
4914 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
4916 MESSAGE ("Sortie de DumpPython");
4917 return aStreamFile._retn();
4921 //=============================================================================
4922 //=============================================================================
4924 //=============================================================================
4925 //=============================================================================
4926 void HOMARD_Gen_i::IsValidStudy( )
4928 // MESSAGE( "IsValidStudy" );
4929 if (CORBA::is_nil(myCurrentStudy))
4931 SALOME::ExceptionStruct es;
4932 es.type = SALOME::BAD_PARAM;
4933 es.text = "Invalid study context";
4934 throw SALOME::SALOME_Exception(es);
4939 //=============================================================================
4940 char* HOMARD_Gen_i::VerifieDir(const char* nomDir)
4942 std::string casename = std::string("") ;
4943 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
4944 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4945 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
4947 if (std::string(nomDir) == std::string(it->second->GetDirName()))
4949 casename = std::string(it->second->GetName()) ;
4953 return CORBA::string_dup( casename.c_str() );
4955 /*//=============================================================================
4956 void SALOMEException( std::string message )
4958 SALOME::ExceptionStruct es;
4959 es.type = SALOME::BAD_PARAM;
4961 throw SALOME::SALOME_Exception(es);
4964 //=============================================================================
4965 char* HOMARD_Gen_i::getVersion()
4967 #if HOMARD_DEVELOPMENT
4968 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
4970 return CORBA::string_dup(HOMARD_VERSION_STR);
4973 //===============================================================================
4974 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un caractere
4975 // ligne : la ligne a manipuler
4976 // caractere : le caractere a reperer
4977 // option : 0 : la chaine avant la premiere apparition du caractere
4978 // 1 : la chaine apres la premiere apparition du caractere
4979 // 2 : la chaine avant la derniere apparition du caractere
4980 // 3 : la chaine apres la derniere apparition du caractere
4981 // Si le caractere est absent, on retourne la chaine totale
4982 //===============================================================================
4983 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string caractere, int option )
4985 // MESSAGE("GetStringInTexte, recherche de '"<<caractere<<"' dans '"<<ligne<<"'"<<", option = "<<option);
4987 std::string chaine = ligne ;
4989 if ( option < 2 ) { position = ligne.find_first_of( caractere ) ; }
4990 else { position = ligne.find_last_of( caractere ) ; }
4991 // MESSAGE("position = "<<position);
4992 // MESSAGE("a = "<<ligne.substr( 0, position ).c_str());
4993 // MESSAGE("b = "<<ligne.substr( position+1 ).c_str());
4995 if ( position != std::string::npos )
4997 if ( ( option == 0 ) || ( option == 2 ) ) { chaine = ligne.substr( 0, position ) ; }
4998 else { chaine = ligne.substr( position+1 ) ; }
5003 //=============================================================================
5004 //=============================================================================
5005 // Gestion des preferences
5006 //=============================================================================
5007 //=============================================================================
5008 // Decodage du fichier d'arcihvage des preferences
5010 void HOMARD_Gen_i::SetPreferences( )
5012 MESSAGE ( "SetPreferences" );
5014 std::string ligne, mot_cle, salome_version ;
5017 // A. Les valeurs par defaut ; elles doivent etre coherentes
5018 std::string LanguageShort = "en" ;
5019 int PublisMeshIN = 0 ;
5020 int PublisMeshOUT = 0 ;
5021 int YACSMaxIter = 0 ;
5022 int YACSMaxNode = 0 ;
5023 int YACSMaxElem = 0 ;
5024 std::string YACSTypeTestchaine = "None" ;
5026 // B. La version de salome
5027 // Cela se presente sous la forme :
5028 // [SALOME KERNEL] : 7.3.0
5030 File = getenv("KERNEL_ROOT_DIR") ;
5031 File += "/bin/salome/VERSION" ;
5032 MESSAGE ( "File = "<<File ) ;
5033 std::ifstream fichier0( File.c_str() ) ;
5034 if ( fichier0 ) // ce test échoue si le fichier n'est pas ouvert
5036 std::string ligne; // variable contenant chaque ligne lue
5037 while ( std::getline( fichier0, ligne ) )
5039 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5040 ligne_bis >> mot_cle ;
5041 if ( mot_cle == "[SALOME" )
5043 salome_version = GetStringInTexte ( ligne, " ", 3 ) ;
5044 // MESSAGE ( "salome_version = "<<salome_version<<"|||");
5049 else { ok = false ; }
5051 // B. Decodage du fichier de preferences
5054 std::string PrefFile ;
5055 PrefFile = getenv("HOME") ;
5056 PrefFile += "/.config/salome/SalomeApprc." + salome_version ;
5057 MESSAGE ( "PrefFile = "<<PrefFile ) ;
5059 std::ifstream fichier( PrefFile.c_str() );
5060 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
5062 bool section_langue = false ;
5063 bool section_homard = false ;
5064 while ( std::getline( fichier, ligne ) )
5066 std::string chaine ;
5067 // 1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
5068 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5069 ligne_bis >> mot_cle ;
5072 // 2.1. Debut d'une section
5073 // MESSAGE(mot_cle);
5074 if ( mot_cle == "<section" )
5075 { /*MESSAGE ( "Debut de la section : "<< ligne);*/
5076 ligne_bis >> mot_cle ;
5077 chaine = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5078 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5079 if ( chaine == "language" ) { section_langue = true ; }
5080 if ( chaine == "HOMARD" ) { section_homard = true ; }
5081 // MESSAGE ( "section_langue = "<<section_langue<<", section_homard = "<<section_homard);
5083 // 2.2. Fin d'une section
5084 else if ( mot_cle == "</section>" )
5085 { /*MESSAGE ( "Fin de la section : "<< ligne<<", section_langue = "<<section_langue<<", section_homard = "<<section_homard);*/
5086 section_langue = false ;
5087 section_homard = false ; }
5091 else if ( section_langue || section_homard )
5092 { MESSAGE ( "a decoder : "<< ligne);
5093 // La valeur : entre les deux premieres quotes
5094 chaine = GetStringInTexte ( ligne, "\"", 1 ) ;
5095 // MESSAGE("chaine 1 = |"<<chaine<<"|");
5096 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5097 // MESSAGE("chaine = |"<<chaine<<"|");
5098 // Le mot_cle : entre les deux dernieres quotes
5099 std::string chaine2 = GetStringInTexte ( ligne, "\"", 2 ) ;
5100 // MESSAGE("chaine2 1 = |"<<chaine2<<"|");
5101 chaine2 = GetStringInTexte ( chaine2, "\"", 3 ) ;
5102 // MESSAGE("chaine2 = |"<<chaine2<<"|");
5104 if ( section_langue )
5105 { if ( chaine2 == "language" ) { LanguageShort = chaine ; } }
5107 if ( section_homard )
5109 std::istringstream chainebis( chaine ) ;
5110 // 3.2.1. Les publications
5111 if ( chaine2 == "publish_mesh_in" ) { chainebis >> PublisMeshIN ; }
5112 if ( chaine2 == "publish_mesh_out" ) { chainebis >> PublisMeshOUT ; }
5113 // 3.2.2. Les maximum pour YACS
5114 if ( chaine2 == "yacs_max_iter" ) { chainebis >> YACSMaxIter ; }
5115 if ( chaine2 == "yacs_max_node" ) { chainebis >> YACSMaxNode ; }
5116 if ( chaine2 == "yacs_max_elem" ) { chainebis >> YACSMaxElem ; }
5117 if ( chaine2 == "yacs_type_test" ) { YACSTypeTestchaine = chaine ; }
5124 // C. Enregistrements
5125 MESSAGE ("Enregistrement de LanguageShort = " << LanguageShort );
5126 SetLanguageShort( LanguageShort.c_str() ) ;
5128 MESSAGE ("Enregistrement de PublisMeshIN = " << PublisMeshIN<<", PublisMeshOUT = "<< PublisMeshOUT);
5129 SetPublisMesh(PublisMeshIN, PublisMeshOUT) ;
5131 MESSAGE ("Enregistrement de YACSMaxIter = " << YACSMaxIter<<", YACSMaxNode = "<< YACSMaxNode<<", YACSMaxElem = "<< YACSMaxElem);
5132 SetYACSMaximum(YACSMaxIter, YACSMaxNode, YACSMaxElem) ;
5134 MESSAGE ("Enregistrement de TypeTest = " << YACSTypeTestchaine.c_str() );
5136 if ( ( YACSTypeTestchaine == "VTest > VRef" ) || ( YACSTypeTestchaine == "VTest > VRef" ) ) { YACSTypeTest = 1 ; }
5137 else if ( ( YACSTypeTestchaine == "VTest < VRef" ) || ( YACSTypeTestchaine == "VTest < VRef" ) ) { YACSTypeTest = 2 ; }
5138 else { YACSTypeTest = 0 ; }
5139 MESSAGE ("==> TypeTest = " << YACSTypeTest );
5140 SetYACSConvergenceType( YACSTypeTest ) ;
5144 //===============================================================================
5146 //===============================================================================
5147 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
5149 // MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
5150 _LangueShort = LanguageShort ;
5151 if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
5152 else { _Langue = "English" ; }
5155 char* HOMARD_Gen_i::GetLanguageShort()
5157 // MESSAGE ("GetLanguageShort");
5158 return CORBA::string_dup( _LangueShort.c_str() );
5160 //===============================================================================
5161 // Options de publications
5162 //===============================================================================
5163 void HOMARD_Gen_i::SetPublisMesh(CORBA::Long PublisMeshIN, CORBA::Long PublisMeshOUT)
5165 _PublisMeshIN = PublisMeshIN ;
5166 _PublisMeshOUT = PublisMeshOUT ;
5169 CORBA::Long HOMARD_Gen_i::GetPublisMeshIN()
5171 return _PublisMeshIN ;
5173 CORBA::Long HOMARD_Gen_i::GetPublisMeshOUT()
5175 return _PublisMeshOUT ;
5177 //===============================================================================
5178 // YACS - test de convergence
5179 //===============================================================================
5180 void HOMARD_Gen_i::SetYACSMaximum(CORBA::Long YACSMaxIter, CORBA::Long YACSMaxNode, CORBA::Long YACSMaxElem)
5182 _YACSMaxIter = YACSMaxIter ;
5183 _YACSMaxNode = YACSMaxNode ;
5184 _YACSMaxElem = YACSMaxElem ;
5187 CORBA::Long HOMARD_Gen_i::GetYACSMaxIter()
5189 return _YACSMaxIter ;
5191 CORBA::Long HOMARD_Gen_i::GetYACSMaxNode()
5193 return _YACSMaxNode ;
5195 CORBA::Long HOMARD_Gen_i::GetYACSMaxElem()
5197 return _YACSMaxElem ;
5199 void HOMARD_Gen_i::SetYACSConvergenceType(CORBA::Long YACSTypeTest)
5201 _YACSTypeTest = YACSTypeTest ;
5204 CORBA::Long HOMARD_Gen_i::GetYACSConvergenceType()
5206 return _YACSTypeTest ;
5209 //=============================================================================
5213 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
5214 PortableServer::POA_ptr poa,
5215 PortableServer::ObjectId* contId,
5216 const char* instanceName,
5217 const char* interfaceName)
5219 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
5220 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
5221 return myHOMARD_Gen->getId();