1 // Copyright (C) 2011-2012 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 "HomardDriver.hxx"
27 #include "HOMARD_DriverTools.hxx"
28 #include "HomardMedCommun.h"
30 #include "HOMARD_version.h"
32 #include "utilities.h"
33 #include "Utils_SINGLETON.hxx"
34 #include "Utils_CorbaException.hxx"
35 #include "SALOMEDS_Tool.hxx"
36 #include "SALOME_LifeCycleCORBA.hxx"
37 #include "SALOMEconfig.h"
38 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
39 #include CORBA_CLIENT_HEADER(SMESH_Gen)
54 //=============================================================================
56 //=============================================================================
57 std::string RemoveTabulation( std::string theScript )
59 std::string::size_type aPos = 0;
60 while( aPos < theScript.length() )
62 aPos = theScript.find( "\n\t", aPos );
63 if( aPos == std::string::npos )
65 theScript.replace( aPos, 2, "\n" );
70 //=============================================================================
72 * standard constructor
74 //=============================================================================
75 HOMARD_Gen_i::HOMARD_Gen_i( CORBA::ORB_ptr orb,
76 PortableServer::POA_ptr poa,
77 PortableServer::ObjectId * contId,
78 const char *instanceName,
79 const char *interfaceName) :
80 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
82 MESSAGE("constructor");
84 _id = _poa->activate_object(_thisObj);
86 myHomard = new ::HOMARD_Gen();
87 _NS = SINGLETON_<SALOME_NamingService>::Instance();
88 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
91 //=================================
95 //================================
96 HOMARD_Gen_i::~HOMARD_Gen_i()
99 //=============================================================================
100 //=============================================================================
101 // Utilitaires pour l'étude
102 //=============================================================================
103 //=============================================================================
104 void HOMARD_Gen_i::addInStudy(SALOMEDS::Study_ptr theStudy)
106 ASSERT(!CORBA::is_nil(theStudy));
107 MESSAGE("addInStudy: ajout eventuel du composant HOMARD dans current study ID = " << GetCurrentStudyID()) ;
108 SALOMEDS::StudyBuilder_var myBuilder = theStudy->NewBuilder();
110 // Create SComponent labelled 'homard' if it doesn't already exit
111 SALOMEDS::SComponent_var homardFather = theStudy->FindComponent(ComponentDataType());
112 if (CORBA::is_nil(homardFather))
114 myBuilder->NewCommand();
115 MESSAGE("Add Component HOMARD");
117 bool aLocked = theStudy->GetProperties()->IsLocked();
118 if (aLocked) theStudy->GetProperties()->SetLocked(false);
120 homardFather = myBuilder->NewComponent(ComponentDataType());
121 SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
122 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
123 CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
124 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
125 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
126 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
127 if (!Comp->_is_nil())
129 aName->SetValue(ComponentDataType());
132 anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributePixMap");
133 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
134 aPixmap->SetPixMap("HOMARD_2.png");
135 myBuilder->DefineComponentInstance(homardFather, HOMARD_Gen::_this());
137 if (aLocked) theStudy->GetProperties()->SetLocked(true);
138 myBuilder->CommitCommand();
141 //=============================================================================
142 void HOMARD_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy)
144 MESSAGE("SetCurrentStudy: current study Id = " << GetCurrentStudyID());
145 myCurrentStudy = SALOMEDS::Study::_duplicate(theStudy);
146 this->addInStudy(myCurrentStudy);
148 //=============================================================================
149 SALOMEDS::Study_ptr HOMARD_Gen_i::GetCurrentStudy()
150 //=============================================================================
152 MESSAGE("GetCurrentStudy: study Id = " << GetCurrentStudyID());
153 return SALOMEDS::Study::_duplicate(myCurrentStudy);
155 //=============================================================================
156 CORBA::Long HOMARD_Gen_i::GetCurrentStudyID()
157 //=============================================================================
159 return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId();
161 //=============================================================================
162 //=============================================================================
164 //=============================================================================
165 //=============================================================================
166 // Utilitaires pour l'iteration
167 //=============================================================================
168 //=============================================================================
169 void HOMARD_Gen_i::SetEtatIter(const char* nomIter, const CORBA::Boolean EtatCalcul)
170 //=====================================================================================
172 MESSAGE( "SetEtatIter : affectation de l'etat '" << EtatCalcul << "' a l'iteration " << nomIter );
173 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
174 if (CORBA::is_nil(myIteration))
176 SALOME::ExceptionStruct es;
177 es.type = SALOME::BAD_PARAM;
178 es.text = "Invalid Iteration ";
179 throw SALOME::SALOME_Exception(es);
183 myIteration->SetEtat(EtatCalcul);
185 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
186 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
188 int number = myIteration->GetNumber() ;
191 icone = "iter0.png" ;
193 icone = "iter_calculee.png" ;
195 icone = "iter_non_calculee.png" ;
196 PublishInStudyAttr(aStudyBuilder, aIterSO, NULL , NULL, icone, NULL) ;
198 aStudyBuilder->CommitCommand();
201 //=============================================================================
202 //=============================================================================
204 //=============================================================================
205 //=============================================================================
206 // Destruction des structures identifiees par leurs noms
207 //=============================================================================
208 //=============================================================================
209 CORBA::Long HOMARD_Gen_i::DeleteBoundary(const char* BoundaryName)
211 MESSAGE ( "DeleteBoundary : BoundaryName = " << BoundaryName );
212 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
213 if (CORBA::is_nil(myBoundary))
215 // const char* message = "Invalid Boundary " ;
216 // SALOMEException(message) ;
217 SALOME::ExceptionStruct es;
218 es.type = SALOME::BAD_PARAM;
219 es.text = "Invalid Boundary ";
220 throw SALOME::SALOME_Exception(es);
224 // On verifie que la frontiere n'est plus utilisee
225 HOMARD::listeCases* maListe = GetAllCasesName();
226 int numberOfCases = maListe->length();
227 MESSAGE ( ".. Nombre de cas = " << numberOfCases );
228 std::string CaseName ;
229 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType ;
231 HOMARD::HOMARD_Cas_var myCase ;
232 for (int NumeCas = 0; NumeCas< numberOfCases; NumeCas++)
234 CaseName = std::string((*maListe)[NumeCas]);
235 MESSAGE ( "... Examen du cas = " << CaseName.c_str() );
236 myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
237 ASSERT(!CORBA::is_nil(myCase));
238 ListBoundaryGroupType = myCase->GetBoundaryGroup();
239 numberOfitems = ListBoundaryGroupType->length();
240 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
241 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
243 if ( std::string((*ListBoundaryGroupType)[NumBoundary]) == BoundaryName )
245 SALOME::ExceptionStruct es;
246 es.type = SALOME::BAD_PARAM;
247 es.text = "This boundary is used in a case and cannot be deleted.";
248 throw SALOME::SALOME_Exception(es);
254 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
255 myContextMap[GetCurrentStudyID()]._mesBoundarys.erase(BoundaryName);
256 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(BoundaryName, ComponentDataType());
257 SALOMEDS::SObject_var aSO =listSO[0];
258 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
259 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
263 //=============================================================================
264 CORBA::Long HOMARD_Gen_i::DeleteCase(const char* nomCas)
266 // Pour detruire un cas
267 MESSAGE ( "DeleteCase : nomCas = " << nomCas );
268 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
269 if (CORBA::is_nil(myCase))
271 SALOME::ExceptionStruct es;
272 es.type = SALOME::BAD_PARAM;
273 es.text = "Invalid Case Context ";
274 throw SALOME::SALOME_Exception(es);
277 // On commence par detruire toutes les iterations en partant de l'initiale et y compris elle
278 CORBA::String_var nomIter = myCase->GetIter0Name();
279 CORBA::Long Option1 = 0 ;
280 CORBA::Long Option2 = 1 ;
281 if ( DeleteIterationOption(nomIter, Option1, Option2) != 0 )
286 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
287 myContextMap[GetCurrentStudyID()]._mesCas.erase(nomCas);
288 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomCas, ComponentDataType());
289 SALOMEDS::SObject_var aSO =listSO[0];
290 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
291 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
295 //=============================================================================
296 CORBA::Long HOMARD_Gen_i::DeleteHypo(const char* nomHypo)
298 MESSAGE ( "DeleteHypo : nomHypo = " << nomHypo );
299 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
300 if (CORBA::is_nil(myHypo))
302 SALOME::ExceptionStruct es;
303 es.type = SALOME::BAD_PARAM;
304 es.text = "Invalid Hypothesis ";
305 throw SALOME::SALOME_Exception(es);
309 // On verifie que l'hypothese n'est plus utilisee
310 HOMARD::listeIters* maListeIter = myHypo->GetIterations();
311 int numberOfIter = maListeIter->length();
312 if ( numberOfIter > 0 )
314 SALOME::ExceptionStruct es;
315 es.type = SALOME::BAD_PARAM;
316 es.text = "This hypothesis is used and cannot be deleted.";
317 throw SALOME::SALOME_Exception(es);
321 // suppression du lien avec les zones eventuelles
322 HOMARD::listeZonesHypo* maListe = myHypo->GetZones();
323 int numberOfZones = maListe->length();
324 MESSAGE ( ".. Nombre de zones = " << numberOfZones );
325 for (int NumeZone = 0; NumeZone< numberOfZones; NumeZone++)
327 std::string ZoneName = std::string((*maListe)[NumeZone]);
328 MESSAGE ( ".. suppression du lien avec la zone = " << ZoneName.c_str() );
329 DissociateHypoZone(nomHypo, ZoneName.c_str()) ;
333 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
334 myContextMap[GetCurrentStudyID()]._mesHypotheses.erase(nomHypo);
335 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomHypo, ComponentDataType());
336 SALOMEDS::SObject_var aSO =listSO[0];
337 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
338 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
342 //=============================================================================
343 CORBA::Long HOMARD_Gen_i::DeleteIteration(const char* nomIter, CORBA::Long Option)
345 // Option = 0 : On ne supprime pas le fichier du maillage associe
346 // Option = 1 : On supprime le fichier du maillage associe
347 // Option = 2 : On supprime le fichier du maillage associe, sauf si c'est la derniere iteration
348 // Pour detruire une iteration courante
349 MESSAGE ( "DeleteIteration : nomIter = " << nomIter << ", avec option = " << Option );
350 CORBA::Long Option1 = 1 ;
351 return DeleteIterationOption(nomIter, Option1, Option);
353 //=============================================================================
354 CORBA::Long HOMARD_Gen_i::DeleteIterationOption(const char* nomIter, CORBA::Long Option1, CORBA::Long Option2)
356 // Option1 = 0 : On autorise la destruction de l'iteration 0
357 // Option1 = 1 : On interdit la destruction de l'iteration 0
359 // Option2 = 0 : On ne supprime pas le fichier du maillage associe
360 // Option2 = 1 : On supprime le fichier du maillage associe
361 MESSAGE ( "DeleteIterationOption : nomIter = " << nomIter << ", avec options = " << Option1<< ", " << Option2 );
362 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
363 if (CORBA::is_nil(myIteration))
365 SALOME::ExceptionStruct es;
366 es.type = SALOME::BAD_PARAM;
367 es.text = "Invalid Iteration ";
368 throw SALOME::SALOME_Exception(es);
372 int numero = myIteration->GetNumber();
373 MESSAGE ( "DeleteIterationOption : numero = " << numero );
374 if ( numero == 0 and Option1 == 1 )
376 SALOME::ExceptionStruct es;
377 es.type = SALOME::BAD_PARAM;
378 es.text = "This iteration cannot be deleted.";
379 throw SALOME::SALOME_Exception(es);
383 // On detruit recursivement toutes les filles
384 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
385 int numberOfIter = maListe->length();
386 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
388 std::string nomIterFille = std::string((*maListe)[NumeIter]);
389 MESSAGE ( ".. appel recursif de DeleteIterationOption pour nomIter = " << nomIterFille.c_str() );
390 DeleteIterationOption(nomIterFille.c_str(), Option1, Option2);
393 // On arrive ici pour une iteration sans fille
394 MESSAGE ( "Destruction effective de " << nomIter );
395 // On commence par invalider l'iteration pour faire le menage des dependances
396 // et eventeullement du maillage associe
397 InvalideIterOption(nomIter, Option2) ;
399 // Retrait dans la descendance de l'iteration parent
402 const char* nomIterationParent = myIteration->GetIterParentName();
403 MESSAGE ( "Retrait dans la descendance de nomIterationParent " << nomIterationParent );
404 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
405 if (CORBA::is_nil(myIterationParent))
407 SALOME::ExceptionStruct es;
408 es.type = SALOME::BAD_PARAM;
409 es.text = "Invalid Iteration ";
410 throw SALOME::SALOME_Exception(es);
413 myIterationParent->UnLinkNextIteration(nomIter);
416 // suppression du lien avec l'hypothese
419 const char* nomHypo = myIteration->GetHypoName();
420 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
421 ASSERT(!CORBA::is_nil(myHypo));
422 myHypo->UnLinkIteration(nomIter);
425 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
426 myContextMap[GetCurrentStudyID()]._mesIterations.erase(nomIter);
427 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomIter, ComponentDataType());
428 SALOMEDS::SObject_var aSO =listSO[0];
429 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
430 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
431 // on peut aussi faire RemoveObject
432 // MESSAGE ( "Au final" );
433 // HOMARD::listeIterations* Liste = GetAllIterationsName() ;
434 // numberOfIter = Liste->length();
435 // for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
437 // std::string nomIterFille = std::string((*Liste)[NumeIter]);
438 // MESSAGE ( ".. nomIter = " << nomIterFille.c_str() );
443 //=============================================================================
444 CORBA::Long HOMARD_Gen_i::DeleteZone(const char* nomZone)
446 MESSAGE ( "DeleteZone : nomZone = " << nomZone );
447 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[nomZone];
448 if (CORBA::is_nil(myZone))
450 SALOME::ExceptionStruct es;
451 es.type = SALOME::BAD_PARAM;
452 es.text = "Invalid Zone ";
453 throw SALOME::SALOME_Exception(es);
457 // On verifie que la zone n'est plus utilisee
458 HOMARD::listeHypo* maListe = myZone->GetHypo();
459 int numberOfHypo = maListe->length();
460 MESSAGE ( ".. Nombre d'hypotheses = " << numberOfHypo );
461 if ( numberOfHypo > 0 )
463 SALOME::ExceptionStruct es;
464 es.type = SALOME::BAD_PARAM;
465 es.text = "This zone is used and cannot be deleted.";
466 throw SALOME::SALOME_Exception(es);
470 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
471 myContextMap[GetCurrentStudyID()]._mesZones.erase(nomZone);
472 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomZone, ComponentDataType());
473 SALOMEDS::SObject_var aSO =listSO[0];
474 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
475 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
479 //=============================================================================
480 //=============================================================================
482 //=============================================================================
483 //=============================================================================
484 // Invalidation des structures identifiees par leurs noms
485 //=============================================================================
486 //=============================================================================
487 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
489 MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName );
490 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
491 if (CORBA::is_nil(myBoundary))
493 SALOME::ExceptionStruct es;
494 es.type = SALOME::BAD_PARAM;
495 es.text = "Invalid Boundary ";
496 throw SALOME::SALOME_Exception(es);
501 SALOME::ExceptionStruct es;
502 es.type = SALOME::BAD_PARAM;
503 es.text = "No change is allowed in a boundary. Ask for evolution.";
504 throw SALOME::SALOME_Exception(es);
508 //=============================================================================
509 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
511 MESSAGE( "InvalideHypo : nomHypo = " << nomHypo );
512 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
513 if (CORBA::is_nil(myHypo))
515 SALOME::ExceptionStruct es;
516 es.type = SALOME::BAD_PARAM;
517 es.text = "Invalid Hypothesis ";
518 throw SALOME::SALOME_Exception(es);
522 HOMARD::listeIters* maListe = myHypo->GetIterations();
523 int numberOfIter = maListe->length();
524 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
526 std::string nomIter = std::string((*maListe)[NumeIter]);
527 MESSAGE( ".. nomIter = " << nomIter );
528 InvalideIter(nomIter.c_str());
531 //=============================================================================
532 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
534 MESSAGE("InvalideIter : nomIter = " << nomIter);
535 // Pour invalider totalement une iteration courante
536 CORBA::Long Option = 1 ;
537 return InvalideIterOption(nomIter, Option);
539 //=============================================================================
540 void HOMARD_Gen_i::InvalideIterOption(const char* nomIter, CORBA::Long Option)
542 // Option = 0 : On ne supprime pas le fichier du maillage associe
543 // Option = 1 : On supprime le fichier du maillage associe
544 MESSAGE ( "InvalideIterOption : nomIter = " << nomIter << ", avec option = " << Option );
545 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
546 if (CORBA::is_nil(myIteration))
548 SALOME::ExceptionStruct es;
549 es.type = SALOME::BAD_PARAM;
550 es.text = "Invalid Iteration ";
551 throw SALOME::SALOME_Exception(es);
555 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
556 int numberOfIter = maListe->length();
557 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
559 std::string nomIterFille = std::string((*maListe)[NumeIter]);
560 MESSAGE ( ".. appel recursif de InvalideIter pour nomIter = " << nomIterFille.c_str() );
561 InvalideIter(nomIterFille.c_str());
564 // On arrive ici pour une iteration sans fille
565 MESSAGE ( "Invalidation effective de " << nomIter );
566 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
567 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
568 for (; aIter->More(); aIter->Next())
570 SALOMEDS::SObject_var so = aIter->Value();
571 SALOMEDS::GenericAttribute_var anAttr;
572 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
573 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
574 std::string value (aCommentAttr->Value());
575 if(value == std::string("HypoHomard")) continue;
576 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
577 aStudyBuilder->RemoveObject(so);
580 int number = myIteration->GetNumber();
583 SetEtatIter(nomIter,false);
584 const char * nomCas = myIteration->GetCaseName();
585 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
586 if (CORBA::is_nil(myCase))
588 SALOME::ExceptionStruct es;
589 es.type = SALOME::BAD_PARAM;
590 es.text = "Invalid Case Context ";
591 throw SALOME::SALOME_Exception(es);
594 const char* dirCase = myCase->GetDirName();
595 const char* nomDir = myIteration->GetDirName();
596 const char* nomFichier = myIteration->GetMeshFile();
597 std::string commande= "rm -rf " + std::string(dirCase) + "/" + std::string(nomDir);
598 if ( Option == 1 ) { commande = commande + ";rm -rf " + std::string(nomFichier) ; }
599 MESSAGE ( "commande = " << commande );
600 if ((system(commande.c_str())) != 0)
602 SALOME::ExceptionStruct es;
603 es.type = SALOME::BAD_PARAM;
604 es.text = "Menage du repertoire de calcul impossible" ;
605 throw SALOME::SALOME_Exception(es);
608 // Suppression du maillage publie dans SMESH
609 const char* MeshName = myIteration->GetMeshName() ;
610 DeleteResultInSmesh(nomFichier, MeshName) ;
614 //=============================================================================
615 void HOMARD_Gen_i::InvalideIterInfo(const char* nomIter)
617 MESSAGE("InvalideIterInfo : nomIter = " << nomIter);
618 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
619 if (CORBA::is_nil(myIteration))
621 SALOME::ExceptionStruct es;
622 es.type = SALOME::BAD_PARAM;
623 es.text = "Invalid Iteration ";
624 throw SALOME::SALOME_Exception(es);
628 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
629 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
630 for (; aIter->More(); aIter->Next())
632 SALOMEDS::SObject_var so = aIter->Value();
633 SALOMEDS::GenericAttribute_var anAttr;
634 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
635 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
636 std::string value (aCommentAttr->Value());
637 /* MESSAGE("... value = " << value);*/
638 if( (value == std::string("logInfo")) or ( value == std::string("SummaryInfo")) )
640 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
641 aStudyBuilder->RemoveObject(so);
645 const char * nomCas = myIteration->GetCaseName();
646 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
647 if (CORBA::is_nil(myCase))
649 SALOME::ExceptionStruct es;
650 es.type = SALOME::BAD_PARAM;
651 es.text = "Invalid Case Context ";
652 throw SALOME::SALOME_Exception(es);
655 const char* dirCase = myCase->GetDirName();
656 const char* nomDir = myIteration->GetDirName();
657 std::string commande = "rm -f " + std::string(dirCase) + "/" + std::string(nomDir) + "/info* " ;
658 commande += std::string(dirCase) + "/" + std::string(nomDir) + "/Liste.*info" ;
659 /* MESSAGE ( "commande = " << commande );*/
660 if ((system(commande.c_str())) != 0)
662 SALOME::ExceptionStruct es;
663 es.type = SALOME::BAD_PARAM;
664 es.text = "Menage du repertoire de calcul impossible" ;
665 throw SALOME::SALOME_Exception(es);
670 //=============================================================================
671 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
673 MESSAGE( "InvalideZone : ZoneName = " << ZoneName );
674 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
675 if (CORBA::is_nil(myZone))
677 SALOME::ExceptionStruct es;
678 es.type = SALOME::BAD_PARAM;
679 es.text = "Invalid Zone ";
680 throw SALOME::SALOME_Exception(es);
683 HOMARD::listeHypo* maListe = myZone->GetHypo();
684 int numberOfHypo = maListe->length();
685 MESSAGE( ".. numberOfHypo = " << numberOfHypo );
686 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
688 std::string nomHypo = std::string((*maListe)[NumeHypo]);
689 MESSAGE( ".. nomHypo = " << nomHypo );
690 InvalideHypo(nomHypo.c_str());
693 //=============================================================================
694 //=============================================================================
696 //=============================================================================
697 //=============================================================================
698 // Association de lien entre des structures identifiees par leurs noms
699 //=============================================================================
700 //=============================================================================
701 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
703 MESSAGE( "AssociateCaseIter : " << nomCas << " ," << nomIter << "," << labelIter );
705 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
706 if (CORBA::is_nil(myCase))
708 SALOME::ExceptionStruct es;
709 es.type = SALOME::BAD_PARAM;
710 es.text = "Invalid Case ";
711 throw SALOME::SALOME_Exception(es);
715 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
716 if (CORBA::is_nil(myIteration))
718 SALOME::ExceptionStruct es;
719 es.type = SALOME::BAD_PARAM;
720 es.text = "Invalid iteration ";
721 throw SALOME::SALOME_Exception(es);
725 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
726 SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
727 if (CORBA::is_nil(aCasSO))
729 SALOME::ExceptionStruct es;
730 es.type = SALOME::BAD_PARAM;
731 es.text = "Invalid Case ";
732 throw SALOME::SALOME_Exception(es);
736 aStudyBuilder->NewCommand();
737 SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
738 PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
739 "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
740 aStudyBuilder->CommitCommand();
742 myCase->AddIteration(nomIter);
743 myIteration->SetCaseName(nomCas);
745 //=====================================================================================
746 void HOMARD_Gen_i::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
748 MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
750 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
751 ASSERT(!CORBA::is_nil(myHypo));
752 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
753 ASSERT(!CORBA::is_nil(aHypoSO));
755 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
756 ASSERT(!CORBA::is_nil(myZone));
757 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
758 ASSERT(!CORBA::is_nil(aZoneSO));
760 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
762 aStudyBuilder->NewCommand();
764 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
765 aStudyBuilder->Addreference(aSubSO, aZoneSO);
767 aStudyBuilder->CommitCommand();
769 myZone->AddHypo(nomHypothesis);
770 myHypo->AddZone0(ZoneName, TypeUse);
772 //=============================================================================
773 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
775 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
777 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
778 ASSERT(!CORBA::is_nil(myHypo));
779 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
780 ASSERT(!CORBA::is_nil(aHypoSO));
782 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
783 ASSERT(!CORBA::is_nil(myIteration));
784 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
785 ASSERT(!CORBA::is_nil(aIterSO));
787 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
789 aStudyBuilder->NewCommand();
791 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
792 aStudyBuilder->Addreference(aSubSO, aHypoSO);
794 aStudyBuilder->CommitCommand();
796 myIteration->SetHypoName(nomHypo);
797 myHypo->LinkIteration(nomIter);
799 //=============================================================================
800 //=============================================================================
802 //=============================================================================
803 //=============================================================================
804 // Dissociation de lien entre des structures identifiees par leurs noms
805 //=============================================================================
806 //=============================================================================
807 void HOMARD_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
809 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
811 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
812 ASSERT(!CORBA::is_nil(myHypo));
813 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
814 ASSERT(!CORBA::is_nil(aHypoSO));
816 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
817 ASSERT(!CORBA::is_nil(myZone));
818 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
819 ASSERT(!CORBA::is_nil(aZoneSO));
821 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
823 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator(aHypoSO);
824 for (; it->More(); it->Next())
826 SALOMEDS::SObject_var aHypObj = it->Value();
827 SALOMEDS::SObject_var ptrObj;
828 if (aHypObj->ReferencedObject(ptrObj))
830 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
832 aStudyBuilder->NewCommand();
833 aStudyBuilder->RemoveObject(aHypObj);
834 aStudyBuilder->CommitCommand();
840 myZone->SupprHypo(nomHypothesis);
841 myHypo->SupprZone(ZoneName);
843 //=============================================================================
844 //=============================================================================
847 //=============================================================================
848 //=============================================================================
849 // Recuperation des listes
850 //=============================================================================
851 //=============================================================================
852 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
854 MESSAGE("GetAllCasesName");
857 HOMARD::listeCases_var ret = new HOMARD::listeCases;
858 ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
859 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
861 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
862 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
864 ret[i++] = CORBA::string_dup((*it).first.c_str());
869 //=============================================================================
870 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
872 MESSAGE("GetAllHypothesesName");
875 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
876 ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
877 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
879 for (it = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
880 it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
882 ret[i++] = CORBA::string_dup((*it).first.c_str());
887 //=============================================================================
888 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
890 MESSAGE("GetAllZonesName");
893 HOMARD::listeZones_var ret = new HOMARD::listeZones;
894 ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
895 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
897 for (it = myContextMap[GetCurrentStudyID()]._mesZones.begin();
898 it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
900 ret[i++] = CORBA::string_dup((*it).first.c_str());
905 //=============================================================================
906 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
908 MESSAGE("GetAllIterationsName");
911 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
912 ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
913 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
915 for (it = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
916 it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
918 ret[i++] = CORBA::string_dup((*it).first.c_str());
923 //=============================================================================
924 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
926 MESSAGE("GetAllBoundarysName");
929 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
930 ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
931 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
933 for (it = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
934 it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
936 ret[i++] = CORBA::string_dup((*it).first.c_str());
941 //=============================================================================
942 //=============================================================================
944 //=============================================================================
945 //=============================================================================
946 // Recuperation des structures identifiees par leurs noms
947 //=============================================================================
948 //=============================================================================
949 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
951 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
952 ASSERT(!CORBA::is_nil(myCase));
953 return HOMARD::HOMARD_Cas::_duplicate(myCase);
955 //=============================================================================
956 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
958 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
959 ASSERT(!CORBA::is_nil(myZone));
960 return HOMARD::HOMARD_Zone::_duplicate(myZone);
962 //=============================================================================
963 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
965 HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
966 ASSERT(!CORBA::is_nil(myHypothesis));
967 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
969 //=============================================================================
970 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* NomIterationation)
972 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIterationation];
973 ASSERT(!CORBA::is_nil(myIteration));
974 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
976 //=============================================================================
977 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
979 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
980 ASSERT(!CORBA::is_nil(myBoundary));
981 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
983 //=============================================================================
984 //=============================================================================
986 //=============================================================================
987 //=============================================================================
989 //=============================================================================
990 //=============================================================================
991 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)
993 MESSAGE ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
994 MESSAGE ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte );
998 HOMARD::HOMARD_Cas_ptr myCase = CreateCase(nomCas, MeshName, MeshFile) ;
999 myCase->SetDirName(DirName) ;
1001 myCase->MeshInfo(Qual, Diam, Conn, Tail, Inte) ;
1005 //=============================================================================
1006 //=============================================================================
1008 //=============================================================================
1009 //=============================================================================
1010 // Recuperation des structures par le contexte
1011 //=============================================================================
1012 //=============================================================================
1013 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::LastIteration(const char* nomCas)
1015 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1016 ASSERT(!CORBA::is_nil(myCase));
1018 HOMARD::HOMARD_Iteration_var myIteration = myCase->LastIteration();
1019 ASSERT(!CORBA::is_nil(myIteration));
1021 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1023 //=============================================================================
1024 //=============================================================================
1026 //=============================================================================
1027 //=============================================================================
1028 // Nouvelles structures
1029 //=============================================================================
1030 //=============================================================================
1031 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1033 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1034 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
1035 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
1036 return aCase._retn();
1038 //=============================================================================
1039 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
1041 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1042 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
1043 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
1044 return aHypo._retn();
1046 //=============================================================================
1047 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
1049 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1050 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
1051 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
1052 return aIter._retn();
1054 //=============================================================================
1055 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1057 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1058 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
1059 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1060 return aBoundary._retn();
1062 //=============================================================================
1063 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
1065 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1066 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
1067 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
1068 return aZone._retn();
1070 //=============================================================================
1071 //=============================================================================
1073 //=============================================================================
1074 //=============================================================================
1075 // Creation des structures identifiees par leurs noms
1076 //=============================================================================
1077 //=============================================================================
1078 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
1080 MESSAGE ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1083 if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
1085 SALOME::ExceptionStruct es;
1086 es.type = SALOME::BAD_PARAM;
1087 es.text = "This case has already been defined";
1088 throw SALOME::SALOME_Exception(es);
1092 int existe = MEDFileExist ( MeshFile ) ;
1095 SALOME::ExceptionStruct es;
1096 es.type = SALOME::BAD_PARAM;
1097 es.text = "The mesh file does not exist.";
1098 throw SALOME::SALOME_Exception(es);
1102 HOMARD::HOMARD_Cas_var myCase = newCase();
1103 myCase->SetName(nomCas);
1104 SALOMEDS::SObject_var aSO;
1105 PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
1106 myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
1108 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile);
1109 HOMARD::extrema_var aSeq = new HOMARD::extrema();
1110 if (LesExtremes.size()!=10) { return false; }
1112 for (int i =0; i< LesExtremes.size(); i++)
1113 aSeq[i]=LesExtremes[i];
1114 myCase->SetBoundingBox(aSeq);
1116 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile);
1117 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType;
1118 aSeqGroupe->length(LesGroupes.size());
1119 std::set<std::string>::const_iterator it;
1121 for (it=LesGroupes.begin() ; it != LesGroupes.end(); it++)
1122 aSeqGroupe[i++]=(*it).c_str();
1123 myCase->SetGroups(aSeqGroupe);
1125 // Recherche d'un nom pour l'iteration 0. Par defaut, on prend le nom
1126 // du maillage du cas. Si ce nom existe deja, on incremente avec 0, 1, 2, etc.
1128 std::string NomIteration = std::string(MeshName) ;
1129 while ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()))
1131 std::ostringstream nom;
1132 nom << MeshName << monNum;
1133 NomIteration=nom.str();
1136 MESSAGE ( "CreateCase : NomIteration = " << NomIteration );
1138 HOMARD::HOMARD_Iteration_var anIter = newIteration();
1139 myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration] = anIter;
1140 std::ostringstream DirName;
1143 anIter->SetDirName(DirName.str().c_str());
1144 anIter->SetName(NomIteration.c_str());
1145 anIter->SetMeshFile(MeshFile);
1146 anIter->SetMeshName(MeshName);
1147 anIter->SetNumber(0);
1149 AssociateCaseIter (nomCas,NomIteration.c_str(),"IterationHomard");
1150 SetEtatIter(NomIteration.c_str(),true);
1152 PublishResultInSmesh(MeshFile, 0);
1154 // Valeurs par defaut des filtrages
1155 myCase->SetPyram(0);
1157 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1159 //=============================================================================
1160 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1162 MESSAGE ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1165 if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
1167 SALOME::ExceptionStruct es;
1168 es.type = SALOME::BAD_PARAM;
1169 es.text = "This hypothesis is already defined.";
1170 throw SALOME::SALOME_Exception(es);
1174 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1175 myHypothesis->SetName(nomHypothesis);
1176 myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
1177 SALOMEDS::SObject_var aSO;
1178 PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
1180 // Valeurs par defaut des options avancees
1181 myHypothesis->SetNivMax(-1);
1182 myHypothesis->SetDiamMin(-1.0);
1183 myHypothesis->SetAdapInit(0);
1184 myHypothesis->SetLevelOutput(0);
1186 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1189 //=============================================================================
1190 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1191 //=============================================================================
1193 MESSAGE ("CreateIteration : NomIteration = " << NomIteration << ", nomIterParent = " << nomIterParent);
1196 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
1197 if (CORBA::is_nil(myIterationParent))
1199 SALOME::ExceptionStruct es;
1200 es.type = SALOME::BAD_PARAM;
1201 es.text = "The parent iteration is not defined.";
1202 throw SALOME::SALOME_Exception(es);
1206 const char* nomCas = myIterationParent->GetCaseName();
1207 MESSAGE ("CreateIteration : nomCas = " << nomCas);
1208 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1209 if (CORBA::is_nil(myCase))
1211 SALOME::ExceptionStruct es;
1212 es.type = SALOME::BAD_PARAM;
1213 es.text = "Invalid Case Context ";
1214 throw SALOME::SALOME_Exception(es);
1218 if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
1220 SALOME::ExceptionStruct es;
1221 es.type = SALOME::BAD_PARAM;
1222 es.text = "This iteration is already defined. ";
1223 throw SALOME::SALOME_Exception(es);
1227 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1228 if (CORBA::is_nil(myIteration))
1230 SALOME::ExceptionStruct es;
1231 es.type = SALOME::BAD_PARAM;
1232 es.text = "Unable to create Iteration ";
1233 throw SALOME::SALOME_Exception(es);
1236 myContextMap[GetCurrentStudyID()]._mesIterations[std::string(NomIteration)] = myIteration;
1237 // Nom de l'iteration et du maillage
1238 myIteration->SetName(NomIteration);
1239 myIteration->SetMeshName(NomIteration);
1241 int numero = myIterationParent->GetNumber() + 1;
1242 myIteration->SetNumber(numero);
1244 // Nombre d'iterations deja connues pour le cas, permettant
1245 // la creation d'un sous-repertoire unique
1246 int nbitercase = myCase->GetNumber();
1247 std::ostringstream iaux ;
1248 iaux << std::setw(2) << std::setfill('0') << nbitercase ;
1249 std::stringstream DirName;
1250 DirName << "I" << iaux.str();
1251 myIteration->SetDirName(DirName.str().c_str());
1253 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1254 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1255 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1256 // situation la plus frequente.
1257 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1258 // le nombre d'iterations du cas permet d'eviter les collisions.
1259 std::stringstream MeshFile;
1260 const char* nomDir = myCase->GetDirName();
1261 MeshFile << nomDir << "/maill." << iaux.str() << ".med";
1262 myIteration->SetMeshFile(MeshFile.str().c_str());
1264 // Association avec le cas
1265 std::string label = "IterationHomard_" + std::string(nomIterParent);
1266 AssociateCaseIter(nomCas, NomIteration, label.c_str());
1267 // Lien avec l'iteration precedente
1268 myIterationParent->LinkNextIteration(NomIteration);
1269 myIteration->SetIterParentName(nomIterParent);
1271 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1273 //=============================================================================
1274 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1276 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1279 if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
1281 SALOME::ExceptionStruct es;
1282 es.type = SALOME::BAD_PARAM;
1283 es.text = "This boundary has already been defined";
1284 throw SALOME::SALOME_Exception(es);
1288 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1289 myBoundary->SetName(BoundaryName);
1290 myBoundary->SetType(BoundaryType);
1292 myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
1294 SALOMEDS::SObject_var aSO;
1295 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
1297 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1299 //=============================================================================
1300 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1302 MESSAGE ("CreateBoundaryDi : BoundaryName = " << BoundaryName << "MeshName = " << MeshName );
1303 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1304 myBoundary->SetMeshFile( MeshFile ) ;
1305 myBoundary->SetMeshName( MeshName ) ;
1307 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1309 //=============================================================================
1310 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1311 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1312 CORBA::Double Xaxis, CORBA::Double Yaxis, CORBA::Double Zaxis,
1313 CORBA::Double Rayon)
1315 MESSAGE ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
1316 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1317 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxis, Yaxis, Zaxis, Rayon ) ;
1319 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1321 //=============================================================================
1322 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1323 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1324 CORBA::Double Rayon)
1326 MESSAGE ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
1327 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1328 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1330 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1332 //=============================================================================
1333 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
1335 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
1338 if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
1340 SALOME::ExceptionStruct es;
1341 es.type = SALOME::BAD_PARAM;
1342 es.text = "This zone has already been defined";
1343 throw SALOME::SALOME_Exception(es);
1347 HOMARD::HOMARD_Zone_var myZone = newZone();
1348 myZone->SetName(ZoneName);
1349 myZone->SetType(ZoneType);
1351 myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
1353 SALOMEDS::SObject_var aSO;
1354 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
1356 return HOMARD::HOMARD_Zone::_duplicate(myZone);
1358 //=============================================================================
1359 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
1360 CORBA::Double Xmini, CORBA::Double Xmaxi,
1361 CORBA::Double Ymini, CORBA::Double Ymaxi,
1362 CORBA::Double Zmini, CORBA::Double Zmaxi)
1364 MESSAGE ("CreateZoneBox : ZoneName = " << ZoneName ) ;
1365 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
1366 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
1368 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1370 //=============================================================================
1371 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
1372 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
1374 MESSAGE ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
1375 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
1376 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1378 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1380 //=============================================================================
1381 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
1382 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1383 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1384 CORBA::Double Rayon, CORBA::Double Haut)
1386 MESSAGE ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
1387 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
1388 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
1390 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1392 //=============================================================================
1393 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
1394 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1395 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1396 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
1398 MESSAGE ("CreateZonePipe : ZoneName = " << ZoneName ) ;
1399 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
1400 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
1402 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1404 //=============================================================================
1405 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
1406 CORBA::Double Umini, CORBA::Double Umaxi,
1407 CORBA::Double Vmini, CORBA::Double Vmaxi,
1410 MESSAGE ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
1411 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
1412 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
1413 // MESSAGE ("Orient = " << Orient ) ;
1415 double Xmini, Xmaxi ;
1416 double Ymini, Ymaxi ;
1417 double Zmini, Zmaxi ;
1425 else if ( Orient == 2 )
1432 else if ( Orient == 3 )
1439 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
1441 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
1442 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
1444 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1446 //=============================================================================
1447 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
1448 CORBA::Double Ucentre, CORBA::Double Vcentre,
1449 CORBA::Double Rayon,
1452 MESSAGE ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
1457 { Xcentre = Ucentre ;
1460 else if ( Orient == 2 )
1463 Zcentre = Vcentre ; }
1464 else if ( Orient == 3 )
1465 { Xcentre = Vcentre ;
1467 Zcentre = Ucentre ; }
1468 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
1470 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
1471 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
1473 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1475 //=============================================================================
1476 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
1477 CORBA::Double Ucentre, CORBA::Double Vcentre,
1478 CORBA::Double Rayon, CORBA::Double Rayonint,
1481 MESSAGE ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
1486 { Xcentre = Ucentre ;
1489 else if ( Orient == 2 )
1492 Zcentre = Vcentre ; }
1493 else if ( Orient == 3 )
1494 { Xcentre = Vcentre ;
1496 Zcentre = Ucentre ; }
1497 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
1499 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
1500 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
1502 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1504 //=============================================================================
1505 //=============================================================================
1510 //=============================================================================
1511 //=============================================================================
1512 // Traitement d'une iteration
1513 // etatMenage = 1 : destruction du repertoire d'execution
1514 // modeHOMARD = 1 : adaptation
1515 // != 1 : information avec les options modeHOMARD
1516 // Option >0 : appel depuis python
1517 // <0 : appel depuis GUI
1518 //=============================================================================
1519 //=============================================================================
1520 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option)
1522 MESSAGE ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", avec Option = " << Option );
1527 // A.1. L'objet iteration
1528 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
1529 ASSERT(!CORBA::is_nil(myIteration));
1531 // A.2. Numero de l'iteration
1532 // siterp1 : numero de l'iteration a traiter
1534 // siter : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
1535 // Ou si information :
1537 int NumeIter = myIteration->GetNumber();
1538 std::string siterp1 ;
1539 std::stringstream saux1 ;
1541 siterp1 = saux1.str() ;
1542 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
1545 if ( modeHOMARD==1 )
1547 std::stringstream saux0 ;
1548 int iaux = max(0, NumeIter-1) ;
1550 siter = saux0.str() ;
1551 if (NumeIter < 11) { siter = "0" + siter ; }
1554 { siter = siterp1 ; }
1557 const char* nomCas = myIteration->GetCaseName();
1558 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1559 ASSERT(!CORBA::is_nil(myCase));
1561 // B. Les repertoires
1562 // B.1. Le repertoire courant
1563 char* nomDirWork = getenv("PWD") ;
1564 // B.2. Le sous-repertoire de l'iteration a traiter
1565 char* DirCompute = ComputeDir(myCase, myIteration, etatMenage);
1566 MESSAGE( ". DirCompute = " << DirCompute );
1568 // C. Le fichier des messages
1569 // C.1. Le deroulement de l'execution de HOMARD
1570 std::string LogFile = DirCompute ;
1571 LogFile += "/Liste" ;
1572 if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
1574 MESSAGE (". LogFile = " << LogFile);
1575 if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
1576 // C.2. Le bilan de l'analyse du maillage
1577 std::string FileInfo = DirCompute ;
1579 if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
1581 { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
1582 else { FileInfo += "info_ap" ; }
1584 FileInfo += "." + siterp1 + ".bilan" ;
1585 myIteration->SetFileInfo(FileInfo.c_str());
1587 // D. On passe dans le repertoire de l'iteration a calculer
1588 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
1591 // E. Les donnees de l'execution HOMARD
1592 // E.1. L'objet du texte du fichier de configuration
1593 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
1594 myDriver->TexteInit(DirCompute, LogFile);
1596 // E.2. Le maillage associe a l'iteration
1597 const char* NomMesh = myIteration->GetMeshName();
1598 MESSAGE ( ". NomMesh = " << NomMesh );
1599 const char* MeshFile = myIteration->GetMeshFile();
1600 MESSAGE ( ". MeshFile = " << MeshFile );
1602 // E.3. Les donnees du traitement HOMARD
1604 if ( modeHOMARD == 1 )
1607 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
1608 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
1609 codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option) ;
1613 InvalideIterInfo(NomIteration);
1614 myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
1616 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
1617 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
1618 myDriver->CreeFichierDonn();
1621 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
1622 DriverTexteBoundary(myCase, myDriver) ;
1624 // E.5. Ecriture du texte dans le fichier
1626 { myDriver->CreeFichier(); }
1630 int codretexec = 12 ;
1633 codretexec = myDriver->ExecuteHomard(Option);
1635 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
1636 if ( modeHOMARD == 1 )
1638 if (codretexec == 0) { SetEtatIter(NomIteration,true); }
1639 else { SetEtatIter(NomIteration,false); }
1640 // GERALD -- QMESSAGE BOX
1644 // H. Gestion des resultats
1647 std::string Commentaire ;
1648 // H.1. Le fichier des messages, dans tous les cas
1649 Commentaire = "log" ;
1650 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
1651 else { Commentaire += "Info" ; }
1652 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
1654 // H.2. Si tout s'est bien passe :
1655 if (codretexec == 0)
1657 // H.2.1. Le fichier de bilan
1658 Commentaire = "Summary" ;
1659 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
1660 else { Commentaire += "Info" ; }
1661 PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
1662 // H.2.2. Le fichier de maillage obtenu
1663 if ( modeHOMARD == 1 )
1665 std::stringstream saux0 ;
1666 Commentaire = "Iteration" ;
1667 Commentaire += " " + siter ;
1668 PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
1669 PublishResultInSmesh(MeshFile, 1);
1672 // H.3 Message d'erreur en cas de probleme
1675 SALOME::ExceptionStruct es;
1676 es.type = SALOME::BAD_PARAM;
1677 std::string text = "Error during the adaptation.\n" ;
1680 ifstream fichier(LogFile.c_str(), ios::in);
1682 while(getline(fichier, ligne) and (ligne != "===== HOMARD ===== STOP ====="));
1683 while (getline(fichier, ligne)) { text += ligne+ "\n";};
1686 text += "no log file ....";
1688 es.text = CORBA::string_dup(text.c_str());
1689 throw SALOME::SALOME_Exception(es);
1693 // I. Menage et retour dans le repertoire du cas
1697 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
1703 //=============================================================================
1704 // Calcul d'une iteration : partie specifique a l'adaptation
1705 //=============================================================================
1706 CORBA::Long HOMARD_Gen_i::ComputeAdap(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage, HomardDriver* myDriver, CORBA::Long Option)
1708 MESSAGE ( "ComputeAdap" );
1713 // Numero de l'iteration
1714 int NumeIter = myIteration->GetNumber();
1715 std::stringstream saux0 ;
1716 saux0 << NumeIter-1 ;
1717 std::string siter = saux0.str() ;
1718 if (NumeIter < 11) { siter = "0" + siter ; }
1720 // A.2. On ne calcule pas l iteration 0
1721 if ( NumeIter == 0 )
1723 SALOME::ExceptionStruct es;
1724 es.type = SALOME::BAD_PARAM;
1725 es.text = "This iteration is the first of the case and cannot be computed.";
1726 throw SALOME::SALOME_Exception(es);
1730 // A.3. On verifie qu il y a une hypothese (erreur improbable);
1731 const char* nomHypo = myIteration->GetHypoName();
1732 if (std::string(nomHypo) == std::string(""))
1734 SALOME::ExceptionStruct es;
1735 es.type = SALOME::BAD_PARAM;
1736 es.text= "This iteration does not have any associated hypothesis.";
1737 throw SALOME::SALOME_Exception(es);
1740 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
1741 ASSERT(!CORBA::is_nil(myHypo));
1743 // B. L'iteration parent
1744 const char* nomIterationParent = myIteration->GetIterParentName();
1745 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
1746 ASSERT(!CORBA::is_nil(myIterationParent));
1747 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
1748 if ( ! myIterationParent->GetEtat() )
1751 int codret = Compute(nomIterationParent, etatMenage, iaux, Option);
1754 // GERALD -- QMESSAGE BOX
1755 ASSERT("Pb au calcul de l'iteration precedente" == 0);
1759 // C. Le sous-repertoire de l'iteration precedente
1760 char* DirComputePa = ComputeDirPa(myCase, myIteration);
1761 MESSAGE( ". DirComputePa = " << DirComputePa );
1763 // D. Les donnees de l'adaptation HOMARD
1764 // D.1. Le type de conformite
1765 int ConfType = myCase->GetConfType();
1766 MESSAGE ( ". ConfType = " << ConfType );
1768 // D.2. Le maillage de depart
1769 const char* NomMeshParent = myIterationParent->GetMeshName();
1770 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
1771 const char* MeshFileParent = myIterationParent->GetMeshFile();
1772 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
1774 // D.3. Le maillage associe a l'iteration
1775 const char* MeshFile = myIteration->GetMeshFile();
1776 MESSAGE ( ". MeshFile = " << MeshFile );
1777 FILE *file = fopen(MeshFile,"r");
1781 if (etatMenage == 0)
1783 SALOME::ExceptionStruct es;
1784 es.type = SALOME::BAD_PARAM;
1785 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
1786 es.text = CORBA::string_dup(text.c_str());
1787 throw SALOME::SALOME_Exception(es);
1792 std::string commande = "rm -f " + std::string(MeshFile);
1793 codret = system(commande.c_str());
1796 SALOME::ExceptionStruct es;
1797 es.type = SALOME::BAD_PARAM;
1798 std::string text = "PB with meshfile destruction ";
1799 es.text = CORBA::string_dup(text.c_str());
1800 throw SALOME::SALOME_Exception(es);
1806 // D.4. Les types de raffinement et de deraffinement
1807 // Les appels corba sont lourds, il vaut mieux les grouper
1808 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
1809 ASSERT(ListTypes->length() == 3);
1810 int TypeAdap = (*ListTypes)[0];
1811 int TypeRaff = (*ListTypes)[1];
1812 int TypeDera = (*ListTypes)[2];
1814 // E. Texte du fichier de configuration
1815 // E.1. Incontournables du texte
1816 myDriver->TexteAdap();
1818 myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
1819 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
1820 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
1822 // E.2. Ajout des informations liees aux zones eventuelles
1823 if ( TypeAdap == 0 )
1824 { DriverTexteZone(myHypo, myDriver) ; }
1826 // E.3. Ajout des informations liees aux champs eventuels
1827 if ( TypeAdap == 1 )
1828 { DriverTexteField(myIteration, myHypo, myDriver) ; }
1830 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
1831 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
1832 int numberOfGroups = listeGroupes->length();
1833 MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
1834 if (numberOfGroups > 0)
1836 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
1838 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
1839 MESSAGE( "... GroupName = " << GroupName );
1840 myDriver->TexteGroup(GroupName);
1844 // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
1845 DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
1847 // E.6. Ajout des options avancees
1848 int Pyram = myCase->GetPyram();
1849 MESSAGE ( ". Pyram = " << Pyram );
1850 int NivMax = myHypo->GetNivMax();
1851 MESSAGE ( ". NivMax = " << NivMax );
1852 double DiamMin = myHypo->GetDiamMin() ;
1853 MESSAGE ( ". DiamMin = " << DiamMin );
1854 int AdapInit = myHypo->GetAdapInit();
1855 MESSAGE ( ". AdapInit = " << AdapInit );
1856 int LevelOutput = myHypo->GetLevelOutput();
1857 MESSAGE ( ". LevelOutput = " << LevelOutput );
1858 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
1862 //=============================================================================
1863 // Calcul d'une iteration : gestion du repertoire de calcul
1864 // Si le sous-repertoire existe :
1865 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
1866 // etatMenage = 1 : on fait le menage du repertoire
1867 // etatMenage = -1 : on ne fait rien
1868 //=============================================================================
1869 char* HOMARD_Gen_i::ComputeDir(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
1871 MESSAGE ( "ComputeDir : repertoires pour le calcul" );
1872 // B.2. Le repertoire du cas
1873 const char* nomDirCase = myCase->GetDirName();
1874 MESSAGE ( ". nomDirCase = " << nomDirCase );
1876 // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
1877 // B.3.1. Le nom du sous-repertoire
1878 const char* nomDirIt = myIteration->GetDirName();
1880 // B.3.2. Le nom complet du sous-repertoire
1881 std::stringstream DirCompute ;
1882 DirCompute << nomDirCase << "/" << nomDirIt;
1883 MESSAGE (". DirCompute = " << DirCompute.str() );
1885 // B.3.3. Si le sous-repertoire n'existe pas, on le cree
1886 if (chdir(DirCompute.str().c_str()) != 0)
1888 // Creation du repertoire car il n'existe pas :
1889 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1891 // GERALD -- QMESSAGE BOX
1892 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
1893 ASSERT("Pb a la creation du repertoire" == 0);
1898 // Le repertoire existe
1899 // On demande de faire le menage de son contenu :
1900 if (etatMenage == 1)
1902 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
1903 std::string commande= "rm -rf " + DirCompute.str()+"/*" ;
1904 int codret = system(commande.c_str());
1907 // GERALD -- QMESSAGE BOX
1908 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
1909 ASSERT("Pb au menage du repertoire de calcul" == 0);
1912 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
1915 if (etatMenage == 0)
1918 struct dirent *dirp;
1919 dp = opendir(DirCompute.str().c_str());
1921 while ((dirp = readdir(dp)) != NULL && result )
1923 std::string file_name(dirp->d_name);
1924 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
1927 if ( result == false)
1929 SALOME::ExceptionStruct es;
1930 es.type = SALOME::BAD_PARAM;
1931 std::string text = "Directory : " + DirCompute.str() + "is not empty";
1932 es.text = CORBA::string_dup(text.c_str());
1933 throw SALOME::SALOME_Exception(es);
1934 ASSERT("Directory is not empty" == 0);
1940 return CORBA::string_dup( DirCompute.str().c_str() );
1942 //=============================================================================
1943 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
1944 //=============================================================================
1945 char* HOMARD_Gen_i::ComputeDirPa(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
1947 MESSAGE ( "ComputeDirPa : repertoires pour le calcul" );
1948 // Le repertoire du cas
1949 const char* nomDirCase = myCase->GetDirName();
1950 MESSAGE ( ". nomDirCase = " << nomDirCase );
1952 // Le sous-repertoire de l'iteration precedente
1954 const char* nomIterationParent = myIteration->GetIterParentName();
1955 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
1956 const char* nomDirItPa = myIterationParent->GetDirName();
1957 std::stringstream DirComputePa ;
1958 DirComputePa << nomDirCase << "/" << nomDirItPa;
1959 MESSAGE( ". nomDirItPa = " << nomDirItPa);
1960 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
1962 return CORBA::string_dup( DirComputePa.str().c_str() );
1964 //=============================================================================
1965 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
1966 //=============================================================================
1967 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
1969 MESSAGE ( "... DriverTexteZone" );
1970 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
1971 int numberOfZonesx2 = ListZone->length();
1974 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
1976 std::string ZoneName = std::string((*ListZone)[iaux]);
1977 MESSAGE ( "... ZoneName = " << ZoneName);
1978 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1979 ASSERT(!CORBA::is_nil(myZone));
1981 int ZoneType = myZone->GetType();
1982 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
1983 int TypeUse = atoi( TypeUsestr.c_str() );
1984 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
1985 NumZone = iaux/2 + 1 ;
1986 HOMARD::double_array* zone = myZone->GetCoords();
1987 if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
1989 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.);
1991 else if ( ZoneType == 4 ) // Cas d une sphere
1993 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.);
1995 else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
1997 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.);
1999 else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
2001 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]);
2003 else { ASSERT("ZoneType est incorrect." == 0) ; }
2008 //=============================================================================
2009 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
2010 //=============================================================================
2011 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2013 MESSAGE ( "... DriverTexteField" );
2014 // Le fichier du champ
2015 char* FieldFile = myIteration->GetFieldFile();
2016 MESSAGE ( ". FieldFile = " << FieldFile );
2017 if (strlen(FieldFile) == 0)
2019 // GERALD -- QMESSAGE BOX
2020 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
2021 ASSERT("The file for the field is not given." == 0);
2023 // Les caracteristiques d'instants
2024 int TimeStep = myIteration->GetTimeStep();
2025 MESSAGE( ". TimeStep = " << TimeStep );
2026 int Rank = myIteration->GetRank();
2027 MESSAGE( ". Rank = " << Rank );
2028 // Les informations sur les champ
2029 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
2031 const char* FieldName = aInfosHypo->FieldName;
2033 int TypeThR = aInfosHypo->TypeThR;
2034 double ThreshR = aInfosHypo->ThreshR;
2035 int TypeThC = aInfosHypo->TypeThC;
2036 double ThreshC = aInfosHypo->ThreshC;
2037 // Saut entre mailles ou non ?
2038 int UsField = aInfosHypo->UsField;
2039 MESSAGE( ". UsField = " << UsField );
2040 // L'usage des composantes
2041 int UsCmpI = aInfosHypo->UsCmpI;
2042 MESSAGE( ". UsCmpI = " << UsCmpI );
2044 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
2047 HOMARD::listeComposantsHypo* mescompo = myHypo->GetListComp();
2048 int numberOfCompos = mescompo->length();
2049 MESSAGE( ". numberOfCompos = " << numberOfCompos );
2050 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
2052 std::string nomCompo = std::string((*mescompo)[NumeComp]);
2053 MESSAGE( "... nomCompo = " << nomCompo );
2054 myDriver->TexteCompo(NumeComp, nomCompo);
2058 //=============================================================================
2059 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
2060 //=============================================================================
2061 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
2063 MESSAGE ( "... DriverTexteBoundary" );
2064 // On ecrit d'abord la definition des frontieres, puis les liens avec les groupes
2065 std::list<std::string> ListeBoundaryTraitees ;
2066 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2067 int numberOfitems = ListBoundaryGroupType->length();
2068 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
2069 int BoundaryOption = 1 ;
2070 int NumBoundaryAnalytical = 0 ;
2071 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2073 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2074 MESSAGE ( "... BoundaryName = " << BoundaryName);
2076 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
2077 while (it != ListeBoundaryTraitees.end())
2079 MESSAGE ( "... BoundaryNameTraitee = " << *it);
2080 if ( BoundaryName == *it ) { A_faire = 0 ; }
2085 // Caracteristiques de la frontiere
2086 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2087 ASSERT(!CORBA::is_nil(myBoundary));
2088 int BoundaryType = myBoundary->GetType();
2089 MESSAGE ( "... BoundaryType = " << BoundaryType );
2090 // Ecriture selon le type
2091 if (BoundaryType == 0) // Cas d une frontiere discrete
2093 const char* MeshName = myBoundary->GetMeshName() ;
2094 const char* MeshFile = myBoundary->GetMeshFile() ;
2095 myDriver->TexteBoundaryDi( MeshName, MeshFile);
2096 BoundaryOption = BoundaryOption*2 ;
2098 else // Cas d une frontiere analytique
2100 NumBoundaryAnalytical++ ;
2101 HOMARD::double_array* coor = myBoundary->GetCoords();
2102 if (BoundaryType == 1) // Cas d un cylindre
2104 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6]);
2105 BoundaryOption = BoundaryOption*3 ;
2107 else if (BoundaryType == 2) // Cas d une sphere
2109 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0.);
2110 BoundaryOption = BoundaryOption*3 ;
2113 // Memorisation du traitement
2114 ListeBoundaryTraitees.push_back( BoundaryName );
2117 NumBoundaryAnalytical = 0 ;
2118 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2120 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2121 MESSAGE ( "... BoundaryName = " << BoundaryName);
2122 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2123 ASSERT(!CORBA::is_nil(myBoundary));
2124 int BoundaryType = myBoundary->GetType();
2125 MESSAGE ( "... BoundaryType = " << BoundaryType );
2126 // Recuperation du nom du groupe
2127 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
2128 MESSAGE ( "... GroupName = " << GroupName);
2129 if (BoundaryType == 0) // Cas d une frontiere discrete
2131 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
2133 else // Cas d une frontiere analytique
2135 NumBoundaryAnalytical++ ;
2136 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
2139 myDriver->TexteBoundaryOption(BoundaryOption);
2142 //=============================================================================
2143 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
2144 //=============================================================================
2145 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2147 MESSAGE ( "... DriverTexteFieldInterp" );
2148 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
2149 if (TypeFieldInterp != 0)
2151 // Le fichier des champs
2152 char* FieldFile = myIteration->GetFieldFile();
2153 MESSAGE ( ". FieldFile = " << FieldFile );
2154 if (strlen(FieldFile) == 0)
2156 // GERALD -- QMESSAGE BOX
2157 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
2158 ASSERT("The file for the field is not given." == 0);
2160 // Les caracteristiques d'instants
2161 int TimeStep = myIteration->GetTimeStep();
2162 MESSAGE( ". TimeStep = " << TimeStep );
2163 int Rank = myIteration->GetRank();
2164 MESSAGE( ". Rank = " << Rank );
2166 const char* MeshFile = myIteration->GetMeshFile();
2167 myDriver->TexteFieldInterp(TypeFieldInterp, FieldFile, MeshFile, TimeStep, Rank);
2169 if (TypeFieldInterp == 2)
2171 HOMARD::listFieldInterpHypo* meschamps = myHypo->GetListFieldInterp();
2172 int numberOfFields = meschamps->length();
2173 MESSAGE( ". numberOfFields = " << numberOfFields );
2174 for (int NumeChamp = 0; NumeChamp< numberOfFields; NumeChamp++)
2176 std::string nomChamp = std::string((*meschamps)[NumeChamp]);
2177 MESSAGE( "... nomChamp = " << nomChamp );
2178 myDriver->TexteFieldInterpName(NumeChamp, nomChamp);
2184 //===========================================================================
2185 //===========================================================================
2188 //===========================================================================
2189 //===========================================================================
2191 //===========================================================================
2192 //===========================================================================
2193 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
2194 SALOMEDS::SObject_ptr theSObject,
2195 CORBA::Object_ptr theObject,
2196 const char* theName)
2198 MESSAGE("PublishInStudy pour " << theName);
2199 SALOMEDS::SObject_var aResultSO;
2200 if (CORBA::is_nil(theStudy))
2202 SALOME::ExceptionStruct es;
2203 es.type = SALOME::BAD_PARAM;
2204 es.text = "Invalid Study Context ";
2205 throw SALOME::SALOME_Exception(es);
2209 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
2210 // Rq : Iteration est publiee ailleurs
2211 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
2212 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
2213 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
2214 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
2216 addInStudy(theStudy);
2218 // Controle de la non publication d'un objet de meme nom
2219 if ((!aHypo->_is_nil()) or (!aZone->_is_nil()) or (!aBoundary->_is_nil()))
2221 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
2222 if (listSO->length() >= 1)
2224 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
2225 std::cerr <<"This name "<<theName<<" is already used "<<listSO->length()<<" time(s)" << std::endl;
2226 aResultSO = listSO[0];
2227 return aResultSO._retn();
2231 // Caracteristiques de l'etude
2232 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
2233 aStudyBuilder->NewCommand();
2234 if(!aCase->_is_nil())
2235 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
2236 else if(!aHypo->_is_nil())
2237 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
2238 else if(!aZone->_is_nil())
2239 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
2240 else if(!aBoundary->_is_nil())
2241 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
2243 aStudyBuilder->CommitCommand();
2244 return aResultSO._retn();
2246 //=============================================================================
2247 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
2248 SALOMEDS::StudyBuilder_var aStudyBuilder,
2249 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
2251 MESSAGE("PublishCaseInStudy pour "<<theName);
2252 SALOMEDS::SObject_var aResultSO;
2253 SALOMEDS::GenericAttribute_var anAttr;
2255 if (CORBA::is_nil(theObject)) {
2256 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
2257 return aResultSO._retn();
2259 if (theStudy->_is_nil()) {
2260 MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
2261 return aResultSO._retn();
2264 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2265 if (theFatherHomard->_is_nil())
2267 MESSAGE("theFatherHomard->_is_nil()");
2268 return aResultSO._retn();
2271 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
2272 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
2273 _orb->object_to_string(theObject) ) ;
2274 return aResultSO._retn();
2277 //=============================================================================
2278 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
2279 SALOMEDS::StudyBuilder_var aStudyBuilder,
2280 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
2282 MESSAGE("PublishZoneStudy pour "<<theName);
2283 SALOMEDS::SObject_var aResultSO;
2284 SALOMEDS::GenericAttribute_var anAttr;
2286 if (CORBA::is_nil(theObject))
2288 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
2289 return aResultSO._retn();
2291 if (theStudy->_is_nil())
2293 MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
2294 return aResultSO._retn();
2296 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2297 if (theFatherHomard->_is_nil())
2299 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
2300 return aResultSO._retn();
2303 // Caracteristique de la zone
2304 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
2305 CORBA::Long ZoneType = myZone->GetType();
2307 // On ajoute la categorie des zones dans l etude si necessaire
2308 SALOMEDS::SObject_var aSOZone;
2309 if (!theFatherHomard->FindSubObject(100, aSOZone))
2311 MESSAGE("Ajout de la categorie des zones");
2312 aSOZone = aStudyBuilder->NewObjectToTag(theFatherHomard, 100);
2313 PublishInStudyAttr(aStudyBuilder, aSOZone, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
2315 else { MESSAGE("La categorie des zones existe deja."); }
2317 aResultSO = aStudyBuilder->NewObject(aSOZone);
2326 { icone = "boxdxy_2.png" ;
2330 { icone = "boxdxyz_2.png" ;
2338 { icone = "disk_2.png" ;
2342 { icone = "spherepoint_2.png" ;
2346 { icone = "cylinderpointvector_2.png" ;
2354 { icone = "diskwithhole_2.png" ;
2358 { icone = "pipe_2.png" ;
2362 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone, _orb->object_to_string(theObject) ) ;
2364 return aResultSO._retn();
2366 //=============================================================================
2367 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
2368 SALOMEDS::StudyBuilder_var aStudyBuilder,
2369 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
2371 MESSAGE("PublishBoundaryStudy pour "<<theName);
2372 SALOMEDS::SObject_var aResultSO;
2373 SALOMEDS::GenericAttribute_var anAttr;
2375 // Caracteristique de la Boundary
2376 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
2378 // On recupere le module pere dans l etude
2379 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2380 if (theFatherHomard->_is_nil())
2382 MESSAGE("theFatherHomard->_is_nil()");
2383 return aResultSO._retn();
2386 // On ajoute la categorie des boundarys dans l etude si necessaire
2387 SALOMEDS::SObject_var aSOBoundary;
2388 if (!theFatherHomard->FindSubObject(101, aSOBoundary))
2390 MESSAGE("Ajout de la categorie des boundarys");
2391 aSOBoundary = aStudyBuilder->NewObjectToTag(theFatherHomard, 101);
2392 PublishInStudyAttr(aStudyBuilder, aSOBoundary, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
2394 else { MESSAGE("La categorie des boundarys existe deja."); }
2396 aResultSO = aStudyBuilder->NewObject(aSOBoundary);
2397 CORBA::Long BoundaryType = myBoundary->GetType();
2398 // MESSAGE("BoundaryType : "<<BoundaryType);
2401 switch (BoundaryType)
2404 { value = "BoundaryDiHomard" ;
2405 icone = "mesh_tree_mesh.png" ;
2409 { value = "BoundaryAnHomard" ;
2410 icone = "cylinderpointvector_2.png" ;
2414 { value = "BoundaryAnHomard" ;
2415 icone = "spherepoint_2.png" ;
2419 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value, icone, _orb->object_to_string(theObject));
2420 return aResultSO._retn();
2423 //=============================================================================
2424 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
2425 SALOMEDS::StudyBuilder_var aStudyBuilder,
2426 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
2428 MESSAGE("PublishHypotheseInStudy pour "<<theName);
2429 SALOMEDS::SObject_var aResultSO;
2430 SALOMEDS::GenericAttribute_var anAttr;
2432 // On recupere le module pere dans l etude
2433 // On ajoute la categorie des hypotheses dans l etude si necessaire
2434 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2435 if (theFatherHomard->_is_nil())
2437 MESSAGE("theFatherHomard->_is_nil()");
2438 return aResultSO._retn();
2440 SALOMEDS::SObject_var aSOHypothese;
2441 if (!theFatherHomard->FindSubObject(0, aSOHypothese))
2443 MESSAGE("Ajout de la categorie des hypotheses");
2444 aSOHypothese = aStudyBuilder->NewObjectToTag(theFatherHomard, 0);
2445 PublishInStudyAttr(aStudyBuilder, aSOHypothese, "Hypothesis", "HypoList","hypotheses.png", NULL);
2447 else { MESSAGE("La categorie des hypotheses existe deja."); }
2449 // Creation du resultat dans l'etude
2450 aResultSO = aStudyBuilder->NewObject(aSOHypothese);
2451 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
2453 return aResultSO._retn();
2455 //===========================================================================
2456 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
2457 SALOMEDS::SObject_var aResultSO,
2458 const char* name, const char* value, const char* icone, const char* ior)
2460 SALOMEDS::GenericAttribute_var anAttr ;
2464 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
2465 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
2466 aNameAttrib->SetValue(name);
2469 // Ajout du commentaire
2470 if ( value != NULL )
2472 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
2473 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
2474 aCommentAttrib->SetValue(value);
2478 if ( icone != NULL )
2480 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO,"AttributePixMap");
2481 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
2482 aPixmap->SetPixMap(icone);
2488 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
2489 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2490 anIOR->SetValue(ior);
2494 //=====================================================================================
2495 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
2497 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
2499 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
2500 ASSERT(!CORBA::is_nil(myCase));
2501 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
2502 ASSERT(!CORBA::is_nil(aCaseSO));
2504 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2505 ASSERT(!CORBA::is_nil(myBoundary));
2506 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
2507 ASSERT(!CORBA::is_nil(aBoundarySO));
2509 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2511 aStudyBuilder->NewCommand();
2513 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
2514 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
2516 aStudyBuilder->CommitCommand();
2519 //=============================================================================
2520 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
2521 // Option = 0 : fichier issu d'une importation
2522 // Option = 1 : fichier issu d'une execution HOMARD
2524 MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
2525 if (CORBA::is_nil(myCurrentStudy))
2527 SALOME::ExceptionStruct es;
2528 es.type = SALOME::BAD_PARAM;
2529 es.text = "Invalid Study Context ";
2530 throw SALOME::SALOME_Exception(es);
2534 // Le module SMESH est-il actif ?
2535 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
2537 if (!CORBA::is_nil(aSmeshSO))
2539 // On verifie que le fichier n est pas deja publie
2540 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
2541 for (; aIter->More(); aIter->Next())
2543 SALOMEDS::SObject_var aSO = aIter->Value();
2544 SALOMEDS::GenericAttribute_var aGAttr;
2545 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
2547 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2548 CORBA::String_var value=anAttr->Value();
2549 if (strcmp((const char*)value,NomFich) == 0)
2551 MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
2552 // Pour un fichier importe, on ne republie pas
2557 // Pour un fichier calcule, on commence par faire la depublication
2560 MESSAGE ( "PublishResultInSmesh : depublication" );
2561 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
2562 CORBA::String_var value2=anAttr2->Value();
2563 const char* MeshName = value2 ;
2564 MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
2565 DeleteResultInSmesh(NomFich, MeshName) ;
2572 // On enregistre le fichier
2573 MESSAGE( "Enregistrement du fichier");
2574 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
2575 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
2576 ASSERT(!CORBA::is_nil(aSmeshEngine));
2577 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
2578 SMESH::DriverMED_ReadStatus theStatus;
2579 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
2581 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
2582 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
2583 for (int i = 0; i < mesMaillages->length(); i++)
2585 MESSAGE( ". Mise a jour des attributs du maillage");
2586 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
2587 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
2588 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2589 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
2590 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2591 anAttr->SetValue(NomFich);
2592 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
2593 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
2595 if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
2596 else { icone = "mesh_tree_mesh.png" ; }
2597 anAttr2->SetPixMap( icone );
2601 //=============================================================================
2602 void HOMARD_Gen_i::DeleteResultInSmesh(const char* NomFich, const char* MeshName)
2604 MESSAGE (" DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
2605 if (CORBA::is_nil(myCurrentStudy))
2607 SALOME::ExceptionStruct es;
2608 es.type = SALOME::BAD_PARAM;
2609 es.text = "Invalid Study Context ";
2610 throw SALOME::SALOME_Exception(es);
2614 // Le module SMESH est-il actif ?
2615 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
2617 if (CORBA::is_nil(aSmeshSO))
2621 // On verifie que le fichier est deja publie
2622 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
2623 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
2624 for (; aIter->More(); aIter->Next())
2626 SALOMEDS::SObject_var aSO = aIter->Value();
2627 SALOMEDS::GenericAttribute_var aGAttr;
2628 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
2630 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2631 CORBA::String_var value=anAttr->Value();
2632 if (strcmp((const char*)value,NomFich) == 0)
2634 if (aSO->FindAttribute(aGAttr,"AttributeName"))
2636 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
2637 CORBA::String_var value2=anAttr2->Value();
2638 if (strcmp((const char*)value2,MeshName) == 0)
2640 myBuilder->RemoveObjectWithChildren( aSO ) ;
2648 //=============================================================================
2649 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
2651 // MESSAGE (" PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
2652 if (CORBA::is_nil(myCurrentStudy))
2654 SALOME::ExceptionStruct es;
2655 es.type = SALOME::BAD_PARAM;
2656 es.text = "Invalid Study Context ";
2657 throw SALOME::SALOME_Exception(es);
2661 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
2662 if (CORBA::is_nil(myIteration))
2664 SALOME::ExceptionStruct es;
2665 es.type = SALOME::BAD_PARAM;
2666 es.text = "Invalid Iteration ";
2667 throw SALOME::SALOME_Exception(es);
2670 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
2671 if (CORBA::is_nil(myIteration))
2673 SALOME::ExceptionStruct es;
2674 es.type = SALOME::BAD_PARAM;
2675 es.text = "Invalid Iteration Study Object";
2676 throw SALOME::SALOME_Exception(es);
2680 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2682 aStudyBuilder->NewCommand();
2684 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
2685 // Pour les fichiers med, on affiche une icone de maillage
2686 // Pour les fichiers qui sont texte, on affiche une icone de fichier texte 'texte'
2687 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
2689 const char* ior = " " ;
2690 if ( Commentaire[0] == 'I' )
2691 { icone = "med.png" ; }
2693 { icone = "texte_2.png" ; }
2694 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone, ior ) ;
2696 aStudyBuilder->CommitCommand();
2698 //=============================================================================
2699 //=============================================================================
2701 //=============================================================================
2702 //=============================================================================
2703 // Next functions are inherited from SALOMEDS::Driver interface
2704 //=============================================================================
2705 //=============================================================================
2706 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
2708 CORBA::Boolean isMultiFile)
2710 MESSAGE (" Save for theURL = "<< theURL);
2711 SALOMEDS::TMPFile_var aStreamFile;
2713 // get temporary directory name
2714 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2716 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2717 StudyContext& context = myContextMap[ aStudy->StudyId() ];
2719 // HOMARD data file name
2720 std::string aFileName = "";
2722 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2723 aFileName += "_HOMARD.dat";
2725 // initialize sequence of file names
2726 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
2727 aFileSeq->length(1);
2728 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
2730 // get full path to the data file
2731 aFileName = tmpDir + aFileName;
2735 std::ofstream f(aFileName.c_str());
2737 // clear temporary id map
2738 context._idmap.clear();
2743 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
2744 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
2745 HOMARD::HOMARD_Cas_var aCas = it_case->second;
2746 PortableServer::ServantBase_var aServant = GetServant(aCas);
2747 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2749 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
2750 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
2754 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2755 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
2756 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
2757 PortableServer::ServantBase_var aServant = GetServant(aZone);
2758 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2760 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
2761 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2764 // -> save hypotheses
2765 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2766 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
2767 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
2768 PortableServer::ServantBase_var aServant = GetServant(aHypo);
2769 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2771 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
2772 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2775 // -> save iterations
2776 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2777 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
2778 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
2779 PortableServer::ServantBase_var aServant = GetServant(aIter);
2780 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2782 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
2783 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2786 // -> save boundaries
2787 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2788 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
2789 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
2790 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2791 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2792 if (aBoundaryServant) {
2793 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
2794 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2798 MESSAGE ("close file");
2801 // put temporary files to the stream
2802 MESSAGE ("put temporary files to the stream");
2803 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
2805 // remove temporary files
2806 MESSAGE ("remove temporary files");
2807 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2809 // return data stream
2810 MESSAGE ("return data stream");
2811 return aStreamFile._retn();
2814 //===========================================================================
2815 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
2817 CORBA::Boolean isMultiFile)
2819 // No specific ASCII persistence
2820 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
2821 return aStreamFile._retn();
2824 //===========================================================================
2825 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
2826 const SALOMEDS::TMPFile& theStream,
2828 CORBA::Boolean isMultiFile)
2830 MESSAGE (" Load pour theURL = "<< theURL);
2831 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2833 // set current study
2834 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
2835 SetCurrentStudy(aStudy);
2837 // get temporary directory name
2838 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2840 // Convert the stream into sequence of files to process
2841 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
2844 // HOMARD data file name
2845 std::string aFileName = "";
2847 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2848 aFileName = tmpDir + aFileName + "_HOMARD.dat";
2850 StudyContext& context = myContextMap[ aStudy->StudyId() ];
2854 std::ifstream f(aFileName.c_str());
2857 context._mesCas.clear();
2858 context._mesHypotheses.clear();
2859 context._mesIterations.clear();
2860 context._mesZones.clear();
2861 context._mesBoundarys.clear();
2862 context._idmap.clear();
2868 std::getline(f, line);
2869 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
2870 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
2871 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
2872 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
2873 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
2874 if (line.substr(0, caseSignature.size()) == caseSignature) {
2876 MESSAGE (" Recreation du cas" );
2877 HOMARD::HOMARD_Cas_var aCase = newCase();
2878 PortableServer::ServantBase_var aServant = GetServant(aCase);
2879 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2880 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
2881 context._mesCas[aCase->GetName()] = aCase;
2882 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
2885 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
2886 MESSAGE (" Recreation de la zone" );
2888 HOMARD::HOMARD_Zone_var aZone = newZone();
2889 PortableServer::ServantBase_var aServant = GetServant(aZone);
2890 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2891 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
2892 context._mesZones[aZone->GetName()] = aZone;
2893 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2896 else if (line.substr(0, iterSignature.size()) == iterSignature) {
2897 // re-create iteration
2898 MESSAGE (" Recreation de l iteration" );
2899 HOMARD::HOMARD_Iteration_var aIter = newIteration();
2900 PortableServer::ServantBase_var aServant = GetServant(aIter);
2901 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2902 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
2903 context._mesIterations[aIter->GetName()] = aIter;
2904 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2907 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
2908 // re-create hypothesis
2909 MESSAGE (" Recreation de l hypothese" );
2910 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
2911 PortableServer::ServantBase_var aServant = GetServant(aHypo);
2912 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2913 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
2914 context._mesHypotheses[aHypo->GetName()] = aHypo;
2915 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2918 else if (line.substr(0, bounSignature.size()) == bounSignature) {
2919 // re-create boundary
2920 MESSAGE (" Recreation de la frontiere" );
2921 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
2922 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2923 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2924 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
2925 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
2926 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2935 // Remove temporary files created from the stream
2937 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2942 //===========================================================================
2943 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
2944 const SALOMEDS::TMPFile& theStream,
2946 CORBA::Boolean isMultiFile)
2948 // No specific ASCII persistence
2949 return Load(theComponent, theStream, theURL, isMultiFile);
2952 //===========================================================================
2953 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
2955 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
2956 // clearing study context should be done here:
2957 // - destroy all servants and related CORBA objects
2959 // - remove context from myContextMap
2960 myContextMap.erase(theComponent->GetStudy()->StudyId());
2961 // - nullify myCurrentStudy
2962 myCurrentStudy = SALOMEDS::Study::_nil();
2966 //===========================================================================
2967 char* HOMARD_Gen_i::ComponentDataType()
2969 return CORBA::string_dup("HOMARD");
2972 //===========================================================================
2973 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
2974 const char* IORString,
2975 CORBA::Boolean isMultiFile,
2976 CORBA::Boolean isASCII)
2978 CORBA::String_var aString("");
2979 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
2980 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2981 CORBA::Object_var anObj = _orb->string_to_object(IORString);
2982 if (!CORBA::is_nil(anObj)) {
2983 PortableServer::ServantBase_var aServant = GetServant(anObj);
2984 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
2986 std::map<int, PortableServer::ServantBase*>::const_iterator it;
2987 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
2988 if (it->second == aStorable) {
2989 std::stringstream os;
2991 aString = CORBA::string_dup(os.str().c_str());
2997 return aString._retn();
3000 //===========================================================================
3001 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
3002 const char* aLocalPersistentID,
3003 CORBA::Boolean isMultiFile,
3004 CORBA::Boolean isASCII)
3006 CORBA::String_var aString("");
3007 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
3008 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
3009 int id = atoi(aLocalPersistentID);
3010 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
3011 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
3012 if (!CORBA::is_nil(object)) {
3013 aString = _orb->object_to_string(object);
3017 return aString._retn();
3020 //===========================================================================
3021 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
3023 if(CORBA::is_nil(myCurrentStudy))
3026 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
3027 if(!aCas->_is_nil())
3030 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
3031 if(!aHypo->_is_nil())
3034 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
3035 if(!aZone->_is_nil())
3038 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
3039 if(!aBoundary->_is_nil())
3042 /* Iteration is not published directly
3043 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
3044 if(!aIter->_is_nil())
3050 //===========================================================================
3051 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
3053 // No Copy/Paste support
3057 //===========================================================================
3058 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
3059 CORBA::Long& theObjectID)
3061 // No Copy/Paste support
3062 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
3063 return aStreamFile._retn();
3066 //===========================================================================
3067 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
3068 CORBA::Long theObjectID)
3070 // No Copy/Paste support
3074 //===========================================================================
3075 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
3076 CORBA::Long theObjectID,
3077 SALOMEDS::SObject_ptr theSObject)
3079 // No Copy/Paste support
3080 SALOMEDS::SObject_var aResultSO;
3081 return aResultSO._retn();
3084 //===========================================================================
3085 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
3087 PortableServer::Servant aServant = 0;
3088 if (!CORBA::is_nil(theObject)) {
3090 aServant = _poa->reference_to_servant(theObject);
3098 //==========================================================================
3099 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
3100 CORBA::Boolean isPublished,
3101 CORBA::Boolean isMultiFile,
3102 CORBA::Boolean& isValidScript)
3104 MESSAGE ("Entree dans DumpPython");
3106 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
3107 if(CORBA::is_nil(aStudy))
3108 return new Engines::TMPFile(0);
3110 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
3111 if(CORBA::is_nil(aSO))
3112 return new Engines::TMPFile(0);
3114 std::string aScript = "\"\"\"\n";
3115 aScript += "Python script for HOMARD\n";
3116 aScript += "Copyright EDF-R&D 2013\n";
3117 aScript += "\"\"\"\n";
3118 aScript += "__revision__ = \"V1.2\"\n";
3119 aScript += "import HOMARD\n";
3121 aScript += "import salome\n";
3122 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
3124 aScript += "def RebuildData(theStudy):\n";
3125 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
3128 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
3129 MESSAGE (". Au depart \n"<<aScript);
3132 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
3134 MESSAGE (". Ecritures des frontieres");
3135 aScript += "#\n# Creation of the boundaries";
3136 aScript += "\n# ==========================";
3138 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
3139 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
3140 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
3142 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
3143 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
3144 std::string dumpBoundary = dumpCorbaBoundary.in();
3145 MESSAGE (dumpBoundary<<"\n");
3146 aScript += dumpBoundary;
3150 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
3152 MESSAGE (". Ecritures des zones");
3153 aScript += "#\n# Creation of the zones";
3154 aScript += "\n# =====================";
3156 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
3157 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
3158 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
3160 HOMARD::HOMARD_Zone_var maZone = (*it_zone).second;
3161 CORBA::String_var dumpCorbaZone = maZone->GetDumpPython();
3162 std::string dumpZone = dumpCorbaZone.in();
3163 MESSAGE (dumpZone<<"\n");
3164 aScript += dumpZone;
3168 if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
3170 MESSAGE (". Ecritures des hypotheses");
3171 aScript += "#\n# Creation of the hypotheses";
3172 aScript += "\n# ==========================";
3174 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
3175 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
3176 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
3178 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
3179 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
3180 std::string dumpHypo = dumpCorbaHypo.in();
3181 MESSAGE (dumpHypo<<"\n");
3182 aScript += dumpHypo;
3186 if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
3188 MESSAGE (". Ecritures des cas");
3189 aScript += "#\n# Creation of the cases";
3190 aScript += "\n# =====================";
3192 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
3193 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
3194 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
3196 std::string nomCas = (*it_cas).first;
3197 std::string dumpCas = std::string("\n# Creation of the case ") ;
3198 dumpCas += nomCas + std::string("\n");
3199 dumpCas += std::string("\t") + nomCas;
3200 dumpCas += std::string(" = homard.CreateCase('") + nomCas + std::string("', '");
3202 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
3203 CORBA::String_var cIter0= myCase->GetIter0Name();
3204 std::string iter0 = cIter0.in();
3206 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
3207 CORBA::String_var cMesh0= myIteration->GetMeshFile();
3208 std::string mesh0 = cMesh0.in();
3209 CORBA::String_var cMeshName0= myIteration->GetMeshName();
3210 std::string meshName0 = cMeshName0.in();
3211 dumpCas += meshName0 + std::string("', '")+ mesh0 + std::string("')\n");
3212 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
3213 std::string dumpCas2= dumpCorbaCase.in();
3215 MESSAGE (dumpCas<<dumpCas2<<"\n");
3216 aScript += dumpCas + dumpCas2;
3220 if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
3222 MESSAGE (". Ecritures des iterations");
3223 aScript += "#\n# Creation of the iterations" ;
3224 aScript += "\n# ==========================";
3226 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
3227 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
3228 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
3230 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
3231 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
3232 std::string dumpIter = dumpCorbaIter.in();
3233 MESSAGE (dumpIter<<"\n");
3234 aScript += dumpIter;
3237 MESSAGE (". Ecritures finales");
3239 aScript += "\n\tpass";
3242 if( !isMultiFile ) // remove unnecessary tabulation
3243 aScript = RemoveTabulation( aScript );
3245 // MESSAGE ("A ecrire \n"<<aScript);
3246 const size_t aLen = strlen(aScript.c_str());
3247 char* aBuffer = new char[aLen+1];
3248 strcpy(aBuffer, aScript.c_str());
3250 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
3251 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
3253 MESSAGE ("Sortie de DumpPython");
3254 return aStreamFile._retn();
3258 //=============================================================================
3259 //=============================================================================
3261 //=============================================================================
3262 //=============================================================================
3263 void HOMARD_Gen_i::IsValidStudy( )
3265 // MESSAGE( "IsValidStudy" );
3266 if (CORBA::is_nil(myCurrentStudy))
3268 SALOME::ExceptionStruct es;
3269 es.type = SALOME::BAD_PARAM;
3270 es.text = "Invalid Study Context";
3271 throw SALOME::SALOME_Exception(es);
3276 //=============================================================================
3277 CORBA::Boolean HOMARD_Gen_i::VerifieDir(const char* nomDir)
3279 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
3280 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
3281 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
3283 if (std::string(nomDir) == std::string(it->second->GetDirName())) return false;
3287 /*//=============================================================================
3288 void SALOMEException( std::string message )
3290 SALOME::ExceptionStruct es;
3291 es.type = SALOME::BAD_PARAM;
3293 throw SALOME::SALOME_Exception(es);
3296 //=============================================================================
3297 char* HOMARD_Gen_i::getVersion()
3299 #if HOMARD_DEVELOPMENT
3300 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
3302 return CORBA::string_dup(HOMARD_VERSION_STR);
3306 //=============================================================================
3309 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
3310 PortableServer::POA_ptr poa,
3311 PortableServer::ObjectId* contId,
3312 const char* instanceName,
3313 const char* interfaceName)
3315 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
3316 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
3317 return myHOMARD_Gen->getId();