1 // Copyright (C) 2011-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "HOMARD_Gen_i.hxx"
21 #include "HOMARD_Cas_i.hxx"
22 #include "HOMARD_Hypothesis_i.hxx"
23 #include "HOMARD_Iteration_i.hxx"
24 #include "HOMARD_Boundary_i.hxx"
25 #include "HOMARD_Zone_i.hxx"
26 #include "HOMARD_YACS_i.hxx"
27 #include "HomardDriver.hxx"
28 #include "HOMARD_DriverTools.hxx"
29 #include "HomardMedCommun.h"
30 #include "YACSDriver.hxx"
33 #include "HOMARD_version.h"
35 #include "utilities.h"
36 #include "Utils_SINGLETON.hxx"
37 #include "Utils_CorbaException.hxx"
38 #include "SALOMEDS_Tool.hxx"
39 #include "SALOME_LifeCycleCORBA.hxx"
40 #include "SALOMEconfig.h"
41 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
42 #include CORBA_CLIENT_HEADER(SMESH_Gen)
65 //=============================================================================
67 //=============================================================================
68 std::string RemoveTabulation( std::string theScript )
70 std::string::size_type aPos = 0;
71 while( aPos < theScript.length() )
73 aPos = theScript.find( "\n\t", aPos );
74 if( aPos == std::string::npos )
76 theScript.replace( aPos, 2, "\n" );
81 //=============================================================================
83 * standard constructor
85 //=============================================================================
86 HOMARD_Gen_i::HOMARD_Gen_i( CORBA::ORB_ptr orb,
87 PortableServer::POA_ptr poa,
88 PortableServer::ObjectId * contId,
89 const char *instanceName,
90 const char *interfaceName) :
91 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
93 MESSAGE("constructor");
95 _id = _poa->activate_object(_thisObj);
97 myHomard = new ::HOMARD_Gen();
98 _NS = SINGLETON_<SALOME_NamingService>::Instance();
99 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
107 _Langue = "Francais" ;
108 _LangueShort = "fr" ;
110 //=================================
112 * standard destructor
114 //================================
115 HOMARD_Gen_i::~HOMARD_Gen_i()
118 //=============================================================================
119 //=============================================================================
120 // Utilitaires pour l'étude
121 //=============================================================================
122 //=============================================================================
123 void HOMARD_Gen_i::addInStudy(SALOMEDS::Study_ptr theStudy)
125 ASSERT(!CORBA::is_nil(theStudy));
126 MESSAGE("addInStudy: ajout eventuel du composant HOMARD dans current study ID = " << GetCurrentStudyID()) ;
127 SALOMEDS::StudyBuilder_var myBuilder = theStudy->NewBuilder();
129 // Create SComponent labelled 'homard' if it doesn't already exit
130 SALOMEDS::SComponent_var homardFather = theStudy->FindComponent(ComponentDataType());
131 if (CORBA::is_nil(homardFather))
133 myBuilder->NewCommand();
134 MESSAGE("Add Component HOMARD");
136 bool aLocked = theStudy->GetProperties()->IsLocked();
137 if (aLocked) theStudy->GetProperties()->SetLocked(false);
139 homardFather = myBuilder->NewComponent(ComponentDataType());
140 SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
141 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
142 CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
143 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
144 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
145 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
146 if (!Comp->_is_nil())
148 aName->SetValue(ComponentDataType());
151 anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributePixMap");
152 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
153 aPixmap->SetPixMap("HOMARD_2.png");
154 myBuilder->DefineComponentInstance(homardFather, HOMARD_Gen::_this());
156 if (aLocked) theStudy->GetProperties()->SetLocked(true);
157 myBuilder->CommitCommand();
160 //=============================================================================
161 void HOMARD_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy)
163 MESSAGE("SetCurrentStudy: current study Id = " << GetCurrentStudyID());
164 myCurrentStudy = SALOMEDS::Study::_duplicate(theStudy);
165 this->addInStudy(myCurrentStudy);
167 //=============================================================================
168 SALOMEDS::Study_ptr HOMARD_Gen_i::GetCurrentStudy()
169 //=============================================================================
171 MESSAGE("GetCurrentStudy: study Id = " << GetCurrentStudyID());
172 return SALOMEDS::Study::_duplicate(myCurrentStudy);
174 //=============================================================================
175 CORBA::Long HOMARD_Gen_i::GetCurrentStudyID()
176 //=============================================================================
178 return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId();
180 //=============================================================================
181 //=============================================================================
183 //=============================================================================
184 //=============================================================================
185 // Utilitaires pour l'iteration
186 //=============================================================================
187 //=============================================================================
188 void HOMARD_Gen_i::SetEtatIter(const char* nomIter, const CORBA::Long Etat)
189 //=====================================================================================
191 MESSAGE( "SetEtatIter : affectation de l'etat " << Etat << " a l'iteration " << nomIter );
192 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
193 if (CORBA::is_nil(myIteration))
195 SALOME::ExceptionStruct es;
196 es.type = SALOME::BAD_PARAM;
197 es.text = "Invalid iteration";
198 throw SALOME::SALOME_Exception(es);
202 myIteration->SetState(Etat);
204 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
205 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
209 icone = "iter0.png" ;
210 else if ( Etat == 2 )
211 icone = "iter_calculee.png" ;
213 icone = "iter_non_calculee.png" ;
214 PublishInStudyAttr(aStudyBuilder, aIterSO, NULL , NULL, icone.c_str(), NULL) ;
216 aStudyBuilder->CommitCommand();
219 //=============================================================================
220 //=============================================================================
222 //=============================================================================
223 //=============================================================================
224 // Destruction des structures identifiees par leurs noms
225 //=============================================================================
226 //=============================================================================
227 CORBA::Long HOMARD_Gen_i::DeleteBoundary(const char* BoundaryName)
229 MESSAGE ( "DeleteBoundary : BoundaryName = " << BoundaryName );
230 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
231 if (CORBA::is_nil(myBoundary))
233 SALOME::ExceptionStruct es;
234 es.type = SALOME::BAD_PARAM;
235 es.text = "Invalid boundary";
236 throw SALOME::SALOME_Exception(es);
240 // On verifie que la frontiere n'est plus utilisee
241 HOMARD::listeCases* maListe = GetAllCasesName();
242 int numberOfCases = maListe->length();
243 MESSAGE ( ".. Nombre de cas = " << numberOfCases );
244 std::string CaseName ;
245 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType ;
247 HOMARD::HOMARD_Cas_var myCase ;
248 for (int NumeCas = 0; NumeCas< numberOfCases; NumeCas++)
250 CaseName = std::string((*maListe)[NumeCas]);
251 MESSAGE ( "... Examen du cas = " << CaseName.c_str() );
252 myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
253 ASSERT(!CORBA::is_nil(myCase));
254 ListBoundaryGroupType = myCase->GetBoundaryGroup();
255 numberOfitems = ListBoundaryGroupType->length();
256 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
257 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
259 if ( std::string((*ListBoundaryGroupType)[NumBoundary]) == BoundaryName )
261 SALOME::ExceptionStruct es;
262 es.type = SALOME::BAD_PARAM;
263 es.text = "This boundary is used in a case and cannot be deleted.";
264 throw SALOME::SALOME_Exception(es);
270 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
271 myContextMap[GetCurrentStudyID()]._mesBoundarys.erase(BoundaryName);
272 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(BoundaryName, ComponentDataType());
273 SALOMEDS::SObject_var aSO =listSO[0];
274 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
275 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
279 //=============================================================================
280 CORBA::Long HOMARD_Gen_i::DeleteCase(const char* nomCas, CORBA::Long Option)
282 // Pour detruire un cas
283 MESSAGE ( "DeleteCase : nomCas = " << nomCas << ", avec option = " << Option );
284 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
285 if (CORBA::is_nil(myCase))
287 SALOME::ExceptionStruct es;
288 es.type = SALOME::BAD_PARAM;
289 es.text = "Invalid case context";
290 throw SALOME::SALOME_Exception(es);
293 // On commence par detruire toutes les iterations en partant de l'initiale et y compris elle
294 CORBA::String_var nomIter = myCase->GetIter0Name();
295 CORBA::Long Option1 = 0 ;
296 if ( DeleteIterationOption(nomIter, Option1, Option) != 0 )
301 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
302 myContextMap[GetCurrentStudyID()]._mesCas.erase(nomCas);
303 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomCas, ComponentDataType());
304 SALOMEDS::SObject_var aSO =listSO[0];
305 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
306 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
310 //=============================================================================
311 CORBA::Long HOMARD_Gen_i::DeleteHypo(const char* nomHypo)
313 MESSAGE ( "DeleteHypo : nomHypo = " << nomHypo );
314 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
315 if (CORBA::is_nil(myHypo))
317 SALOME::ExceptionStruct es;
318 es.type = SALOME::BAD_PARAM;
319 es.text = "Invalid hypothesis";
320 throw SALOME::SALOME_Exception(es);
324 // On verifie que l'hypothese n'est plus utilisee
325 HOMARD::listeIters* maListeIter = myHypo->GetIterations();
326 int numberOfIter = maListeIter->length();
327 if ( numberOfIter > 0 )
329 SALOME::ExceptionStruct es;
330 es.type = SALOME::BAD_PARAM;
331 es.text = "This hypothesis is used in an iteration and cannot be deleted.";
332 throw SALOME::SALOME_Exception(es);
336 // suppression du lien avec les zones eventuelles
337 HOMARD::listeZonesHypo* maListe = myHypo->GetZones();
338 int numberOfZones = maListe->length();
339 MESSAGE ( ".. Nombre de zones = " << numberOfZones );
340 for (int NumeZone = 0; NumeZone< numberOfZones; NumeZone++)
342 std::string ZoneName = std::string((*maListe)[NumeZone]);
343 MESSAGE ( ".. suppression du lien avec la zone = " << ZoneName.c_str() );
344 DissociateHypoZone(nomHypo, ZoneName.c_str()) ;
348 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
349 myContextMap[GetCurrentStudyID()]._mesHypotheses.erase(nomHypo);
350 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomHypo, ComponentDataType());
351 SALOMEDS::SObject_var aSO =listSO[0];
352 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
353 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
357 //=============================================================================
358 CORBA::Long HOMARD_Gen_i::DeleteIteration(const char* nomIter, CORBA::Long Option)
360 // Option = 0 : On ne supprime pas le fichier du maillage associe
361 // Option = 1 : On supprime le fichier du maillage associe
362 // Pour detruire une iteration courante
363 MESSAGE ( "DeleteIteration : nomIter = " << nomIter << ", avec option = " << Option );
364 CORBA::Long Option1 = 1 ;
365 return DeleteIterationOption(nomIter, Option1, Option);
367 //=============================================================================
368 CORBA::Long HOMARD_Gen_i::DeleteIterationOption(const char* nomIter, CORBA::Long Option1, CORBA::Long Option2)
370 // Option1 = 0 : On autorise la destruction de l'iteration 0
371 // Option1 = 1 : On interdit la destruction de l'iteration 0
373 // Option2 = 0 : On ne supprime pas le fichier du maillage associe
374 // Option2 = 1 : On supprime le fichier du maillage associe
375 MESSAGE ( "DeleteIterationOption : nomIter = " << nomIter << ", avec options = " << Option1<< ", " << Option2 );
376 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
377 if (CORBA::is_nil(myIteration))
379 SALOME::ExceptionStruct es;
380 es.type = SALOME::BAD_PARAM;
381 es.text = "Invalid iteration";
382 throw SALOME::SALOME_Exception(es);
386 int numero = myIteration->GetNumber();
387 MESSAGE ( "DeleteIterationOption : numero = " << numero );
388 if ( numero == 0 && Option1 == 1 )
390 SALOME::ExceptionStruct es;
391 es.type = SALOME::BAD_PARAM;
392 es.text = "This iteration cannot be deleted.";
393 throw SALOME::SALOME_Exception(es);
397 // On detruit recursivement toutes les filles
398 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
399 int numberOfIter = maListe->length();
400 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
402 std::string nomIterFille = std::string((*maListe)[NumeIter]);
403 MESSAGE ( ".. appel recursif de DeleteIterationOption pour nomIter = " << nomIterFille.c_str() );
404 DeleteIterationOption(nomIterFille.c_str(), Option1, Option2);
407 // On arrive ici pour une iteration sans fille
408 MESSAGE ( "Destruction effective de " << nomIter );
409 // On commence par invalider l'iteration pour faire le menage des dependances
410 // et eventuellement du maillage associe
412 if ( numero == 0 ) { option = 0 ; }
413 else { option = Option2 ; }
414 InvalideIterOption(nomIter, option) ;
416 // Retrait dans la descendance de l'iteration parent
419 std::string nomIterationParent = myIteration->GetIterParentName();
420 MESSAGE ( "Retrait dans la descendance de nomIterationParent " << nomIterationParent );
421 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
422 if (CORBA::is_nil(myIterationParent))
424 SALOME::ExceptionStruct es;
425 es.type = SALOME::BAD_PARAM;
426 es.text = "Invalid iteration";
427 throw SALOME::SALOME_Exception(es);
430 myIterationParent->UnLinkNextIteration(nomIter);
433 // suppression du lien avec l'hypothese
436 std::string nomHypo = myIteration->GetHypoName();
437 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
438 ASSERT(!CORBA::is_nil(myHypo));
439 myHypo->UnLinkIteration(nomIter);
442 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
443 myContextMap[GetCurrentStudyID()]._mesIterations.erase(nomIter);
444 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomIter, ComponentDataType());
445 SALOMEDS::SObject_var aSO =listSO[0];
446 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
447 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
448 // on peut aussi faire RemoveObject
449 // MESSAGE ( "Au final" );
450 // HOMARD::listeIterations* Liste = GetAllIterationsName() ;
451 // numberOfIter = Liste->length();
452 // for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
454 // std::string nomIterFille = std::string((*Liste)[NumeIter]);
455 // MESSAGE ( ".. nomIter = " << nomIterFille.c_str() );
460 //=============================================================================
461 CORBA::Long HOMARD_Gen_i::DeleteYACS(const char* nomYACS, CORBA::Long Option)
463 // Option = 0 : On ne supprime pas le fichier du schema associe
464 // Option = 1 : On supprime le fichier du schema associe
465 MESSAGE ( "DeleteYACS : nomYACS = " << nomYACS << ", avec option = " << Option );
466 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
467 if (CORBA::is_nil(myYACS))
469 SALOME::ExceptionStruct es;
470 es.type = SALOME::BAD_PARAM;
471 es.text = "Invalid schema YACS";
472 throw SALOME::SALOME_Exception(es);
475 // Suppression eventuelle du fichier XML
478 std::string nomFichier = myYACS->GetXMLFile();
479 std::string commande = "rm -rf " + nomFichier ;
480 MESSAGE ( "commande = " << commande );
481 if ((system(commande.c_str())) != 0)
483 SALOME::ExceptionStruct es;
484 es.type = SALOME::BAD_PARAM;
485 es.text = "The xml file for the schema YACS cannot be removed." ;
486 throw SALOME::SALOME_Exception(es);
490 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
491 myContextMap[GetCurrentStudyID()]._mesYACSs.erase(nomYACS);
492 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomYACS, ComponentDataType());
493 SALOMEDS::SObject_var aSO =listSO[0];
494 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
495 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
499 //=============================================================================
500 CORBA::Long HOMARD_Gen_i::DeleteZone(const char* nomZone)
502 MESSAGE ( "DeleteZone : nomZone = " << nomZone );
503 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[nomZone];
504 if (CORBA::is_nil(myZone))
506 SALOME::ExceptionStruct es;
507 es.type = SALOME::BAD_PARAM;
508 es.text = "Invalid zone";
509 throw SALOME::SALOME_Exception(es);
513 // On verifie que la zone n'est plus utilisee
514 HOMARD::listeHypo* maListe = myZone->GetHypo();
515 int numberOfHypo = maListe->length();
516 MESSAGE ( ".. Nombre d'hypotheses = " << numberOfHypo );
517 if ( numberOfHypo > 0 )
519 SALOME::ExceptionStruct es;
520 es.type = SALOME::BAD_PARAM;
521 es.text = "This zone is used in an hypothesis and cannot be deleted.";
522 throw SALOME::SALOME_Exception(es);
526 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
527 myContextMap[GetCurrentStudyID()]._mesZones.erase(nomZone);
528 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomZone, ComponentDataType());
529 SALOMEDS::SObject_var aSO =listSO[0];
530 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
531 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
535 //=============================================================================
536 //=============================================================================
538 //=============================================================================
539 //=============================================================================
540 // Invalidation des structures identifiees par leurs noms
541 //=============================================================================
542 //=============================================================================
543 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
545 MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName );
546 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
547 if (CORBA::is_nil(myBoundary))
549 SALOME::ExceptionStruct es;
550 es.type = SALOME::BAD_PARAM;
551 es.text = "Invalid boundary";
552 throw SALOME::SALOME_Exception(es);
557 SALOME::ExceptionStruct es;
558 es.type = SALOME::BAD_PARAM;
559 es.text = "No change is allowed in a boundary. Ask for evolution.";
560 throw SALOME::SALOME_Exception(es);
564 //=============================================================================
565 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
567 MESSAGE( "InvalideHypo : nomHypo = " << nomHypo );
568 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
569 if (CORBA::is_nil(myHypo))
571 SALOME::ExceptionStruct es;
572 es.type = SALOME::BAD_PARAM;
573 es.text = "Invalid hypothesis";
574 throw SALOME::SALOME_Exception(es);
578 HOMARD::listeIters* maListe = myHypo->GetIterations();
579 int numberOfIter = maListe->length();
580 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
582 std::string nomIter = std::string((*maListe)[NumeIter]);
583 MESSAGE( ".. nomIter = " << nomIter );
584 InvalideIter(nomIter.c_str());
587 //=============================================================================
588 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
590 MESSAGE("InvalideIter : nomIter = " << nomIter);
591 // Pour invalider totalement une iteration courante
592 CORBA::Long Option = 1 ;
593 return InvalideIterOption(nomIter, Option);
595 //=============================================================================
596 void HOMARD_Gen_i::InvalideIterOption(const char* nomIter, CORBA::Long Option)
598 // Option = 0 : On ne supprime pas le fichier du maillage associe
599 // Option = 1 : On supprime le fichier du maillage associe
600 MESSAGE ( "InvalideIterOption : nomIter = " << nomIter << ", avec option = " << Option );
601 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
602 if (CORBA::is_nil(myIteration))
604 SALOME::ExceptionStruct es;
605 es.type = SALOME::BAD_PARAM;
606 es.text = "Invalid iteration";
607 throw SALOME::SALOME_Exception(es);
611 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
612 int numberOfIter = maListe->length();
613 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
615 std::string nomIterFille = std::string((*maListe)[NumeIter]);
616 MESSAGE ( ".. appel recursif de InvalideIter pour nomIter = " << nomIterFille.c_str() );
617 InvalideIter(nomIterFille.c_str());
620 // On arrive ici pour une iteration sans fille
621 MESSAGE ( "Invalidation effective de " << nomIter );
622 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
623 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
624 for (; aIter->More(); aIter->Next())
626 SALOMEDS::SObject_var so = aIter->Value();
627 SALOMEDS::GenericAttribute_var anAttr;
628 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
629 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
630 std::string value (aCommentAttr->Value());
631 if(value == std::string("HypoHomard")) continue;
632 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
633 aStudyBuilder->RemoveObject(so);
636 int etat = myIteration->GetState();
639 SetEtatIter(nomIter,1);
640 const char * nomCas = myIteration->GetCaseName();
641 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
642 if (CORBA::is_nil(myCase))
644 SALOME::ExceptionStruct es;
645 es.type = SALOME::BAD_PARAM;
646 es.text = "Invalid case context";
647 throw SALOME::SALOME_Exception(es);
650 std::string nomDir = myIteration->GetDirName();
651 std::string nomFichier = myIteration->GetMeshFile();
652 std::string commande = "rm -rf " + std::string(nomDir);
653 if ( Option == 1 ) { commande = commande + ";rm -rf " + std::string(nomFichier) ; }
654 MESSAGE ( "commande = " << commande );
655 if ((system(commande.c_str())) != 0)
657 SALOME::ExceptionStruct es;
658 es.type = SALOME::BAD_PARAM;
659 es.text = "The directory for the calculation cannot be cleared." ;
660 throw SALOME::SALOME_Exception(es);
663 // Suppression du maillage publie dans SMESH
664 std::string MeshName = myIteration->GetMeshName() ;
665 DeleteResultInSmesh(nomFichier, MeshName) ;
669 //=============================================================================
670 void HOMARD_Gen_i::InvalideIterInfo(const char* nomIter)
672 MESSAGE("InvalideIterInfo : nomIter = " << nomIter);
673 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
674 if (CORBA::is_nil(myIteration))
676 SALOME::ExceptionStruct es;
677 es.type = SALOME::BAD_PARAM;
678 es.text = "Invalid iteration";
679 throw SALOME::SALOME_Exception(es);
683 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
684 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
685 for (; aIter->More(); aIter->Next())
687 SALOMEDS::SObject_var so = aIter->Value();
688 SALOMEDS::GenericAttribute_var anAttr;
689 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
690 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
691 std::string value (aCommentAttr->Value());
692 /* MESSAGE("... value = " << value);*/
693 if( (value == std::string("logInfo")) || ( value == std::string("SummaryInfo")) )
695 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
696 aStudyBuilder->RemoveObject(so);
700 const char * nomCas = myIteration->GetCaseName();
701 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
702 if (CORBA::is_nil(myCase))
704 SALOME::ExceptionStruct es;
705 es.type = SALOME::BAD_PARAM;
706 es.text = "Invalid case context";
707 throw SALOME::SALOME_Exception(es);
710 const char* nomDir = myIteration->GetDirName();
711 std::string commande = "rm -f " + std::string(nomDir) + "/info* " ;
712 commande += std::string(nomDir) + "/Liste.*info" ;
713 /* MESSAGE ( "commande = " << commande );*/
714 if ((system(commande.c_str())) != 0)
716 SALOME::ExceptionStruct es;
717 es.type = SALOME::BAD_PARAM;
718 es.text = "The directory for the calculation cannot be cleared." ;
719 throw SALOME::SALOME_Exception(es);
723 //=============================================================================
724 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
726 MESSAGE( "InvalideZone : ZoneName = " << ZoneName );
727 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
728 if (CORBA::is_nil(myZone))
730 SALOME::ExceptionStruct es;
731 es.type = SALOME::BAD_PARAM;
732 es.text = "Invalid zone";
733 throw SALOME::SALOME_Exception(es);
736 HOMARD::listeHypo* maListe = myZone->GetHypo();
737 int numberOfHypo = maListe->length();
738 MESSAGE( ".. numberOfHypo = " << numberOfHypo );
739 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
741 std::string nomHypo = std::string((*maListe)[NumeHypo]);
742 MESSAGE( ".. nomHypo = " << nomHypo );
743 InvalideHypo(nomHypo.c_str());
746 //=============================================================================
747 //=============================================================================
749 //=============================================================================
750 //=============================================================================
751 // Association de lien entre des structures identifiees par leurs noms
752 //=============================================================================
753 //=============================================================================
754 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
756 MESSAGE( "AssociateCaseIter : " << nomCas << ", " << nomIter << ", " << labelIter );
758 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
759 if (CORBA::is_nil(myCase))
761 SALOME::ExceptionStruct es;
762 es.type = SALOME::BAD_PARAM;
763 es.text = "Invalid case";
764 throw SALOME::SALOME_Exception(es);
768 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
769 if (CORBA::is_nil(myIteration))
771 SALOME::ExceptionStruct es;
772 es.type = SALOME::BAD_PARAM;
773 es.text = "Invalid iteration";
774 throw SALOME::SALOME_Exception(es);
778 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
779 SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
780 if (CORBA::is_nil(aCasSO))
782 SALOME::ExceptionStruct es;
783 es.type = SALOME::BAD_PARAM;
784 es.text = "Invalid case";
785 throw SALOME::SALOME_Exception(es);
789 aStudyBuilder->NewCommand();
790 SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
791 PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
792 "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
793 aStudyBuilder->CommitCommand();
795 myCase->AddIteration(nomIter);
796 myIteration->SetCaseName(nomCas);
798 //=====================================================================================
799 void HOMARD_Gen_i::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
801 MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
803 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
804 ASSERT(!CORBA::is_nil(myHypo));
805 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
806 ASSERT(!CORBA::is_nil(aHypoSO));
808 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
809 ASSERT(!CORBA::is_nil(myZone));
810 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
811 ASSERT(!CORBA::is_nil(aZoneSO));
813 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
815 aStudyBuilder->NewCommand();
817 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
818 aStudyBuilder->Addreference(aSubSO, aZoneSO);
820 aStudyBuilder->CommitCommand();
822 myZone->AddHypo(nomHypothesis);
823 myHypo->AddZone0(ZoneName, TypeUse);
825 //=============================================================================
826 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
828 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
830 // Verification de l'existence de l'hypothese
831 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
832 ASSERT(!CORBA::is_nil(myHypo));
833 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
834 ASSERT(!CORBA::is_nil(aHypoSO));
836 // Verification de l'existence de l'iteration
837 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
838 ASSERT(!CORBA::is_nil(myIteration));
839 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
840 ASSERT(!CORBA::is_nil(aIterSO));
842 // Gestion de l'etude
843 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
845 aStudyBuilder->NewCommand();
847 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
848 aStudyBuilder->Addreference(aSubSO, aHypoSO);
850 aStudyBuilder->CommitCommand();
853 myIteration->SetHypoName(nomHypo);
854 myHypo->LinkIteration(nomIter);
856 // On stocke les noms des champ a interpoler pour le futur controle de la donnee des pas de temps
857 myIteration->SupprFieldInterps() ;
858 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
859 int numberOfFieldsx2 = ListField->length();
860 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
862 std::string FieldName = std::string((*ListField)[iaux]) ;
863 myIteration->SetFieldInterp(FieldName.c_str()) ;
867 //=============================================================================
868 //=============================================================================
870 //=============================================================================
871 //=============================================================================
872 // Dissociation de lien entre des structures identifiees par leurs noms
873 //=============================================================================
874 //=============================================================================
875 void HOMARD_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
877 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
879 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
880 ASSERT(!CORBA::is_nil(myHypo));
881 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
882 ASSERT(!CORBA::is_nil(aHypoSO));
884 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
885 ASSERT(!CORBA::is_nil(myZone));
886 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
887 ASSERT(!CORBA::is_nil(aZoneSO));
889 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
891 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator(aHypoSO);
892 for (; it->More(); it->Next())
894 SALOMEDS::SObject_var aHypObj = it->Value();
895 SALOMEDS::SObject_var ptrObj;
896 if (aHypObj->ReferencedObject(ptrObj))
898 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
900 aStudyBuilder->NewCommand();
901 aStudyBuilder->RemoveObject(aHypObj);
902 aStudyBuilder->CommitCommand();
908 myZone->SupprHypo(nomHypothesis);
909 myHypo->SupprZone(ZoneName);
911 //=============================================================================
912 //=============================================================================
915 //=============================================================================
916 //=============================================================================
917 // Recuperation des listes
918 //=============================================================================
919 //=============================================================================
920 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
922 MESSAGE("GetAllBoundarysName");
925 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
926 ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
927 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
929 for (it = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
930 it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
932 ret[i++] = CORBA::string_dup((*it).first.c_str());
937 //=============================================================================
938 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
940 MESSAGE("GetAllCasesName");
943 HOMARD::listeCases_var ret = new HOMARD::listeCases;
944 ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
945 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
947 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
948 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
950 ret[i++] = CORBA::string_dup((*it).first.c_str());
955 //=============================================================================
956 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
958 MESSAGE("GetAllHypothesesName");
961 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
962 ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
963 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
965 for (it = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
966 it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
968 ret[i++] = CORBA::string_dup((*it).first.c_str());
973 //=============================================================================
974 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
976 MESSAGE("GetAllIterationsName");
979 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
980 ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
981 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
983 for (it = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
984 it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
986 ret[i++] = CORBA::string_dup((*it).first.c_str());
991 //=============================================================================
992 HOMARD::listeYACSs* HOMARD_Gen_i::GetAllYACSsName()
994 MESSAGE("GetAllYACSsName");
997 HOMARD::listeYACSs_var ret = new HOMARD::listeYACSs;
998 ret->length(myContextMap[GetCurrentStudyID()]._mesYACSs.size());
999 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it;
1001 for (it = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
1002 it != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); it++)
1004 ret[i++] = CORBA::string_dup((*it).first.c_str());
1009 //=============================================================================
1010 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
1012 MESSAGE("GetAllZonesName");
1015 HOMARD::listeZones_var ret = new HOMARD::listeZones;
1016 ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
1017 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
1019 for (it = myContextMap[GetCurrentStudyID()]._mesZones.begin();
1020 it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
1022 ret[i++] = CORBA::string_dup((*it).first.c_str());
1027 //=============================================================================
1028 //=============================================================================
1030 //=============================================================================
1031 //=============================================================================
1032 // Recuperation des structures identifiees par leurs noms
1033 //=============================================================================
1034 //=============================================================================
1035 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
1037 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
1038 ASSERT(!CORBA::is_nil(myBoundary));
1039 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1041 //=============================================================================
1042 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
1044 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1045 ASSERT(!CORBA::is_nil(myCase));
1046 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1048 //=============================================================================
1049 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
1051 HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
1052 ASSERT(!CORBA::is_nil(myHypothesis));
1053 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1055 //=============================================================================
1056 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* NomIterationation)
1058 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIterationation];
1059 ASSERT(!CORBA::is_nil(myIteration));
1060 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1062 //=============================================================================
1063 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::GetYACS(const char* nomYACS)
1065 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
1066 ASSERT(!CORBA::is_nil(myYACS));
1067 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
1069 //=============================================================================
1070 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
1072 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1073 ASSERT(!CORBA::is_nil(myZone));
1074 return HOMARD::HOMARD_Zone::_duplicate(myZone);
1076 //=============================================================================
1077 //=============================================================================
1079 //=============================================================================
1080 //=============================================================================
1082 //=============================================================================
1083 //=============================================================================
1084 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)
1086 INFOS ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1087 INFOS ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte );
1091 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, 0, 1) ;
1092 myCase->SetDirName(DirName) ;
1094 myCase->MeshInfo(Qual, Diam, Conn, Tail, Inte) ;
1098 //=============================================================================
1099 //=============================================================================
1101 //=============================================================================
1102 //=============================================================================
1103 // Recuperation des structures par le contexte
1104 //=============================================================================
1105 //=============================================================================
1106 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::LastIteration(const char* nomCas)
1108 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1109 ASSERT(!CORBA::is_nil(myCase));
1111 HOMARD::HOMARD_Iteration_var myIteration = myCase->LastIteration();
1112 ASSERT(!CORBA::is_nil(myIteration));
1114 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1116 //=============================================================================
1117 //=============================================================================
1119 //=============================================================================
1120 //=============================================================================
1121 // Nouvelles structures
1122 //=============================================================================
1123 //=============================================================================
1124 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1126 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1127 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
1128 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
1129 return aCase._retn();
1131 //=============================================================================
1132 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
1134 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1135 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
1136 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
1137 return aHypo._retn();
1139 //=============================================================================
1140 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
1142 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1143 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
1144 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
1145 return aIter._retn();
1147 //=============================================================================
1148 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1150 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1151 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
1152 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1153 return aBoundary._retn();
1155 //=============================================================================
1156 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
1158 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1159 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
1160 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
1161 return aZone._retn();
1163 //=============================================================================
1164 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::newYACS()
1166 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1167 HOMARD_YACS_i* aServant = new HOMARD_YACS_i(_orb, engine);
1168 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(aServant->_this());
1169 return aYACS._retn();
1171 //=============================================================================
1172 //=============================================================================
1174 //=============================================================================
1175 //=============================================================================
1176 // Creation des structures identifiees par leurs noms
1177 //=============================================================================
1178 //=============================================================================
1179 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
1181 // Creation d'un cas initial
1182 // nomCas : nom du cas a creer
1183 // MeshName, MeshFile : nom et fichier du maillage correspondant
1186 INFOS ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1188 // Par defaut, on ne publie pas le maillage
1189 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 0, 0, 1) ;
1191 // Valeurs par defaut des filtrages
1192 myCase->SetPyram(0);
1194 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1196 //=============================================================================
1197 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromIteration(const char* nomCas, const char* DirNameStart)
1199 // nomCas : nom du cas a creer
1200 // DirNameStart : nom du repertoire contenant l'iteration de reprise
1203 INFOS ( "CreateCaseFromIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1204 std::string nomDirWork = getenv("PWD") ;
1207 // A. Decodage du point de reprise
1208 // A.1. Controle du repertoire de depart de l'iteration
1210 codret = chdir(DirNameStart) ;
1212 codret = _chdir(DirNameStart) ;
1216 SALOME::ExceptionStruct es;
1217 es.type = SALOME::BAD_PARAM;
1218 es.text = "The directory of the iteration does not exist.";
1219 throw SALOME::SALOME_Exception(es);
1222 // A.2. Reperage des fichiers du repertoire de reprise
1223 std::string file_configuration = "" ;
1224 std::string file_maillage_homard = "" ;
1228 struct dirent *dirp;
1229 dp = opendir(DirNameStart);
1230 while ( (dirp = readdir(dp)) != NULL )
1232 std::string file_name(dirp->d_name);
1233 // MESSAGE ( file_name );
1234 bilan = file_name.find("HOMARD.Configuration.") ;
1235 if ( bilan != string::npos ) { file_configuration = file_name ; }
1236 bilan = file_name.find("maill.") ;
1237 if ( bilan != string::npos )
1239 bilan = file_name.find(".hom.med") ;
1240 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1245 HANDLE hFind = INVALID_HANDLE_VALUE;
1246 WIN32_FIND_DATA ffd;
1247 hFind = FindFirstFile(DirNameStart, &ffd);
1248 if (INVALID_HANDLE_VALUE != hFind) {
1249 while (FindNextFile(hFind, &ffd) != 0) {
1250 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1251 std::string file_name(ffd.cFileName);
1252 bilan = file_name.find("HOMARD.Configuration.") ;
1253 if ( bilan != string::npos ) { file_configuration = file_name ; }
1254 bilan = file_name.find("maill.") ;
1255 if ( bilan != string::npos )
1257 bilan = file_name.find(".hom.med") ;
1258 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1264 MESSAGE ( "==> file_configuration : " << file_configuration ) ;
1265 MESSAGE ( "==> file_maillage_homard : " << file_maillage_homard ) ;
1267 if ( ( file_configuration == "" ) || ( file_maillage_homard == "" ) )
1269 SALOME::ExceptionStruct es;
1270 es.type = SALOME::BAD_PARAM;
1272 if ( file_configuration == "" ) { text = "The configuration file cannot be found." ; }
1273 else { text = "The HOMARD mesh file cannot be found." ; }
1274 es.text = CORBA::string_dup(text.c_str());
1275 throw SALOME::SALOME_Exception(es);
1278 // B. Lecture du fichier de configuration
1279 // ATTENTION : on doit veiller a la coherence entre HomardDriver et CreateCaseFromIteration
1285 // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1286 std::ifstream fichier( file_configuration.c_str() );
1287 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1289 std::string ligne; // variable contenant chaque ligne lue
1290 std::string mot_cle;
1291 std::string argument;
1293 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1294 while ( std::getline( fichier, ligne ) )
1296 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1297 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1298 ligne_bis >> mot_cle ;
1299 // B.2. Des valeurs entieres : le second bloc de la ligne
1300 if ( mot_cle == "NumeIter" )
1302 ligne_bis >> NumeIter ;
1305 // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1306 else if ( ( mot_cle == "TypeConf" ) || ( mot_cle == "TypeElem" ) )
1308 ligne_bis >> argument ;
1310 if ( mot_cle == "TypeConf" )
1312 if ( argument == "conforme" ) { TypeConf = 1 ; }
1313 else if ( argument == "non_conforme_1_noeud" ) { TypeConf = 2 ; }
1314 else if ( argument == "non_conforme_1_arete" ) { TypeConf = 3 ; }
1315 else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1317 else if ( mot_cle == "TypeElem" )
1319 if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1320 else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1323 // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1324 // il faut les supprimer
1325 else if ( ( mot_cle == "CCNoMNP1" ) || ( mot_cle == "CCMaiNP1" ) )
1327 ligne_bis >> argument ;
1328 if ( argument[0] == '"' ) { decalage = 1 ; }
1329 else { decalage = 0 ; }
1330 size_t size = argument.size() + 1 - 2*decalage ;
1332 if ( mot_cle == "CCNoMNP1" )
1334 MeshName = new char[ size ];
1335 strncpy( MeshName, argument.c_str()+decalage, size );
1336 MeshName[size-1] = '\0' ;
1338 else if ( mot_cle == "CCMaiNP1" )
1340 MeshFile = new char[ size ];
1341 strncpy( MeshFile, argument.c_str()+decalage, size );
1342 MeshFile[size-1] = '\0' ;
1346 MESSAGE ( "==> TypeConf : " << TypeConf ) ;
1347 MESSAGE ( "==> MeshName : " << MeshName ) ;
1348 MESSAGE ( "==> MeshFile : " << MeshFile ) ;
1349 MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1350 MESSAGE ( "==> Pyram : " << Pyram ) ;
1354 SALOME::ExceptionStruct es;
1355 es.type = SALOME::BAD_PARAM;
1356 std::string text = "The configuration file cannot be read." ;
1357 es.text = CORBA::string_dup(text.c_str());
1358 throw SALOME::SALOME_Exception(es);
1361 // C. Creation effective du cas
1363 // Par defaut, on ne publie pas le maillage
1364 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, 1) ;
1366 // D. Parametrages lus dans le fichier de configuration
1368 myCase->SetConfType (TypeConf) ;
1369 myCase->SetPyram (Pyram) ;
1371 // E. Copie du fichier de maillage homard
1372 // E.1. Repertoire associe au cas
1373 char* nomDirCase = myCase->GetDirName() ;
1374 // E.2. Repertoire associe a l'iteration de ce cas
1376 IterName = myCase->GetIter0Name() ;
1377 HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1378 char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1379 Iter->SetDirNameLoc(nomDirIter);
1380 std::string nomDirIterTotal ;
1381 nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1383 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1385 if (_mkdir(nomDirIterTotal.c_str()) != 0)
1388 MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1389 SALOME::ExceptionStruct es;
1390 es.type = SALOME::BAD_PARAM;
1391 std::string text = "The directory for the computation cannot be created." ;
1392 es.text = CORBA::string_dup(text.c_str());
1393 throw SALOME::SALOME_Exception(es);
1395 // E.3. Copie du maillage HOMARD au format MED
1397 codret = chdir(DirNameStart) ;
1399 codret = _chdir(DirNameStart) ;
1401 std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1402 MESSAGE ( "commande : " << commande ) ;
1403 codret = system(commande.c_str()) ;
1404 MESSAGE ( "codret : " << codret ) ;
1407 SALOME::ExceptionStruct es;
1408 es.type = SALOME::BAD_PARAM;
1409 es.text = "The starting point for the case cannot be copied into the working directory.";
1410 throw SALOME::SALOME_Exception(es);
1420 chdir(nomDirWork.c_str());
1422 _chdir(nomDirWork.c_str());
1424 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1426 //=============================================================================
1427 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1429 // nomCas : nom du cas a creer
1430 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1433 INFOS ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1435 std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1437 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1438 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1440 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1442 //=============================================================================
1443 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1445 // nomCas : nom du cas a creer
1446 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1447 // Number : numero de l'iteration de depart
1450 INFOS ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1453 SALOME::ExceptionStruct es;
1454 es.type = SALOME::BAD_PARAM;
1455 es.text = "The number of iteration must be positive.";
1456 throw SALOME::SALOME_Exception(es);
1460 std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1462 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1463 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1465 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1467 //=============================================================================
1468 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1470 // Retourne le nom du repertoire ou se trouve l'iteration voulue.
1471 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1472 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1475 MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1476 std::string nomDirWork = getenv("PWD") ;
1477 std::string DirNameStartIter ;
1479 int NumeIterMax = -1 ;
1481 // A.1. Controle du repertoire de depart du cas
1483 codret = chdir(DirNameStart) ;
1485 codret = _chdir(DirNameStart) ;
1489 SALOME::ExceptionStruct es;
1490 es.type = SALOME::BAD_PARAM;
1491 es.text = "The directory of the case for the pursuit does not exist.";
1492 throw SALOME::SALOME_Exception(es);
1495 // A.2. Reperage des sous-repertoire du repertoire de reprise
1496 bool existe = false ;
1499 struct dirent *dirp;
1500 dp = opendir(DirNameStart);
1501 while ( (dirp = readdir(dp)) != NULL ) {
1502 std::string DirName_1(dirp->d_name);
1504 HANDLE hFind = INVALID_HANDLE_VALUE;
1505 WIN32_FIND_DATA ffd;
1506 hFind = FindFirstFile(DirNameStart, &ffd);
1507 if (INVALID_HANDLE_VALUE != hFind) {
1508 while (FindNextFile(hFind, &ffd) != 0) {
1509 std::string DirName_1 = "";
1510 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1511 DirName_1 = std::string(ffd.cFileName);
1514 if ( ( DirName_1 != "." ) && ( DirName_1 != ".." ) )
1517 if ( chdir(DirName_1.c_str()) == 0 )
1519 // On cherche le fichier de configuration dans ce sous-repertoire
1520 codret = chdir(DirNameStart);
1522 struct dirent *dirp_1;
1523 dp_1 = opendir(DirName_1.c_str()) ;
1524 while ( (dirp_1 = readdir(dp_1)) != NULL )
1526 std::string file_name_1(dirp_1->d_name);
1528 if ( _chdir(DirName_1.c_str()) == 0 )
1530 codret = _chdir(DirNameStart);
1531 HANDLE hFind1 = INVALID_HANDLE_VALUE;
1532 WIN32_FIND_DATA ffd1;
1533 hFind1 = FindFirstFile(DirName_1.c_str(), &ffd1);
1534 while (FindNextFile(hFind1, &ffd1) != 0)
1536 if (ffd1.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1537 std::string file_name_1(ffd1.cFileName);
1539 int bilan = file_name_1.find("HOMARD.Configuration.") ;
1540 if ( bilan != string::npos )
1542 // Decodage du fichier pour trouver le numero d'iteration
1544 chdir(DirName_1.c_str()) ;
1546 _chdir(DirName_1.c_str()) ;
1549 std::ifstream fichier( file_name_1.c_str() );
1550 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1553 std::string ligne; // variable contenant chaque ligne lue
1554 std::string mot_cle;
1555 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1556 while ( std::getline( fichier, ligne ) )
1558 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1559 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1560 ligne_bis >> mot_cle ;
1561 if ( mot_cle == "NumeIter" )
1563 ligne_bis >> NumeIter ;
1565 // MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1566 if ( Number == - 1 )
1568 if ( NumeIter >= NumeIterMax )
1570 NumeIterMax = NumeIter ;
1571 DirNameStartIter = DirName_1 ;
1576 if ( NumeIter == Number )
1578 DirNameStartIter = DirName_1 ;
1588 SALOME::ExceptionStruct es;
1589 es.type = SALOME::BAD_PARAM;
1590 std::string text = "The configuration file cannot be read." ;
1591 es.text = CORBA::string_dup(text.c_str());
1592 throw SALOME::SALOME_Exception(es);
1595 chdir(DirNameStart) ;
1597 _chdir(DirNameStart) ;
1600 if ( existe ) { break ; }
1607 if ( existe ) { break ; }
1613 chdir(nomDirWork.c_str());
1617 _chdir(nomDirWork.c_str());
1620 if ( ( Number >= 0 && ( !existe ) ) || ( Number < 0 && ( NumeIterMax == -1 ) ) )
1622 SALOME::ExceptionStruct es;
1623 es.type = SALOME::BAD_PARAM;
1624 es.text = "The directory of the iteration does not exist.";
1625 throw SALOME::SALOME_Exception(es);
1629 return DirNameStartIter ;
1631 //=============================================================================
1632 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)
1634 // nomCas : nom du cas a creer
1635 // MeshName, MeshFile : nom et fichier du maillage correspondant
1636 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1637 // 1 : le maillage fourni peut ne pas exister ==> on continue si absent
1638 // -1 : le maillage n'est pas fourni
1639 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1640 // Option : multiple de nombres premiers
1641 // 1 : aucune option
1642 // x2 : publication du maillage dans SMESH
1644 MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1645 MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1646 MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1652 // A.2. Controle du nom :
1653 if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
1655 SALOME::ExceptionStruct es;
1656 es.type = SALOME::BAD_PARAM;
1657 es.text = "This case has already been defined.";
1658 throw SALOME::SALOME_Exception(es);
1662 // A.3. Controle du fichier du maillage
1663 int existeMeshFile ;
1664 if ( MeshOption >= 0 )
1666 existeMeshFile = MEDFileExist ( MeshFile ) ;
1667 MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1668 if ( ( existeMeshFile == 0 ) && ( MeshOption == 0 ) )
1670 SALOME::ExceptionStruct es;
1671 es.type = SALOME::BAD_PARAM;
1672 es.text = "The mesh file does not exist.";
1673 throw SALOME::SALOME_Exception(es);
1677 else { existeMeshFile = 0 ; }
1679 // B. Creation de l'objet cas et publication
1680 // MESSAGE ( "CreateCase0 : Creation de l'objet" );
1681 HOMARD::HOMARD_Cas_var myCase = newCase();
1682 myCase->SetName(nomCas);
1683 SALOMEDS::SObject_var aSO;
1684 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
1685 myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
1687 // C. Caracteristiques du maillage
1688 if ( existeMeshFile != 0 )
1690 // Les valeurs extremes des coordonnees
1691 // MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnees" );
1692 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1693 HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1694 if (LesExtremes.size()!=10) { return false; }
1696 for (int i =0 ; i< LesExtremes.size() ; i++)
1697 aSeq[i]=LesExtremes[i] ;
1698 myCase->SetBoundingBox(aSeq) ;
1700 // MESSAGE ( "CreateCase0 : Les groupes" );
1701 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile) ;
1702 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1703 aSeqGroupe->length(LesGroupes.size());
1704 std::set<std::string>::const_iterator it ;
1706 for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1707 aSeqGroupe[i++]=(*it).c_str() ;
1708 myCase->SetGroups(aSeqGroupe) ;
1711 // D. L'iteration initiale du cas
1712 MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1713 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1714 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1716 std::string NomIteration = std::string(MeshName) ;
1717 while ( (myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()) )
1719 std::ostringstream nom;
1720 nom << MeshName << monNum;
1721 NomIteration = nom.str();
1724 MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1726 // D.2. Creation de l'iteration
1727 HOMARD::HOMARD_Iteration_var anIter = newIteration();
1728 myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration] = anIter;
1729 anIter->SetName(NomIteration.c_str());
1730 AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1732 // D.4. Maillage correspondant
1733 if ( existeMeshFile != 0 )
1735 anIter->SetMeshFile(MeshFile);
1736 if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1738 anIter->SetMeshName(MeshName);
1740 // D.5. Numero d'iteration
1741 anIter->SetNumber(NumeIter);
1744 SetEtatIter(NomIteration.c_str(), -NumeIter);
1747 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1749 //=============================================================================
1750 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1752 INFOS ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1755 // A. Controle du nom :
1756 if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
1758 SALOME::ExceptionStruct es;
1759 es.type = SALOME::BAD_PARAM;
1760 es.text = "This hypothesis has already been defined.";
1761 throw SALOME::SALOME_Exception(es);
1765 // B. Creation de l'objet
1766 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1767 if (CORBA::is_nil(myHypothesis))
1769 SALOME::ExceptionStruct es;
1770 es.type = SALOME::BAD_PARAM;
1771 es.text = "Unable to create the hypothesis";
1772 throw SALOME::SALOME_Exception(es);
1775 myHypothesis->SetName(nomHypothesis);
1777 // C. Enregistrement
1778 myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
1780 SALOMEDS::SObject_var aSO;
1781 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
1783 // D. Valeurs par defaut des options avancees
1784 myHypothesis->SetNivMax(-1);
1785 myHypothesis->SetDiamMin(-1.0);
1786 myHypothesis->SetAdapInit(0);
1787 myHypothesis->SetLevelOutput(0);
1789 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1792 //=============================================================================
1793 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1794 //=============================================================================
1796 INFOS ("CreateIteration : NomIteration = " << NomIteration << ", nomIterParent = " << nomIterParent);
1799 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
1800 if (CORBA::is_nil(myIterationParent))
1802 SALOME::ExceptionStruct es;
1803 es.type = SALOME::BAD_PARAM;
1804 es.text = "The parent iteration is not defined.";
1805 throw SALOME::SALOME_Exception(es);
1809 const char* nomCas = myIterationParent->GetCaseName();
1810 MESSAGE ("CreateIteration : nomCas = " << nomCas);
1811 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1812 if (CORBA::is_nil(myCase))
1814 SALOME::ExceptionStruct es;
1815 es.type = SALOME::BAD_PARAM;
1816 es.text = "Invalid case context";
1817 throw SALOME::SALOME_Exception(es);
1820 const char* nomDirCase = myCase->GetDirName();
1822 // Controle du nom :
1823 if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
1825 SALOME::ExceptionStruct es;
1826 es.type = SALOME::BAD_PARAM;
1827 es.text = "This iteration has already been defined.";
1828 throw SALOME::SALOME_Exception(es);
1832 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1833 if (CORBA::is_nil(myIteration))
1835 SALOME::ExceptionStruct es;
1836 es.type = SALOME::BAD_PARAM;
1837 es.text = "Unable to create the iteration";
1838 throw SALOME::SALOME_Exception(es);
1841 myContextMap[GetCurrentStudyID()]._mesIterations[std::string(NomIteration)] = myIteration;
1842 // Nom de l'iteration et du maillage
1843 myIteration->SetName(NomIteration);
1844 myIteration->SetMeshName(NomIteration);
1845 myIteration->SetState(1);
1847 int numero = myIterationParent->GetNumber() + 1;
1848 myIteration->SetNumber(numero);
1850 // Nombre d'iterations deja connues pour le cas, permettant
1851 // la creation d'un sous-repertoire unique
1852 int nbitercase = myCase->GetNumberofIter();
1853 char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1854 myIteration->SetDirNameLoc(nomDirIter);
1856 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1857 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1858 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1859 // situation la plus frequente.
1860 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1861 // le nombre d'iterations du cas permet d'eviter les collisions.
1863 if ( nbitercase < 100 ) { jaux = 2 ; }
1864 else if ( nbitercase < 1000 ) { jaux = 3 ; }
1865 else if ( nbitercase < 10000 ) { jaux = 4 ; }
1866 else if ( nbitercase < 100000 ) { jaux = 5 ; }
1868 std::ostringstream iaux ;
1869 iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1870 std::stringstream MeshFile;
1871 MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1872 myIteration->SetMeshFile(MeshFile.str().c_str());
1874 // Association avec le cas
1875 std::string label = "IterationHomard_" + std::string(nomIterParent);
1876 AssociateCaseIter(nomCas, NomIteration, label.c_str());
1877 // Lien avec l'iteration precedente
1878 myIterationParent->LinkNextIteration(NomIteration);
1879 myIteration->SetIterParentName(nomIterParent);
1881 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1883 //=============================================================================
1884 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1886 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1889 // Controle du nom :
1890 if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
1892 MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1893 SALOME::ExceptionStruct es;
1894 es.type = SALOME::BAD_PARAM;
1895 es.text = "This boundary has already been defined";
1896 throw SALOME::SALOME_Exception(es);
1900 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1901 myBoundary->SetName(BoundaryName);
1902 myBoundary->SetType(BoundaryType);
1904 myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
1906 SALOMEDS::SObject_var aSO;
1907 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
1909 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1911 //=============================================================================
1912 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1914 INFOS ("CreateBoundaryDi : BoundaryName = " << BoundaryName << "MeshName = " << MeshName );
1915 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1916 myBoundary->SetMeshFile( MeshFile ) ;
1917 myBoundary->SetMeshName( MeshName ) ;
1919 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1921 //=============================================================================
1922 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1923 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1924 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1925 CORBA::Double Rayon)
1927 INFOS ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
1929 SALOME::ExceptionStruct es;
1932 { es.text = "The radius must be positive." ;
1934 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1935 if ( daux < 0.0000001 )
1936 { es.text = "The axis must be a non 0 vector." ;
1940 es.type = SALOME::BAD_PARAM;
1941 throw SALOME::SALOME_Exception(es);
1945 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1946 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1948 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1950 //=============================================================================
1951 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1952 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1953 CORBA::Double Rayon)
1955 INFOS ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
1957 SALOME::ExceptionStruct es;
1960 { es.text = "The radius must be positive." ;
1964 es.type = SALOME::BAD_PARAM;
1965 throw SALOME::SALOME_Exception(es);
1969 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1970 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1972 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1974 //=============================================================================
1975 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
1976 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
1977 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
1979 INFOS ("CreateBoundaryConeA : BoundaryName = " << BoundaryName ) ;
1981 SALOME::ExceptionStruct es;
1983 if ( Angle <= 0.0 || Angle >= 90.0 )
1984 { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
1986 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1987 if ( daux < 0.0000001 )
1988 { es.text = "The axis must be a non 0 vector." ;
1992 es.type = SALOME::BAD_PARAM;
1993 throw SALOME::SALOME_Exception(es);
1997 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
1998 myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
2000 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2002 //=============================================================================
2003 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
2004 CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
2005 CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
2007 INFOS ("CreateBoundaryConeR : BoundaryName = " << BoundaryName ) ;
2009 SALOME::ExceptionStruct es;
2011 if ( Rayon1 < 0.0 || Rayon2 < 0.0 )
2012 { es.text = "The radius must be positive." ;
2014 double daux = fabs(Rayon2-Rayon1) ;
2015 if ( daux < 0.0000001 )
2016 { es.text = "The radius must be different." ;
2018 daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
2019 if ( daux < 0.0000001 )
2020 { es.text = "The centers must be different." ;
2024 es.type = SALOME::BAD_PARAM;
2025 throw SALOME::SALOME_Exception(es);
2029 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
2030 myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
2032 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2034 //=============================================================================
2035 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
2037 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
2040 // Controle du nom :
2041 if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
2043 SALOME::ExceptionStruct es;
2044 es.type = SALOME::BAD_PARAM;
2045 es.text = "This zone has already been defined";
2046 throw SALOME::SALOME_Exception(es);
2050 HOMARD::HOMARD_Zone_var myZone = newZone();
2051 myZone->SetName(ZoneName);
2052 myZone->SetType(ZoneType);
2054 myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
2056 SALOMEDS::SObject_var aSO;
2057 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
2059 return HOMARD::HOMARD_Zone::_duplicate(myZone);
2061 //=============================================================================
2062 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
2063 CORBA::Double Xmini, CORBA::Double Xmaxi,
2064 CORBA::Double Ymini, CORBA::Double Ymaxi,
2065 CORBA::Double Zmini, CORBA::Double Zmaxi)
2067 INFOS ("CreateZoneBox : ZoneName = " << ZoneName ) ;
2069 SALOME::ExceptionStruct es;
2071 if ( Xmini > Xmaxi )
2072 { es.text = "The X coordinates are not coherent." ;
2074 if ( Ymini > Ymaxi )
2075 { es.text = "The Y coordinates are not coherent." ;
2077 if ( Zmini > Zmaxi )
2078 { es.text = "The Z coordinates are not coherent." ;
2082 es.type = SALOME::BAD_PARAM;
2083 throw SALOME::SALOME_Exception(es);
2087 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
2088 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2090 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2092 //=============================================================================
2093 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
2094 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
2096 INFOS ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
2098 SALOME::ExceptionStruct es;
2101 { es.text = "The radius must be positive." ;
2105 es.type = SALOME::BAD_PARAM;
2106 throw SALOME::SALOME_Exception(es);
2110 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
2111 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2113 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2115 //=============================================================================
2116 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
2117 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2118 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2119 CORBA::Double Rayon, CORBA::Double Haut)
2121 INFOS ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
2123 SALOME::ExceptionStruct es;
2126 { es.text = "The radius must be positive." ;
2128 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2129 if ( daux < 0.0000001 )
2130 { es.text = "The axis must be a non 0 vector." ;
2133 { es.text = "The height must be positive." ;
2137 es.type = SALOME::BAD_PARAM;
2138 throw SALOME::SALOME_Exception(es);
2142 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
2143 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
2145 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2147 //=============================================================================
2148 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
2149 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2150 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2151 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
2153 INFOS ("CreateZonePipe : ZoneName = " << ZoneName ) ;
2155 SALOME::ExceptionStruct es;
2157 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2158 { es.text = "The radius must be positive." ;
2160 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2161 if ( daux < 0.0000001 )
2162 { es.text = "The axis must be a non 0 vector." ;
2165 { es.text = "The height must be positive." ;
2167 if ( Rayon <= Rayonint )
2168 { es.text = "The external radius must be higher than the internal radius." ;
2172 es.type = SALOME::BAD_PARAM;
2173 throw SALOME::SALOME_Exception(es);
2177 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
2178 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
2180 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2182 //=============================================================================
2183 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
2184 CORBA::Double Umini, CORBA::Double Umaxi,
2185 CORBA::Double Vmini, CORBA::Double Vmaxi,
2188 INFOS ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
2189 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
2190 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
2191 // MESSAGE ("Orient = " << Orient ) ;
2193 SALOME::ExceptionStruct es;
2195 if ( Umini > Umaxi )
2196 { es.text = "The first coordinates are not coherent." ;
2198 if ( Vmini > Vmaxi )
2199 { es.text = "The second coordinates are not coherent." ;
2201 if ( Orient < 1 || Orient > 3 )
2202 { es.text = "The orientation must be 1, 2 or 3." ;
2206 es.type = SALOME::BAD_PARAM;
2207 throw SALOME::SALOME_Exception(es);
2211 double Xmini, Xmaxi ;
2212 double Ymini, Ymaxi ;
2213 double Zmini, Zmaxi ;
2221 else if ( Orient == 2 )
2228 else if ( Orient == 3 )
2235 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2237 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2238 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2240 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2242 //=============================================================================
2243 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2244 CORBA::Double Ucentre, CORBA::Double Vcentre,
2245 CORBA::Double Rayon,
2248 INFOS ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
2250 SALOME::ExceptionStruct es;
2253 { es.text = "The radius must be positive." ;
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);
2269 { Xcentre = Ucentre ;
2272 else if ( Orient == 2 )
2275 Zcentre = Vcentre ; }
2276 else if ( Orient == 3 )
2277 { Xcentre = Vcentre ;
2279 Zcentre = Ucentre ; }
2280 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2282 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2283 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2285 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2287 //=============================================================================
2288 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2289 CORBA::Double Ucentre, CORBA::Double Vcentre,
2290 CORBA::Double Rayon, CORBA::Double Rayonint,
2293 INFOS ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
2295 SALOME::ExceptionStruct es;
2297 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2298 { es.text = "The radius must be positive." ;
2300 if ( Orient < 1 || Orient > 3 )
2301 { es.text = "The orientation must be 1, 2 or 3." ;
2303 if ( Rayon <= Rayonint )
2304 { es.text = "The external radius must be higher than the internal radius." ;
2308 es.type = SALOME::BAD_PARAM;
2309 throw SALOME::SALOME_Exception(es);
2317 { Xcentre = Ucentre ;
2320 else if ( Orient == 2 )
2323 Zcentre = Vcentre ; }
2324 else if ( Orient == 3 )
2325 { Xcentre = Vcentre ;
2327 Zcentre = Ucentre ; }
2328 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2330 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2331 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2333 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2335 //=============================================================================
2336 //=============================================================================
2341 //=============================================================================
2342 //=============================================================================
2343 // Traitement d'une iteration
2344 // etatMenage = 1 : destruction du repertoire d'execution
2345 // modeHOMARD = 1 : adaptation
2346 // != 1 : information avec les options modeHOMARD
2347 // Option1 >0 : appel depuis python
2348 // <0 : appel depuis GUI
2349 // Option2 : multiple de nombres premiers
2350 // 1 : aucune option
2351 // x2 : publication du maillage dans SMESH
2352 //=============================================================================
2353 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2355 INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2360 // A.1. L'objet iteration
2361 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
2362 ASSERT(!CORBA::is_nil(myIteration));
2364 // A.2. Numero de l'iteration
2365 // siterp1 : numero de l'iteration a traiter
2367 // siter : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2368 // Ou si information :
2370 int NumeIter = myIteration->GetNumber();
2371 std::string siterp1 ;
2372 std::stringstream saux1 ;
2374 siterp1 = saux1.str() ;
2375 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2378 if ( modeHOMARD==1 )
2380 std::stringstream saux0 ;
2381 int iaux = max(0, NumeIter-1) ;
2383 siter = saux0.str() ;
2384 if (NumeIter < 11) { siter = "0" + siter ; }
2387 { siter = siterp1 ; }
2390 const char* nomCas = myIteration->GetCaseName();
2391 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
2392 ASSERT(!CORBA::is_nil(myCase));
2394 // B. Les repertoires
2395 // B.1. Le repertoire courant
2396 std::string nomDirWork = getenv("PWD") ;
2397 // B.2. Le sous-repertoire de l'iteration a traiter
2398 char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2399 MESSAGE( ". DirCompute = " << DirCompute );
2401 // C. Le fichier des messages
2402 // C.1. Le deroulement de l'execution de HOMARD
2403 std::string LogFile = DirCompute ;
2404 LogFile += "/Liste" ;
2405 if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2407 MESSAGE (". LogFile = " << LogFile);
2408 if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2409 // C.2. Le bilan de l'analyse du maillage
2410 std::string FileInfo = DirCompute ;
2412 if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2414 { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2415 else { FileInfo += "info_ap" ; }
2417 FileInfo += "." + siterp1 + ".bilan" ;
2418 myIteration->SetFileInfo(FileInfo.c_str());
2420 // D. On passe dans le repertoire de l'iteration a calculer
2421 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2428 // E. Les donnees de l'execution HOMARD
2429 // E.1. L'objet du texte du fichier de configuration
2430 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2431 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2433 // E.2. Le maillage associe a l'iteration
2434 const char* NomMesh = myIteration->GetMeshName();
2435 MESSAGE ( ". NomMesh = " << NomMesh );
2436 const char* MeshFile = myIteration->GetMeshFile();
2437 MESSAGE ( ". MeshFile = " << MeshFile );
2439 // E.3. Les donnees du traitement HOMARD
2441 if ( modeHOMARD == 1 )
2444 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2445 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2446 codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2450 InvalideIterInfo(NomIteration);
2451 myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2453 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2454 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2455 myDriver->CreeFichierDonn();
2458 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2459 DriverTexteBoundary(myCase, myDriver) ;
2461 // E.5. Ecriture du texte dans le fichier
2462 MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2464 { myDriver->CreeFichier(); }
2468 int codretexec = 12 ;
2471 codretexec = myDriver->ExecuteHomard(Option1);
2473 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2474 // En mode adaptation, on ajuste l'etat de l'iteration
2475 if ( modeHOMARD == 1 )
2477 if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2478 else { SetEtatIter(NomIteration,1); }
2479 // GERALD -- QMESSAGE BOX
2483 // H. Gestion des resultats
2486 std::string Commentaire ;
2487 // H.1. Le fichier des messages, dans tous les cas
2488 Commentaire = "log" ;
2489 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2490 else { Commentaire += "Info" ; }
2491 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2493 // H.2. Si tout s'est bien passe :
2494 if (codretexec == 0)
2496 // H.2.1. Le fichier de bilan
2497 Commentaire = "Summary" ;
2498 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2499 else { Commentaire += "Info" ; }
2500 PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2501 // H.2.2. Le fichier de maillage obtenu
2502 if ( modeHOMARD == 1 )
2504 std::stringstream saux0 ;
2505 Commentaire = "Mesh" ;
2506 Commentaire += " " + siterp1 ;
2507 PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2508 if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2511 // H.3 Message d'erreur
2512 if (codretexec != 0)
2515 // Message d'erreur en cas de probleme en adaptation
2516 if ( modeHOMARD == 1 )
2518 text = "Error during the adaptation.\n" ;
2519 bool stopvu = false ;
2520 std::ifstream fichier( LogFile.c_str() );
2521 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
2523 std::string ligne; // variable contenant chaque ligne lue
2524 while ( std::getline( fichier, ligne ) )
2528 { text += ligne+ "\n"; }
2531 int position = ligne.find( "===== HOMARD ===== STOP =====" ) ;
2532 if ( position > 0 ) { stopvu = true ; }
2539 text = "Voir le fichier Liste.log.\n" ;
2542 SALOME::ExceptionStruct es;
2543 es.type = SALOME::BAD_PARAM;
2544 es.text = CORBA::string_dup(text.c_str());
2545 throw SALOME::SALOME_Exception(es);
2547 // En mode information, on force le succes pour pouvoir consulter le fichier log
2548 if ( modeHOMARD != 1 ) { codretexec = 0 ; }
2552 // I. Menage et retour dans le repertoire du cas
2556 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2559 chdir(nomDirWork.c_str());
2561 _chdir(nomDirWork.c_str());
2567 //=============================================================================
2568 // Calcul d'une iteration : partie specifique a l'adaptation
2569 //=============================================================================
2570 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)
2572 MESSAGE ( "ComputeAdap" );
2577 // Etat de l'iteration
2578 int etat = myIteration->GetState();
2579 // Numero de l'iteration
2580 int NumeIter = myIteration->GetNumber();
2581 std::stringstream saux0 ;
2582 saux0 << NumeIter-1 ;
2583 std::string siter = saux0.str() ;
2584 if (NumeIter < 11) { siter = "0" + siter ; }
2586 // A.2. On ne calcule pas l iteration initiale
2589 MESSAGE ( "etat = "<<etat );
2590 SALOME::ExceptionStruct es;
2591 es.type = SALOME::BAD_PARAM;
2592 es.text = "This iteration is the first of the case and cannot be computed.";
2593 throw SALOME::SALOME_Exception(es);
2597 // A.3. On verifie qu il y a une hypothese (erreur improbable);
2598 const char* nomHypo = myIteration->GetHypoName();
2599 if (std::string(nomHypo) == std::string(""))
2601 SALOME::ExceptionStruct es;
2602 es.type = SALOME::BAD_PARAM;
2603 es.text = "This iteration does not have any associated hypothesis.";
2604 throw SALOME::SALOME_Exception(es);
2607 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
2608 ASSERT(!CORBA::is_nil(myHypo));
2610 // B. L'iteration parent
2611 const char* nomIterationParent = myIteration->GetIterParentName();
2612 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2613 ASSERT(!CORBA::is_nil(myIterationParent));
2614 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2615 if ( myIterationParent->GetState() == 1 )
2618 int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2621 // GERALD -- QMESSAGE BOX
2622 VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2626 // C. Le sous-repertoire de l'iteration precedente
2627 char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2628 MESSAGE( ". DirComputePa = " << DirComputePa );
2630 // D. Les donnees de l'adaptation HOMARD
2631 // D.1. Le type de conformite
2632 int ConfType = myCase->GetConfType();
2633 MESSAGE ( ". ConfType = " << ConfType );
2635 // D.2. Le maillage de depart
2636 const char* NomMeshParent = myIterationParent->GetMeshName();
2637 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2638 const char* MeshFileParent = myIterationParent->GetMeshFile();
2639 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2641 // D.3. Le maillage associe a l'iteration
2642 const char* MeshFile = myIteration->GetMeshFile();
2643 MESSAGE ( ". MeshFile = " << MeshFile );
2644 FILE *file = fopen(MeshFile,"r");
2648 if (etatMenage == 0)
2650 SALOME::ExceptionStruct es;
2651 es.type = SALOME::BAD_PARAM;
2652 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2653 es.text = CORBA::string_dup(text.c_str());
2654 throw SALOME::SALOME_Exception(es);
2659 std::string commande = "rm -f " + std::string(MeshFile);
2660 codret = system(commande.c_str());
2663 SALOME::ExceptionStruct es;
2664 es.type = SALOME::BAD_PARAM;
2665 es.text = "The mesh file cannot be deleted.";
2666 throw SALOME::SALOME_Exception(es);
2672 // D.4. Les types de raffinement et de deraffinement
2673 // Les appels corba sont lourds, il vaut mieux les grouper
2674 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2675 ASSERT(ListTypes->length() == 3);
2676 int TypeAdap = (*ListTypes)[0];
2677 int TypeRaff = (*ListTypes)[1];
2678 int TypeDera = (*ListTypes)[2];
2680 // E. Texte du fichier de configuration
2681 // E.1. Incontournables du texte
2682 myDriver->TexteAdap();
2684 myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2685 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2686 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2688 // E.2. Ajout des informations liees aux zones eventuelles
2689 if ( TypeAdap == 0 )
2690 { DriverTexteZone(myHypo, myDriver) ; }
2692 // E.3. Ajout des informations liees aux champs eventuels
2693 if ( TypeAdap == 1 )
2694 { DriverTexteField(myIteration, myHypo, myDriver) ; }
2696 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2697 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2698 int numberOfGroups = listeGroupes->length();
2699 MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2700 if (numberOfGroups > 0)
2702 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2704 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2705 MESSAGE( "... GroupName = " << GroupName );
2706 myDriver->TexteGroup(GroupName);
2710 // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2711 DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2713 // E.6. Ajout des options avancees
2714 int Pyram = myCase->GetPyram();
2715 MESSAGE ( ". Pyram = " << Pyram );
2716 int NivMax = myHypo->GetNivMax();
2717 MESSAGE ( ". NivMax = " << NivMax );
2718 double DiamMin = myHypo->GetDiamMin() ;
2719 MESSAGE ( ". DiamMin = " << DiamMin );
2720 int AdapInit = myHypo->GetAdapInit();
2721 MESSAGE ( ". AdapInit = " << AdapInit );
2722 int LevelOutput = myHypo->GetLevelOutput();
2723 MESSAGE ( ". LevelOutput = " << LevelOutput );
2724 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
2726 // E.7. Ajout des informations sur le deroulement de l'execution
2727 int MessInfo = myIteration->GetInfoCompute();
2728 MESSAGE ( ". MessInfo = " << MessInfo );
2729 myDriver->TexteInfoCompute(MessInfo);
2733 //=============================================================================
2734 // Creation d'un nom de sous-repertoire pour l'iteration au sein d'un repertoire parent
2735 // nomrep : nom du repertoire parent
2736 // num : le nom du sous-repertoire est sous la forme 'In', n est >= num
2737 //=============================================================================
2738 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
2740 MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2741 // On verifie que le repertoire parent existe
2743 int codret = chdir(nomrep) ;
2745 int codret = _chdir(nomrep) ;
2749 SALOME::ExceptionStruct es;
2750 es.type = SALOME::BAD_PARAM;
2751 es.text = "The directory of the case does not exist.";
2752 throw SALOME::SALOME_Exception(es);
2755 std::string nomDirActuel = getenv("PWD") ;
2756 std::string DirName ;
2757 // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un repertoire inconnu
2758 bool a_chercher = true ;
2759 while ( a_chercher )
2761 // On passe dans le repertoire parent
2768 // On recherche un nom sous la forme Iabc, avec abc representant le numero
2770 if ( num < 100 ) { jaux = 2 ; }
2771 else if ( num < 1000 ) { jaux = 3 ; }
2772 else if ( num < 10000 ) { jaux = 4 ; }
2773 else if ( num < 100000 ) { jaux = 5 ; }
2775 std::ostringstream iaux ;
2776 iaux << std::setw(jaux) << std::setfill('0') << num ;
2777 std::ostringstream DirNameA ;
2778 DirNameA << "I" << iaux.str();
2779 // Si on ne pas peut entrer dans le repertoire, on doit verifier
2780 // que c'est bien un probleme d'absence
2782 if ( chdir(DirNameA.str().c_str()) != 0 )
2785 if ( _chdir(DirNameA.str().c_str()) != 0 )
2788 bool existe = false ;
2791 struct dirent *dirp;
2792 dp = opendir(nomrep);
2793 while ( (dirp = readdir(dp)) != NULL )
2795 std::string file_name(dirp->d_name);
2797 HANDLE hFind = INVALID_HANDLE_VALUE;
2798 WIN32_FIND_DATA ffd;
2799 hFind = FindFirstFile(nomrep, &ffd);
2800 if (INVALID_HANDLE_VALUE != hFind) {
2801 while (FindNextFile(hFind, &ffd) != 0) {
2802 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2803 std::string file_name(ffd.cFileName);
2805 if ( file_name == DirNameA.str() ) { existe = true ; }
2815 DirName = DirNameA.str() ;
2816 a_chercher = false ;
2823 MESSAGE ( "==> DirName = " << DirName);
2824 MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
2826 chdir(nomDirActuel.c_str());
2828 _chdir(nomDirActuel.c_str());
2830 return CORBA::string_dup( DirName.c_str() );
2832 //=============================================================================
2833 // Calcul d'une iteration : gestion du repertoire de calcul
2834 // Si le sous-repertoire existe :
2835 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
2836 // etatMenage = 1 : on fait le menage du repertoire
2837 // etatMenage = -1 : on ne fait rien
2838 //=============================================================================
2839 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
2841 MESSAGE ( "ComputeDirManagement : repertoires pour le calcul" );
2842 // B.2. Le repertoire du cas
2843 const char* nomDirCase = myCase->GetDirName();
2844 MESSAGE ( ". nomDirCase = " << nomDirCase );
2846 // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
2847 // B.3.1. Le nom du sous-repertoire
2848 const char* nomDirIt = myIteration->GetDirNameLoc();
2850 // B.3.2. Le nom complet du sous-repertoire
2851 std::stringstream DirCompute ;
2852 DirCompute << nomDirCase << "/" << nomDirIt;
2853 MESSAGE (". DirCompute = " << DirCompute.str() );
2855 // B.3.3. Si le sous-repertoire n'existe pas, on le cree
2857 if (chdir(DirCompute.str().c_str()) != 0)
2859 // Creation du repertoire car il n'existe pas :
2860 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2863 if (_chdir(DirCompute.str().c_str()) != 0)
2865 // Creation du repertoire car il n'existe pas :
2866 if (_mkdir(DirCompute.str().c_str()) != 0)
2869 // GERALD -- QMESSAGE BOX
2870 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
2871 VERIFICATION("Pb a la creation du repertoire" == 0);
2876 // Le repertoire existe
2877 // On demande de faire le menage de son contenu :
2878 if (etatMenage == 1)
2880 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
2881 std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
2882 int codret = system(commande.c_str());
2885 // GERALD -- QMESSAGE BOX
2886 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
2887 VERIFICATION("Pb au menage du repertoire de calcul" == 0);
2890 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2893 if (etatMenage == 0)
2897 struct dirent *dirp;
2898 dp = opendir(DirCompute.str().c_str());
2900 while ((dirp = readdir(dp)) != NULL && result )
2902 std::string file_name(dirp->d_name);
2903 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2907 HANDLE hFind = INVALID_HANDLE_VALUE;
2908 WIN32_FIND_DATA ffd;
2909 hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
2911 if (INVALID_HANDLE_VALUE != hFind) {
2912 while (FindNextFile(hFind, &ffd) != 0) {
2913 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2914 std::string file_name(ffd.cFileName);
2915 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2920 if ( result == false)
2922 SALOME::ExceptionStruct es;
2923 es.type = SALOME::BAD_PARAM;
2924 std::string text = "Directory : " + DirCompute.str() + "is not empty";
2925 es.text = CORBA::string_dup(text.c_str());
2926 throw SALOME::SALOME_Exception(es);
2927 VERIFICATION("Directory is not empty" == 0);
2933 return CORBA::string_dup( DirCompute.str().c_str() );
2935 //=============================================================================
2936 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
2937 //=============================================================================
2938 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
2940 MESSAGE ( "ComputeDirPaManagement : repertoires pour le calcul" );
2941 // Le repertoire du cas
2942 const char* nomDirCase = myCase->GetDirName();
2943 MESSAGE ( ". nomDirCase = " << nomDirCase );
2945 // Le sous-repertoire de l'iteration precedente
2947 const char* nomIterationParent = myIteration->GetIterParentName();
2948 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2949 const char* nomDirItPa = myIterationParent->GetDirNameLoc();
2950 std::stringstream DirComputePa ;
2951 DirComputePa << nomDirCase << "/" << nomDirItPa;
2952 MESSAGE( ". nomDirItPa = " << nomDirItPa);
2953 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
2955 return CORBA::string_dup( DirComputePa.str().c_str() );
2957 //=============================================================================
2958 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
2959 //=============================================================================
2960 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2962 MESSAGE ( "... DriverTexteZone" );
2963 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
2964 int numberOfZonesx2 = ListZone->length();
2967 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
2969 std::string ZoneName = std::string((*ListZone)[iaux]);
2970 MESSAGE ( "... ZoneName = " << ZoneName);
2971 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
2972 ASSERT(!CORBA::is_nil(myZone));
2974 int ZoneType = myZone->GetType();
2975 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
2976 int TypeUse = atoi( TypeUsestr.c_str() );
2977 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
2978 NumZone = iaux/2 + 1 ;
2979 HOMARD::double_array* zone = myZone->GetCoords();
2980 if ( ZoneType == 2 || ( ZoneType>=11 && ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
2981 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
2982 else if ( ZoneType == 4 ) // Cas d une sphere
2983 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
2984 else if ( ZoneType == 5 || ( ZoneType>=31 && ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
2985 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
2986 else if ( ZoneType == 7 || ( ZoneType>=61 && ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
2987 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
2988 else { VERIFICATION("ZoneType est incorrect." == 0) ; }
2993 //=============================================================================
2994 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
2995 //=============================================================================
2996 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2998 MESSAGE ( "... DriverTexteField" );
2999 // Le fichier du champ
3000 char* FieldFile = myIteration->GetFieldFile();
3001 MESSAGE ( ". FieldFile = " << FieldFile );
3002 if (strlen(FieldFile) == 0)
3004 // GERALD -- QMESSAGE BOX
3005 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
3006 VERIFICATION("The file for the field is not given." == 0);
3008 // Les caracteristiques d'instants du champ de pilotage
3009 int TimeStep = myIteration->GetTimeStep();
3010 MESSAGE( ". TimeStep = " << TimeStep );
3011 int Rank = myIteration->GetRank();
3012 MESSAGE( ". Rank = " << Rank );
3013 // Les informations sur les champs
3014 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
3016 const char* FieldName = aInfosHypo->FieldName;
3018 int TypeThR = aInfosHypo->TypeThR;
3019 double ThreshR = aInfosHypo->ThreshR;
3020 int TypeThC = aInfosHypo->TypeThC;
3021 double ThreshC = aInfosHypo->ThreshC;
3022 // Saut entre mailles ou non ?
3023 int UsField = aInfosHypo->UsField;
3024 MESSAGE( ". UsField = " << UsField );
3025 // L'usage des composantes
3026 int UsCmpI = aInfosHypo->UsCmpI;
3027 MESSAGE( ". UsCmpI = " << UsCmpI );
3029 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
3032 HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
3033 int numberOfCompos = mescompo->length();
3034 MESSAGE( ". numberOfCompos = " << numberOfCompos );
3035 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
3037 std::string nomCompo = std::string((*mescompo)[NumeComp]);
3038 MESSAGE( "... nomCompo = " << nomCompo );
3039 myDriver->TexteCompo(NumeComp, nomCompo);
3043 //=============================================================================
3044 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
3045 // On ecrit dans l'ordre :
3046 // 1. la definition des frontieres
3047 // 2. les liens avec les groupes
3048 // 3. un entier resumant le type de comportement pour les frontieres
3049 //=============================================================================
3050 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
3052 MESSAGE ( "... DriverTexteBoundary" );
3053 // 1. Recuperation des frontieres
3054 std::list<std::string> ListeBoundaryTraitees ;
3055 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3056 int numberOfitems = ListBoundaryGroupType->length();
3057 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
3058 int BoundaryOption = 1 ;
3059 // 2. Parcours des frontieres pour ecrire leur description
3060 int NumBoundaryAnalytical = 0 ;
3061 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3063 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3064 MESSAGE ( "... BoundaryName = " << BoundaryName);
3065 // 2.1. La frontiere a-t-elle deja ete ecrite ?
3066 // Cela arrive quand elle estliéé a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
3068 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3069 while (it != ListeBoundaryTraitees.end())
3071 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3072 if ( BoundaryName == *it ) { A_faire = 0 ; }
3075 // 2.2. Ecriture de la frontiere
3078 // 2.2.1. Caracteristiques de la frontiere
3079 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3080 ASSERT(!CORBA::is_nil(myBoundary));
3081 int BoundaryType = myBoundary->GetType();
3082 MESSAGE ( "... BoundaryType = " << BoundaryType );
3083 // 2.2.2. Ecriture selon le type
3084 // 2.2.2.1. Cas d une frontiere discrete
3085 if (BoundaryType == 0)
3087 const char* MeshName = myBoundary->GetMeshName() ;
3088 const char* MeshFile = myBoundary->GetMeshFile() ;
3089 myDriver->TexteBoundaryDi( MeshName, MeshFile);
3090 if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
3092 // 2.2.2.1. Cas d une frontiere analytique
3095 NumBoundaryAnalytical++ ;
3096 HOMARD::double_array* coor = myBoundary->GetCoords();
3097 if (BoundaryType == 1) // Cas d un cylindre
3099 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3100 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3102 else if (BoundaryType == 2) // Cas d une sphere
3104 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
3105 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3107 else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
3109 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3110 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3112 else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
3114 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3115 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3118 // 2.2.3. Memorisation du traitement
3119 ListeBoundaryTraitees.push_back( BoundaryName );
3122 // 3. Parcours des frontieres pour ecrire les liens avec les groupes
3123 NumBoundaryAnalytical = 0 ;
3124 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3126 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3127 MESSAGE ( "... BoundaryName = " << BoundaryName);
3128 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3129 ASSERT(!CORBA::is_nil(myBoundary));
3130 int BoundaryType = myBoundary->GetType();
3131 MESSAGE ( "... BoundaryType = " << BoundaryType );
3132 // 3.1. Recuperation du nom du groupe
3133 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
3134 MESSAGE ( "... GroupName = " << GroupName);
3135 // 3.2. Cas d une frontiere discrete
3136 if ( BoundaryType == 0 )
3138 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
3140 // 3.3. Cas d une frontiere analytique
3143 NumBoundaryAnalytical++ ;
3144 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
3147 // 4. Ecriture de l'option finale
3148 myDriver->TexteBoundaryOption(BoundaryOption);
3152 //=============================================================================
3153 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3154 //=============================================================================
3155 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3157 MESSAGE ( "... DriverTexteFieldInterp" );
3158 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3159 MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3160 if (TypeFieldInterp != 0)
3162 // Le fichier des champs
3163 char* FieldFile = myIteration->GetFieldFile();
3164 MESSAGE ( ". FieldFile = " << FieldFile );
3165 if (strlen(FieldFile) == 0)
3167 // GERALD -- QMESSAGE BOX
3168 VERIFICATION("The file for the field is not given." == 0);
3171 const char* MeshFile = myIteration->GetMeshFile();
3172 myDriver->TexteFieldInterp(FieldFile, MeshFile);
3175 // Interpolation de tous les champs
3176 if ( TypeFieldInterp == 1 )
3178 myDriver->TexteFieldInterpAll();
3180 // Interpolation de certains champs
3181 else if (TypeFieldInterp == 2)
3183 // Les champs et leurs instants pour l'iteration
3184 HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3185 int numberOfFieldsx3 = ListFieldTSR->length();
3186 MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3187 // Les champs pour l'hypothese
3188 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3189 int numberOfFieldsx2 = ListField->length();
3190 MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3191 // On parcourt tous les champs de l'hypothese
3193 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3196 std::string FieldName = std::string((*ListField)[iaux]) ;
3197 // Le type d'interpolation
3198 std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3199 MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3200 // On cherche à savoir si des instants ont été précisés pour cette itération
3202 for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3205 std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3206 MESSAGE( "..... FieldName2 = " << FieldName2 );
3207 // Quand c'est le bon champ, on ecrit le pas de temps
3208 if ( FieldName == FieldName2 )
3212 std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3213 // Le numero d'ordre
3214 std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3215 MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3217 int TimeStep = atoi( TimeStepstr.c_str() );
3218 int Rank = atoi( Rankstr.c_str() );
3219 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3223 // Si aucun instant n'a été défini
3227 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3235 //===========================================================================
3236 //===========================================================================
3239 //===========================================================================
3240 //===========================================================================
3242 //===========================================================================
3243 //===========================================================================
3244 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
3245 SALOMEDS::SObject_ptr theSObject,
3246 CORBA::Object_ptr theObject,
3247 const char* theName)
3249 MESSAGE("PublishInStudy pour " << theName);
3250 SALOMEDS::SObject_var aResultSO;
3251 if (CORBA::is_nil(theStudy))
3253 SALOME::ExceptionStruct es;
3254 es.type = SALOME::BAD_PARAM;
3255 es.text = "Invalid study context";
3256 throw SALOME::SALOME_Exception(es);
3260 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3261 // Rq : Iteration est publiee ailleurs
3262 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3263 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
3264 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3265 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3266 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3268 addInStudy(theStudy);
3270 // Controle de la non publication d'un objet de meme nom
3271 if ( (!aBoundary->_is_nil()) || (!aHypo->_is_nil()) || (!aYACS->_is_nil()) || (!aZone->_is_nil()) )
3273 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
3274 if (listSO->length() >= 1)
3276 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3277 aResultSO = listSO[0];
3278 return aResultSO._retn();
3282 // Caracteristiques de l'etude
3283 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
3284 aStudyBuilder->NewCommand();
3285 if(!aBoundary->_is_nil())
3286 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
3287 else if(!aCase->_is_nil())
3288 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
3289 else if(!aHypo->_is_nil())
3290 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
3291 else if(!aYACS->_is_nil())
3292 aResultSO = PublishYACSInStudy(theStudy, aStudyBuilder, aYACS, theName);
3293 else if(!aZone->_is_nil())
3294 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
3296 aStudyBuilder->CommitCommand();
3298 return aResultSO._retn();
3300 //=============================================================================
3301 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3302 SALOMEDS::StudyBuilder_var aStudyBuilder,
3303 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3305 MESSAGE("PublishBoundaryStudy pour "<<theName);
3306 SALOMEDS::SObject_var aResultSO;
3308 // Caracteristique de la Boundary
3309 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3311 // On recupere le module pere dans l etude
3312 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3313 if (theFatherHomard->_is_nil())
3315 MESSAGE("theFatherHomard->_is_nil()");
3316 return aResultSO._retn();
3319 // On ajoute la categorie des boundarys dans l etude si necessaire
3320 if ( _tag_boun == 0 )
3323 _tag_boun = _tag_gene ;
3325 MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3326 SALOMEDS::SObject_var aSObject;
3327 if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3329 MESSAGE("Ajout de la categorie des boundarys");
3330 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3331 PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3333 else { MESSAGE("La categorie des boundarys existe deja."); }
3335 CORBA::Long BoundaryType = myBoundary->GetType();
3336 // MESSAGE("BoundaryType : "<<BoundaryType);
3339 switch (BoundaryType)
3342 { value = "BoundaryDiHomard" ;
3343 icone = "mesh_tree_mesh.png" ;
3347 { value = "BoundaryAnHomard" ;
3348 icone = "cylinderpointvector_2.png" ;
3352 { value = "BoundaryAnHomard" ;
3353 icone = "spherepoint_2.png" ;
3357 { value = "BoundaryAnHomard" ;
3358 icone = "conepointvector.png" ;
3362 { value = "BoundaryAnHomard" ;
3363 icone = "conedxyz.png" ;
3367 aResultSO = aStudyBuilder->NewObject(aSObject);
3368 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3369 return aResultSO._retn();
3371 //=============================================================================
3372 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
3373 SALOMEDS::StudyBuilder_var aStudyBuilder,
3374 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3376 MESSAGE("PublishCaseInStudy pour "<<theName);
3377 SALOMEDS::SObject_var aResultSO;
3379 if (CORBA::is_nil(theObject)) {
3380 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3381 return aResultSO._retn();
3383 if (theStudy->_is_nil()) {
3384 MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
3385 return aResultSO._retn();
3388 // On recupere le module pere dans l etude
3389 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3390 if (theFatherHomard->_is_nil())
3392 MESSAGE("theFatherHomard->_is_nil()");
3393 return aResultSO._retn();
3397 MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3398 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3399 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3400 _orb->object_to_string(theObject) ) ;
3402 return aResultSO._retn();
3404 //=============================================================================
3405 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3406 SALOMEDS::StudyBuilder_var aStudyBuilder,
3407 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3409 MESSAGE("PublishHypotheseInStudy pour "<<theName);
3410 SALOMEDS::SObject_var aResultSO;
3412 // On recupere le module pere dans l etude
3413 // On ajoute la categorie des hypotheses dans l etude si necessaire
3414 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3415 if (theFatherHomard->_is_nil())
3417 MESSAGE("theFatherHomard->_is_nil()");
3418 return aResultSO._retn();
3421 // On ajoute la categorie des hypotheses dans l etude si necessaire
3422 SALOMEDS::SObject_var aSObject;
3423 if ( _tag_hypo == 0 )
3426 _tag_hypo = _tag_gene ;
3428 MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3429 if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3431 MESSAGE("Ajout de la categorie des hypotheses");
3432 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3433 PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3435 else { MESSAGE("La categorie des hypotheses existe deja."); }
3437 // Creation du resultat dans l'etude
3438 aResultSO = aStudyBuilder->NewObject(aSObject);
3439 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3441 return aResultSO._retn();
3443 //=============================================================================
3444 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::Study_ptr theStudy,
3445 SALOMEDS::StudyBuilder_var aStudyBuilder,
3446 HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3448 MESSAGE("PublishYACSInStudy pour "<<theName);
3449 SALOMEDS::SObject_var aResultSO;
3451 // On recupere le module pere dans l etude
3452 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3453 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3454 if (theFatherHomard->_is_nil())
3456 MESSAGE("theFatherHomard->_is_nil()");
3457 return aResultSO._retn();
3459 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3460 if ( _tag_yacs == 0 )
3463 _tag_yacs = _tag_gene ;
3465 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3466 SALOMEDS::SObject_var aSObject;
3467 if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3469 MESSAGE("Ajout de la categorie des schemas YACS");
3470 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3471 PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3473 else { MESSAGE("La categorie des schemas YACS existe deja."); }
3475 // Creation du resultat dans l'etude
3476 aResultSO = aStudyBuilder->NewObject(aSObject);
3477 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3479 return aResultSO._retn();
3482 //=============================================================================
3483 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
3484 SALOMEDS::StudyBuilder_var aStudyBuilder,
3485 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3487 MESSAGE("PublishZoneStudy pour "<<theName);
3488 SALOMEDS::SObject_var aResultSO;
3489 if (CORBA::is_nil(theObject))
3491 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3492 return aResultSO._retn();
3494 if (theStudy->_is_nil())
3496 MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3497 return aResultSO._retn();
3499 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3500 if (theFatherHomard->_is_nil())
3502 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3503 return aResultSO._retn();
3506 // Caracteristique de la zone
3507 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3508 CORBA::Long ZoneType = myZone->GetType();
3510 // On ajoute la categorie des zones dans l etude si necessaire
3511 if ( _tag_zone == 0 )
3514 _tag_zone = _tag_gene ;
3516 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3517 SALOMEDS::SObject_var aSObject;
3518 if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3520 MESSAGE("Ajout de la categorie des zones");
3521 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3522 PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3524 else { MESSAGE("La categorie des zones existe deja."); }
3526 aResultSO = aStudyBuilder->NewObject(aSObject);
3535 { icone = "boxdxy_2.png" ;
3539 { icone = "boxdxyz_2.png" ;
3547 { icone = "disk_2.png" ;
3551 { icone = "spherepoint_2.png" ;
3555 { icone = "cylinderpointvector_2.png" ;
3563 { icone = "diskwithhole_2.png" ;
3567 { icone = "pipe_2.png" ;
3571 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3573 return aResultSO._retn();
3575 //===========================================================================
3576 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3577 SALOMEDS::SObject_var aResultSO,
3578 const char* name, const char* comment, const char* icone, const char* ior)
3580 MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3581 // MESSAGE("icone = "<<icone);
3582 // MESSAGE("ior = "<<ior);
3583 SALOMEDS::GenericAttribute_var anAttr ;
3587 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3588 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3589 aNameAttrib->SetValue(name);
3592 // Ajout du commentaire
3593 if ( comment != NULL )
3595 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3596 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3597 aCommentAttrib->SetValue(comment);
3601 if ( icone != NULL )
3603 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3604 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3605 aPixmap->SetPixMap(icone);
3611 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3612 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3613 anIOR->SetValue(ior);
3617 //=====================================================================================
3618 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3620 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3622 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3623 ASSERT(!CORBA::is_nil(myCase));
3624 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3625 ASSERT(!CORBA::is_nil(aCaseSO));
3627 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3628 ASSERT(!CORBA::is_nil(myBoundary));
3629 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3630 ASSERT(!CORBA::is_nil(aBoundarySO));
3632 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3634 aStudyBuilder->NewCommand();
3636 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3637 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3639 aStudyBuilder->CommitCommand();
3642 //=====================================================================================
3643 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3645 MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3647 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3648 ASSERT(!CORBA::is_nil(myYACS));
3649 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3650 ASSERT(!CORBA::is_nil(aYACSSO));
3652 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3653 ASSERT(!CORBA::is_nil(myCase));
3654 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3655 ASSERT(!CORBA::is_nil(aCaseSO));
3657 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3659 aStudyBuilder->NewCommand();
3661 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3662 aStudyBuilder->Addreference(aSubSO, aCaseSO);
3664 aStudyBuilder->CommitCommand();
3667 //=============================================================================
3668 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3669 // Option = 0 : fichier issu d'une importation
3670 // Option = 1 : fichier issu d'une execution HOMARD
3672 MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3673 if (CORBA::is_nil(myCurrentStudy))
3675 SALOME::ExceptionStruct es;
3676 es.type = SALOME::BAD_PARAM;
3677 es.text = "Invalid study context";
3678 throw SALOME::SALOME_Exception(es);
3682 // Le module SMESH est-il actif ?
3683 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3685 if (!CORBA::is_nil(aSmeshSO))
3687 // On verifie que le fichier n est pas deja publie
3688 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3689 for (; aIter->More(); aIter->Next())
3691 SALOMEDS::SObject_var aSO = aIter->Value();
3692 SALOMEDS::GenericAttribute_var aGAttr;
3693 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3695 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3696 CORBA::String_var value=anAttr->Value();
3697 if (strcmp((const char*)value,NomFich) == 0)
3699 MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3700 // Pour un fichier importe, on ne republie pas
3705 // Pour un fichier calcule, on commence par faire la depublication
3708 MESSAGE ( "PublishResultInSmesh : depublication" );
3709 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3710 CORBA::String_var value2=anAttr2->Value();
3711 std::string MeshName = string(value2) ;
3712 MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3713 DeleteResultInSmesh(NomFich, MeshName) ;
3720 // On enregistre le fichier
3721 MESSAGE( "Enregistrement du fichier");
3722 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
3723 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
3724 ASSERT(!CORBA::is_nil(aSmeshEngine));
3725 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
3726 SMESH::DriverMED_ReadStatus theStatus;
3727 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3729 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
3730 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3731 for (int i = 0; i < mesMaillages->length(); i++)
3733 MESSAGE( ". Mise a jour des attributs du maillage");
3734 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
3735 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
3736 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3737 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
3738 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3739 anAttr->SetValue(NomFich);
3740 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
3741 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
3743 if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
3744 else { icone = "mesh_tree_mesh.png" ; }
3745 anAttr2->SetPixMap( icone );
3749 //=============================================================================
3750 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
3752 MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
3753 if (CORBA::is_nil(myCurrentStudy))
3755 SALOME::ExceptionStruct es;
3756 es.type = SALOME::BAD_PARAM;
3757 es.text = "Invalid study context";
3758 throw SALOME::SALOME_Exception(es);
3762 // Le module SMESH est-il actif ?
3763 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3765 if (CORBA::is_nil(aSmeshSO))
3769 // On verifie que le fichier est deja publie
3770 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
3771 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3772 for (; aIter->More(); aIter->Next())
3774 SALOMEDS::SObject_var aSO = aIter->Value();
3775 SALOMEDS::GenericAttribute_var aGAttr;
3776 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3778 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3779 CORBA::String_var value=anAttr->Value();
3780 if (strcmp((const char*)value,NomFich.c_str()) == 0)
3782 if (aSO->FindAttribute(aGAttr,"AttributeName"))
3784 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3785 CORBA::String_var value2=anAttr2->Value();
3786 if (strcmp((const char*)value2,MeshName.c_str()) == 0)
3788 myBuilder->RemoveObjectWithChildren( aSO ) ;
3796 //=============================================================================
3797 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
3799 // MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3800 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3802 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3803 if (CORBA::is_nil(myIteration))
3805 SALOME::ExceptionStruct es;
3806 es.type = SALOME::BAD_PARAM;
3807 es.text = "Invalid iterationStudy Object";
3808 throw SALOME::SALOME_Exception(es);
3812 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3814 aStudyBuilder->NewCommand();
3816 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
3817 // Pour les fichiers med, on affiche une icone de maillage
3818 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
3819 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
3821 std::string ior = " " ;
3822 if ( Commentaire[0] == 'I' )
3823 { icone = "med.png" ; }
3825 { icone = "texte_2.png" ; }
3826 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3828 aStudyBuilder->CommitCommand();
3831 //=============================================================================
3832 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
3834 // MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3835 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3837 SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3838 if (CORBA::is_nil(myYACS))
3840 SALOME::ExceptionStruct es;
3841 es.type = SALOME::BAD_PARAM;
3842 es.text = "Invalid YACSStudy Object";
3843 throw SALOME::SALOME_Exception(es);
3847 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3849 aStudyBuilder->NewCommand();
3851 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3852 std::string icone = "texte_2.png" ;
3853 std::string ior = " " ;
3854 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3856 aStudyBuilder->CommitCommand();
3859 //=============================================================================
3860 //=============================================================================
3862 //=============================================================================
3863 //=============================================================================
3864 //=============================================================================
3865 // Creation d'un schema YACS
3866 // nomCas : nom du cas a traiter
3867 // FileName : nom du fichier contenant le script de lancement du calcul
3868 // DirName : le repertoire de lancement des calculs du schéma
3869 //=============================================================================
3870 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
3872 INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
3873 INFOS ( ". nomCas : " << nomCas);
3874 INFOS ( ". ScriptFile : " << ScriptFile);
3875 INFOS ( ". DirName : " << DirName);
3876 INFOS ( ". MeshFile : " << MeshFile);
3878 // A. Controle du nom :
3879 if ((myContextMap[GetCurrentStudyID()]._mesYACSs).find(nomYACS) != (myContextMap[GetCurrentStudyID()]._mesYACSs).end())
3881 SALOME::ExceptionStruct es;
3882 es.type = SALOME::BAD_PARAM;
3883 es.text = "This schema YACS has already been defined.";
3884 throw SALOME::SALOME_Exception(es);
3888 // B. Creation de l'objet
3889 HOMARD::HOMARD_YACS_var myYACS = newYACS();
3890 if (CORBA::is_nil(myYACS))
3892 SALOME::ExceptionStruct es;
3893 es.type = SALOME::BAD_PARAM;
3894 es.text = "Unable to create the schema YACS";
3895 throw SALOME::SALOME_Exception(es);
3898 myYACS->SetName( nomYACS ) ;
3900 // C. Enregistrement
3901 myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS] = myYACS;
3903 SALOMEDS::SObject_var aSO;
3904 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myYACS, nomYACS);
3906 PublishCaseUnderYACS(nomYACS, nomCas);
3908 // D. Caracterisation
3910 myYACS->SetDirName( DirName ) ;
3911 myYACS->SetMeshFile( MeshFile ) ;
3912 myYACS->SetScriptFile( ScriptFile ) ;
3913 myYACS->SetCaseName( nomCas ) ;
3915 // D.2.1. Type constant
3916 myYACS->SetType( 1 ) ;
3917 // D.2.2. Fichier de sauvegarde dans le repertoire du cas
3918 HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
3919 std::string dirnamecase = caseyacs->GetDirName() ;
3920 std::string XMLFile ;
3921 XMLFile = dirnamecase + "/schema.xml" ;
3922 myYACS->SetXMLFile( XMLFile.c_str() ) ;
3924 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
3926 //=============================================================================
3927 // Ecriture d'un schema YACS
3928 //=============================================================================
3929 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
3931 INFOS ( "YACSWrite : Ecriture de " << nomYACS );
3932 // Le repertoire du cas
3933 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3934 ASSERT(!CORBA::is_nil(myYACS));
3935 // Le nom du fichier du schema
3936 std::string XMLFile ;
3937 XMLFile = myYACS->GetXMLFile() ;
3939 int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
3943 //=============================================================================
3944 // Ecriture d'un schema YACS sur un fichier donne
3945 //=============================================================================
3946 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
3948 INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
3955 HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3956 ASSERT(!CORBA::is_nil(myYACS));
3957 // B.2. Les caracteristiques
3958 std::string DirName = myYACS->GetDirName() ;
3959 std::string MeshFile = myYACS->GetMeshFile() ;
3960 std::string ScriptFile = myYACS->GetScriptFile() ;
3964 const char* nomCas = myYACS->GetCaseName();
3965 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
3966 ASSERT(!CORBA::is_nil(myCase));
3967 // C.2. Les instructions python associees au cas
3968 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
3969 std::string pythonCas = dumpCorbaCase.in();
3970 MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
3972 // D. Les iterations
3973 // D.1. L'iteration initiale
3974 HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
3975 std::string Iter0Name = myCase->GetIter0Name() ;
3976 MESSAGE (". Iter0Name = " << Iter0Name);
3977 std::string MeshName = Iter0->GetMeshName();
3978 MESSAGE (". MeshName = " << MeshName);
3979 // D.2. L'iteration numero 1
3980 HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
3981 int numberOfIter = maListe->length();
3982 if ( numberOfIter > 1 )
3984 MESSAGE (". numberOfIter = " << numberOfIter);
3985 SALOME::ExceptionStruct es ;
3986 es.type = SALOME::BAD_PARAM;
3987 std::string text = "Une seule iteration est permise." ;
3988 es.text = CORBA::string_dup(text.c_str());
3989 throw SALOME::SALOME_Exception(es);
3992 std::string Iter1Name = std::string((*maListe)[0]);
3993 MESSAGE ("... Iter1Name = " << Iter1Name);
3994 HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
3995 // D.3. Les instructions python associees a l'iteration
3996 CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
3997 std::string pythonIter = dumpCorbaIter.in();
3998 MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
4000 // E. L'hypothese pour passer de l'iteration initiale a la suivante
4001 // E.1. La structure
4002 std::string nomHypo = Iter1->GetHypoName();
4003 MESSAGE (". nomHypo = " << nomHypo);
4004 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
4005 ASSERT(!CORBA::is_nil(myHypo));
4006 // E.2. Les caracteristiques de l'adaptation
4007 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
4008 ASSERT(ListTypes->length() == 3);
4009 int TypeAdap = (*ListTypes)[0];
4010 // int TypeRaff = (*ListTypes)[1];
4011 // int TypeDera = (*ListTypes)[2];
4012 // E.3. Les instructions python associees a l'hypothese
4013 CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
4014 std::string pythonHypo = dumpCorbaHypo.in();
4015 MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
4017 // F. Le fichier du schema de reference
4018 // HOMARD_ROOT_DIR : repertoire ou se trouve le module HOMARD
4019 std::string XMLFile_base ;
4020 if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
4023 SALOME::ExceptionStruct es ;
4024 es.type = SALOME::BAD_PARAM;
4025 std::string text = "HOMARD_ROOT_DIR est inconnu." ;
4026 es.text = CORBA::string_dup(text.c_str());
4027 throw SALOME::SALOME_Exception(es);
4030 XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
4032 MESSAGE("XMLFile_base ="<<XMLFile_base);
4034 // G. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4035 YACSDriver* myDriver = new YACSDriver(XMLFile, DirName);
4036 std::ifstream fichier( XMLFile_base.c_str() );
4037 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
4039 // G.1. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4040 std::string ligne; // variable contenant chaque ligne lue
4041 std::string mot_cle;
4042 while ( std::getline( fichier, ligne ) )
4044 // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
4045 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
4046 ligne_bis >> mot_cle ;
4047 // G.1.2. Le maillage initial
4048 if ( mot_cle == "DataInit_MeshFile" )
4049 { myDriver->Texte_DataInit_MeshFile(MeshFile); }
4050 // G.1.3. Le script de lancement
4051 else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
4052 { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
4053 // G.1.4. Les options du cas
4054 else if ( mot_cle == "Iter_1_Case_Options" )
4055 { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
4056 // G.1.5. Execution de HOMARD : le repertoire du cas
4057 else if ( mot_cle == "HOMARD_Exec_DirName" )
4058 { myDriver->Texte_HOMARD_Exec_DirName(); }
4059 // G.1.6. Execution de HOMARD : le nom du maillage
4060 else if ( mot_cle == "HOMARD_Exec_MeshName" )
4062 myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
4063 std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
4064 myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
4066 // G.1.7. Execution de HOMARD : les options de l'hypothese
4067 else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
4068 { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ; }
4069 // G.1.8. Execution de HOMARD : les options de l'iteration
4070 else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
4071 { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ; }
4072 // G.1.9. Zones et frontieres : les creations
4073 else if ( mot_cle == "Iter_1" )
4075 std::string texte_control = myDriver->Texte_Iter_1_control() ;
4076 if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
4077 texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
4078 myDriver->TexteAdd(texte_control);
4080 // G.1.10. Les parametres
4081 else if ( mot_cle == "PARAMETRES" )
4082 { myDriver->TexteAddParametres(); }
4083 // G.1.n. La ligne est recopiee telle quelle
4084 else { myDriver->TexteAdd(ligne); }
4086 // G.2. Ecriture du texte dans le fichier
4088 { myDriver->CreeFichier(); }
4092 SALOME::ExceptionStruct es;
4093 es.type = SALOME::BAD_PARAM;
4094 std::string text = "The reference file for the YACS schema cannot be read." ;
4095 es.text = CORBA::string_dup(text.c_str());
4096 throw SALOME::SALOME_Exception(es);
4101 // H. Publication du fichier dans l'arbre
4103 std::string Commentaire = "xml" ;
4104 PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
4108 //=============================================================================
4109 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
4110 //=============================================================================
4111 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
4113 MESSAGE ( "YACSDriverTexteZone" );
4114 // A. Les zones associees a cette hypothese
4115 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
4116 int numberOfZonesx2 = ListZone->length();
4118 // B. Parcours des zones
4119 std::string texte_control ;
4120 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
4122 // 1. Reperage de la zone
4123 std::string ZoneName = std::string((*ListZone)[iaux]);
4124 MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
4125 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
4126 ASSERT(!CORBA::is_nil(myZone));
4127 // 2. Les instructions python associees a la zone
4128 // La premiere ligne est un commentaire a eliminer
4129 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4130 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4131 std::string pythonStructure_0 = dumpCorbaZone.in();
4132 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4133 std::istringstream tout (pythonStructure_0) ;
4135 std::string pythonStructure ;
4136 while ( std::getline( tout, ligne ) )
4137 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4138 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4139 // 3. Decodage du nom du service
4140 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4141 MESSAGE ( "... methode = " << methode);
4142 // 4. Mise en place des instructions
4143 int ZoneType = myZone->GetType();
4144 MESSAGE ( "... ZoneType = " << ZoneType);
4145 std::string texte_control_0 ;
4146 texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
4147 texte_control += texte_control_0 ;
4152 return texte_control ;
4154 //=============================================================================
4155 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4156 //=============================================================================
4157 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4159 MESSAGE ( "YACSDriverTexteBoundary" );
4160 // A. Les frontieres associees au cas
4161 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4162 int numberOfitems = ListBoundaryGroupType->length();
4164 // B. Parcours des frontieres
4165 std::string texte_control ;
4166 std::list<std::string> ListeBoundaryTraitees ;
4167 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4169 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4170 MESSAGE ( "... BoundaryName = " << BoundaryName);
4171 // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4172 // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4174 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4175 while (it != ListeBoundaryTraitees.end())
4177 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4178 if ( BoundaryName == *it ) { A_faire = 0 ; }
4183 // 1. Caracteristiques de la frontiere
4184 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
4185 ASSERT(!CORBA::is_nil(myBoundary));
4186 // 2. Les instructions python associees a la frontiere
4187 // La premiere ligne est un commentaire a eliminer
4188 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4189 CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4190 std::string pythonStructure_0 = dumpCorbaBoundary.in();
4191 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4192 std::istringstream tout (pythonStructure_0) ;
4194 std::string pythonStructure ;
4195 while ( std::getline( tout, ligne ) )
4196 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4197 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4198 // 3. Decodage du nom du service
4199 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4200 MESSAGE ( "... methode = " << methode);
4201 // 4. Mise en place des instructions
4202 int BoundaryType = myBoundary->GetType();
4203 MESSAGE ( "... BoundaryType = " << BoundaryType);
4204 std::string texte_control_0 ;
4205 texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName );
4206 texte_control += texte_control_0 ;
4207 // 5. Memorisation du traitement
4208 ListeBoundaryTraitees.push_back( BoundaryName );
4212 return texte_control ;
4215 //=============================================================================
4216 //=============================================================================
4217 // Next functions are inherited from SALOMEDS::Driver interface
4218 //=============================================================================
4219 //=============================================================================
4220 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4222 CORBA::Boolean isMultiFile)
4224 MESSAGE ("Save for theURL = "<< theURL);
4225 SALOMEDS::TMPFile_var aStreamFile;
4227 // get temporary directory name
4228 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4230 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4231 StudyContext& context = myContextMap[ aStudy->StudyId() ];
4233 // HOMARD data file name
4234 std::string aFileName = "";
4236 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4237 aFileName += "_HOMARD.dat";
4239 // initialize sequence of file names
4240 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
4241 aFileSeq->length(1);
4242 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
4244 // get full path to the data file
4245 aFileName = tmpDir + aFileName;
4249 std::ofstream f(aFileName.c_str());
4251 // clear temporary id map
4252 context._idmap.clear();
4257 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4258 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4259 HOMARD::HOMARD_Cas_var aCas = it_case->second;
4260 PortableServer::ServantBase_var aServant = GetServant(aCas);
4261 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4263 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4264 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4268 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4269 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4270 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4271 PortableServer::ServantBase_var aServant = GetServant(aZone);
4272 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4274 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4275 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4278 // -> save hypotheses
4279 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4280 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4281 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4282 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4283 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4285 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4286 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4289 // -> save iterations
4290 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4291 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4292 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4293 PortableServer::ServantBase_var aServant = GetServant(aIter);
4294 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4296 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4297 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4300 // -> save boundaries
4301 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4302 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4303 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4304 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4305 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4306 if (aBoundaryServant) {
4307 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4308 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4312 MESSAGE ("close file");
4315 // put temporary files to the stream
4316 MESSAGE ("put temporary files to the stream");
4317 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
4319 // remove temporary files
4320 MESSAGE ("remove temporary files");
4321 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4323 // return data stream
4324 MESSAGE ("return data stream");
4325 return aStreamFile._retn();
4328 //===========================================================================
4329 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4331 CORBA::Boolean isMultiFile)
4333 // No specific ASCII persistence
4334 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4335 return aStreamFile._retn();
4338 //===========================================================================
4339 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4340 const SALOMEDS::TMPFile& theStream,
4342 CORBA::Boolean isMultiFile)
4344 MESSAGE ("Load pour theURL = "<< theURL);
4345 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4347 // set current study
4348 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
4349 SetCurrentStudy(aStudy);
4351 // get temporary directory name
4352 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4354 // Convert the stream into sequence of files to process
4355 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4358 // HOMARD data file name
4359 std::string aFileName = "";
4361 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4362 aFileName = tmpDir + aFileName + "_HOMARD.dat";
4364 StudyContext& context = myContextMap[ aStudy->StudyId() ];
4368 std::ifstream f(aFileName.c_str());
4371 context._mesCas.clear();
4372 context._mesHypotheses.clear();
4373 context._mesIterations.clear();
4374 context._mesZones.clear();
4375 context._mesBoundarys.clear();
4376 context._idmap.clear();
4382 std::getline(f, line);
4383 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4384 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4385 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4386 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4387 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4388 std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4389 if (line.substr(0, bounSignature.size()) == bounSignature) {
4390 // re-create boundary
4391 MESSAGE ("Recreation de la frontiere" );
4392 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4393 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4394 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4395 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4396 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4397 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4400 else if (line.substr(0, caseSignature.size()) == caseSignature) {
4402 MESSAGE ("Recreation du cas" );
4403 HOMARD::HOMARD_Cas_var aCase = newCase();
4404 PortableServer::ServantBase_var aServant = GetServant(aCase);
4405 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4406 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4407 context._mesCas[aCase->GetName()] = aCase;
4408 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4411 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4412 // re-create hypothesis
4413 MESSAGE ("Recreation de l hypothese" );
4414 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4415 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4416 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4417 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4418 context._mesHypotheses[aHypo->GetName()] = aHypo;
4419 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4422 else if (line.substr(0, iterSignature.size()) == iterSignature) {
4423 // re-create iteration
4424 MESSAGE ("Recreation de l iteration" );
4425 HOMARD::HOMARD_Iteration_var aIter = newIteration();
4426 PortableServer::ServantBase_var aServant = GetServant(aIter);
4427 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4428 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4429 context._mesIterations[aIter->GetName()] = aIter;
4430 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4433 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4434 MESSAGE ("Recreation de la zone" );
4436 HOMARD::HOMARD_Zone_var aZone = newZone();
4437 PortableServer::ServantBase_var aServant = GetServant(aZone);
4438 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4439 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4440 context._mesZones[aZone->GetName()] = aZone;
4441 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4444 else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4445 MESSAGE ("Recreation du schema YACS" );
4447 HOMARD::HOMARD_YACS_var aYACS = newYACS();
4448 PortableServer::ServantBase_var aServant = GetServant(aYACS);
4449 HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4450 if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4451 context._mesYACSs[aYACS->GetName()] = aYACS;
4452 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4461 // Remove temporary files created from the stream
4463 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4468 //===========================================================================
4469 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4470 const SALOMEDS::TMPFile& theStream,
4472 CORBA::Boolean isMultiFile)
4474 // No specific ASCII persistence
4475 return Load(theComponent, theStream, theURL, isMultiFile);
4478 //===========================================================================
4479 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4481 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
4482 // clearing study context should be done here:
4483 // - destroy all servants and related CORBA objects
4485 // - remove context from myContextMap
4486 myContextMap.erase(theComponent->GetStudy()->StudyId());
4487 // - nullify myCurrentStudy
4488 myCurrentStudy = SALOMEDS::Study::_nil();
4492 //===========================================================================
4493 char* HOMARD_Gen_i::ComponentDataType()
4495 return CORBA::string_dup("HOMARD");
4498 //===========================================================================
4499 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4500 const char* IORString,
4501 CORBA::Boolean isMultiFile,
4502 CORBA::Boolean isASCII)
4504 CORBA::String_var aString("");
4505 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4506 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4507 CORBA::Object_var anObj = _orb->string_to_object(IORString);
4508 if (!CORBA::is_nil(anObj)) {
4509 PortableServer::ServantBase_var aServant = GetServant(anObj);
4510 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4512 std::map<int, PortableServer::ServantBase*>::const_iterator it;
4513 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4514 if (it->second == aStorable) {
4515 std::stringstream os;
4517 aString = CORBA::string_dup(os.str().c_str());
4523 return aString._retn();
4526 //===========================================================================
4527 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4528 const char* aLocalPersistentID,
4529 CORBA::Boolean isMultiFile,
4530 CORBA::Boolean isASCII)
4532 CORBA::String_var aString("");
4533 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4534 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4535 int id = atoi(aLocalPersistentID);
4536 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4537 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4538 if (!CORBA::is_nil(object)) {
4539 aString = _orb->object_to_string(object);
4543 return aString._retn();
4546 //===========================================================================
4547 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4549 if(CORBA::is_nil(myCurrentStudy))
4552 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4553 if(!aCas->_is_nil())
4556 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4557 if(!aHypo->_is_nil())
4560 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4561 if(!aZone->_is_nil())
4564 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4565 if(!aBoundary->_is_nil())
4568 /* Iteration is not published directly
4569 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4570 if(!aIter->_is_nil())
4576 //===========================================================================
4577 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4579 // No Copy/Paste support
4583 //===========================================================================
4584 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4585 CORBA::Long& theObjectID)
4587 // No Copy/Paste support
4588 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4589 return aStreamFile._retn();
4592 //===========================================================================
4593 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
4594 CORBA::Long theObjectID)
4596 // No Copy/Paste support
4600 //===========================================================================
4601 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4602 CORBA::Long theObjectID,
4603 SALOMEDS::SObject_ptr theSObject)
4605 // No Copy/Paste support
4606 SALOMEDS::SObject_var aResultSO;
4607 return aResultSO._retn();
4610 //===========================================================================
4611 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4613 PortableServer::Servant aServant = 0;
4614 if (!CORBA::is_nil(theObject)) {
4616 aServant = _poa->reference_to_servant(theObject);
4624 //==========================================================================
4625 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4626 CORBA::Boolean isPublished,
4627 CORBA::Boolean isMultiFile,
4628 CORBA::Boolean& isValidScript)
4630 MESSAGE ("Entree dans DumpPython");
4632 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
4633 if(CORBA::is_nil(aStudy))
4634 return new Engines::TMPFile(0);
4636 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
4637 if(CORBA::is_nil(aSO))
4638 return new Engines::TMPFile(0);
4640 std::string aScript = "\"\"\"\n";
4641 aScript += "Python script for HOMARD\n";
4642 aScript += "Copyright EDF-R&D 2013\n";
4643 aScript += "\"\"\"\n";
4644 aScript += "__revision__ = \"V1.2\"\n";
4645 aScript += "import HOMARD\n";
4647 aScript += "import salome\n";
4648 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4650 aScript += "def RebuildData(theStudy):\n";
4651 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
4654 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
4655 MESSAGE (". Au depart \n"<<aScript);
4658 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
4660 MESSAGE (". Ecritures des frontieres");
4661 aScript += "#\n# Creation of the boundaries";
4662 aScript += "\n# ==========================";
4664 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4665 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
4666 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
4668 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4669 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4670 std::string dumpBoundary = dumpCorbaBoundary.in();
4671 MESSAGE (dumpBoundary<<"\n");
4672 aScript += dumpBoundary;
4676 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
4678 MESSAGE (". Ecritures des zones");
4679 aScript += "#\n# Creation of the zones";
4680 aScript += "\n# =====================";
4682 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4683 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
4684 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
4686 HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
4687 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4688 std::string dumpZone = dumpCorbaZone.in();
4689 MESSAGE (dumpZone<<"\n");
4690 aScript += dumpZone;
4694 if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
4696 MESSAGE (". Ecritures des hypotheses");
4697 aScript += "#\n# Creation of the hypotheses";
4698 aScript += "\n# ==========================";
4700 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4701 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
4702 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
4704 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
4705 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
4706 std::string dumpHypo = dumpCorbaHypo.in();
4707 MESSAGE (dumpHypo<<"\n");
4708 aScript += dumpHypo;
4712 if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
4714 MESSAGE (". Ecritures des cas");
4715 aScript += "#\n# Creation of the cases";
4716 aScript += "\n# =====================";
4718 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
4719 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4720 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
4722 std::string nomCas = (*it_cas).first;
4723 std::string dumpCas = std::string("\n# Creation of the case ") ;
4724 dumpCas += nomCas + std::string("\n");
4725 dumpCas += std::string("\t") + nomCas;
4726 dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
4728 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
4729 CORBA::String_var cIter0= myCase->GetIter0Name();
4730 std::string iter0 = cIter0.in();
4732 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
4733 CORBA::String_var cMesh0= myIteration->GetMeshFile();
4734 std::string mesh0 = cMesh0.in();
4735 CORBA::String_var cMeshName0= myIteration->GetMeshName();
4736 std::string meshName0 = cMeshName0.in();
4737 dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
4738 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4739 std::string dumpCas2= dumpCorbaCase.in();
4741 MESSAGE (dumpCas<<dumpCas2<<"\n");
4742 aScript += dumpCas + dumpCas2;
4746 if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
4748 MESSAGE (". Ecritures des iterations");
4749 aScript += "#\n# Creation of the iterations" ;
4750 aScript += "\n# ==========================";
4752 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4753 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
4754 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
4756 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
4757 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
4758 std::string dumpIter = dumpCorbaIter.in();
4759 MESSAGE (dumpIter<<"\n");
4760 aScript += dumpIter;
4764 if (myContextMap[GetCurrentStudyID()]._mesYACSs.size() > 0)
4766 MESSAGE (". Ecritures des schemas YACS");
4767 aScript += "#\n# Creation of the schemas YACS";
4768 aScript += "\n# ============================";
4770 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
4771 for ( it_yacs = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
4772 it_yacs != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); ++it_yacs)
4774 HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
4775 CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
4776 std::string dumpYACS = dumpCorbaYACS.in();
4777 MESSAGE (dumpYACS<<"\n");
4778 aScript += dumpYACS;
4781 MESSAGE (". Ecritures finales");
4783 aScript += "\n\tpass";
4786 if( !isMultiFile ) // remove unnecessary tabulation
4787 aScript = RemoveTabulation( aScript );
4789 // MESSAGE ("A ecrire \n"<<aScript);
4790 const size_t aLen = strlen(aScript.c_str());
4791 char* aBuffer = new char[aLen+1];
4792 strcpy(aBuffer, aScript.c_str());
4794 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
4795 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
4797 MESSAGE ("Sortie de DumpPython");
4798 return aStreamFile._retn();
4802 //=============================================================================
4803 //=============================================================================
4805 //=============================================================================
4806 //=============================================================================
4807 void HOMARD_Gen_i::IsValidStudy( )
4809 // MESSAGE( "IsValidStudy" );
4810 if (CORBA::is_nil(myCurrentStudy))
4812 SALOME::ExceptionStruct es;
4813 es.type = SALOME::BAD_PARAM;
4814 es.text = "Invalid study context";
4815 throw SALOME::SALOME_Exception(es);
4820 //=============================================================================
4821 char* HOMARD_Gen_i::VerifieDir(const char* nomDir)
4823 std::string casename = std::string("") ;
4824 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
4825 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4826 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
4828 if (std::string(nomDir) == std::string(it->second->GetDirName()))
4830 casename = std::string(it->second->GetName()) ;
4834 return CORBA::string_dup( casename.c_str() );
4836 /*//=============================================================================
4837 void SALOMEException( std::string message )
4839 SALOME::ExceptionStruct es;
4840 es.type = SALOME::BAD_PARAM;
4842 throw SALOME::SALOME_Exception(es);
4845 //=============================================================================
4846 char* HOMARD_Gen_i::getVersion()
4848 #if HOMARD_DEVELOPMENT
4849 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
4851 return CORBA::string_dup(HOMARD_VERSION_STR);
4854 //===============================================================================
4855 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un texte
4856 // ligne : la ligne a manipuler
4857 // texte : le texte a reperer
4858 // option : 0 : la chaine avant le texte
4859 // 1 : la chaine apres le texte
4860 // Si le texte est absent, on retourne la chaine totale
4861 //===============================================================================
4862 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string texte, int option )
4864 // MESSAGE("GetStringInTexte, recherche de '"<<texte<<"' dans '"<<ligne<<"'"<<", option = "<<option);
4866 std::string chaine = ligne ;
4867 int position = ligne.find_first_of( texte ) ;
4870 if ( option == 0 ) { chaine = ligne.substr( 0, position ) ; }
4871 else { chaine = ligne.substr( position+1 ) ; }
4876 // //===============================================================================
4877 // // Langue de SALOME
4878 // //===============================================================================
4879 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
4881 // MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
4882 _LangueShort = LanguageShort ;
4883 if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
4884 else { _Langue = "English" ; }
4887 char* HOMARD_Gen_i::GetLanguageShort()
4889 // MESSAGE ("GetLanguageShort");
4890 return CORBA::string_dup( _LangueShort.c_str() );
4893 //=============================================================================
4897 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
4898 PortableServer::POA_ptr poa,
4899 PortableServer::ObjectId* contId,
4900 const char* instanceName,
4901 const char* interfaceName)
4903 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
4904 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
4905 return myHOMARD_Gen->getId();