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 Option = 0 ;
280 if ( DeleteIterationOption(nomIter, Option) != 0 )
285 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
286 myContextMap[GetCurrentStudyID()]._mesCas.erase(nomCas);
287 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomCas, ComponentDataType());
288 SALOMEDS::SObject_var aSO =listSO[0];
289 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
290 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
294 //=============================================================================
295 CORBA::Long HOMARD_Gen_i::DeleteHypo(const char* nomHypo)
297 MESSAGE ( "DeleteHypo : nomHypo = " << nomHypo );
298 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
299 if (CORBA::is_nil(myHypo))
301 SALOME::ExceptionStruct es;
302 es.type = SALOME::BAD_PARAM;
303 es.text = "Invalid Hypothesis ";
304 throw SALOME::SALOME_Exception(es);
308 // On verifie que l'hypothese n'est plus utilisee
309 HOMARD::listeIters* maListeIter = myHypo->GetIterations();
310 int numberOfIter = maListeIter->length();
311 if ( numberOfIter > 0 )
313 SALOME::ExceptionStruct es;
314 es.type = SALOME::BAD_PARAM;
315 es.text = "This hypothesis is used and cannot be deleted.";
316 throw SALOME::SALOME_Exception(es);
320 // suppression du lien avec les zones eventuelles
321 HOMARD::listeZonesHypo* maListe = myHypo->GetZones();
322 int numberOfZones = maListe->length();
323 MESSAGE ( ".. Nombre de zones = " << numberOfZones );
324 for (int NumeZone = 0; NumeZone< numberOfZones; NumeZone++)
326 std::string ZoneName = std::string((*maListe)[NumeZone]);
327 MESSAGE ( ".. suppression du lien avec la zone = " << ZoneName.c_str() );
328 DissociateHypoZone(nomHypo, ZoneName.c_str()) ;
332 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
333 myContextMap[GetCurrentStudyID()]._mesHypotheses.erase(nomHypo);
334 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomHypo, ComponentDataType());
335 SALOMEDS::SObject_var aSO =listSO[0];
336 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
337 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
341 //=============================================================================
342 CORBA::Long HOMARD_Gen_i::DeleteIteration(const char* nomIter)
344 // Pour detruire une iteration courante
345 MESSAGE ( "DeleteIteration : nomIter = " << nomIter );
346 CORBA::Long Option = 1 ;
347 return DeleteIterationOption(nomIter, Option);
349 //=============================================================================
350 CORBA::Long HOMARD_Gen_i::DeleteIterationOption(const char* nomIter, CORBA::Long Option)
352 // Option = 0 : On autorise la destruction de l'iteration 0
353 // Option = 1 : On interdit la destruction de l'iteration 0
354 MESSAGE ( "DeleteIterationOption : nomIter = " << nomIter << ", avec option = " << Option );
355 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
356 if (CORBA::is_nil(myIteration))
358 SALOME::ExceptionStruct es;
359 es.type = SALOME::BAD_PARAM;
360 es.text = "Invalid Iteration ";
361 throw SALOME::SALOME_Exception(es);
365 int numero = myIteration->GetNumber();
366 MESSAGE ( "DeleteIterationOption : numero = " << numero );
367 if ( numero == 0 and Option == 1 )
369 SALOME::ExceptionStruct es;
370 es.type = SALOME::BAD_PARAM;
371 es.text = "This iteration cannot be deleted.";
372 throw SALOME::SALOME_Exception(es);
376 // On detruit recursivement toutes les filles
377 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
378 int numberOfIter = maListe->length();
379 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
381 std::string nomIterFille = std::string((*maListe)[NumeIter]);
382 MESSAGE ( ".. appel recursif de DeleteIterationOption pour nomIter = " << nomIterFille.c_str() );
383 DeleteIterationOption(nomIterFille.c_str(), Option);
386 // On arrive ici pour une iteration sans fille
387 MESSAGE ( "Destruction effective de " << nomIter );
388 // On commence par invalider l'iteration pour faire le menage des dependances
389 // et des publications dans SMESH
390 InvalideIter(nomIter) ;
392 // Retrait dans la descendance de l'iteration parent
395 const char* nomIterationParent = myIteration->GetIterParentName();
396 MESSAGE ( "Retrait dans la descendance de nomIterationParent " << nomIterationParent );
397 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
398 if (CORBA::is_nil(myIterationParent))
400 SALOME::ExceptionStruct es;
401 es.type = SALOME::BAD_PARAM;
402 es.text = "Invalid Iteration ";
403 throw SALOME::SALOME_Exception(es);
406 myIterationParent->UnLinkNextIteration(nomIter);
409 // suppression du lien avec l'hypothese
412 const char* nomHypo = myIteration->GetHypoName();
413 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
414 ASSERT(!CORBA::is_nil(myHypo));
415 myHypo->UnLinkIteration(nomIter);
418 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
419 myContextMap[GetCurrentStudyID()]._mesIterations.erase(nomIter);
420 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomIter, ComponentDataType());
421 SALOMEDS::SObject_var aSO =listSO[0];
422 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
423 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
424 // on peut aussi faire RemoveObject
425 // MESSAGE ( "Au final" );
426 // HOMARD::listeIterations* Liste = GetAllIterationsName() ;
427 // numberOfIter = Liste->length();
428 // for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
430 // std::string nomIterFille = std::string((*Liste)[NumeIter]);
431 // MESSAGE ( ".. nomIter = " << nomIterFille.c_str() );
436 //=============================================================================
437 CORBA::Long HOMARD_Gen_i::DeleteZone(const char* nomZone)
439 MESSAGE ( "DeleteZone : nomZone = " << nomZone );
440 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[nomZone];
441 if (CORBA::is_nil(myZone))
443 SALOME::ExceptionStruct es;
444 es.type = SALOME::BAD_PARAM;
445 es.text = "Invalid Zone ";
446 throw SALOME::SALOME_Exception(es);
450 // On verifie que la zone n'est plus utilisee
451 HOMARD::listeHypo* maListe = myZone->GetHypo();
452 int numberOfHypo = maListe->length();
453 MESSAGE ( ".. Nombre d'hypotheses = " << numberOfHypo );
454 if ( numberOfHypo > 0 )
456 SALOME::ExceptionStruct es;
457 es.type = SALOME::BAD_PARAM;
458 es.text = "This zone is used and cannot be deleted.";
459 throw SALOME::SALOME_Exception(es);
463 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
464 myContextMap[GetCurrentStudyID()]._mesZones.erase(nomZone);
465 SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomZone, ComponentDataType());
466 SALOMEDS::SObject_var aSO =listSO[0];
467 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
468 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
472 //=============================================================================
473 //=============================================================================
475 //=============================================================================
476 //=============================================================================
477 // Invalidation des structures identifiees par leurs noms
478 //=============================================================================
479 //=============================================================================
480 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
482 MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName );
483 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
484 if (CORBA::is_nil(myBoundary))
486 SALOME::ExceptionStruct es;
487 es.type = SALOME::BAD_PARAM;
488 es.text = "Invalid Boundary ";
489 throw SALOME::SALOME_Exception(es);
494 SALOME::ExceptionStruct es;
495 es.type = SALOME::BAD_PARAM;
496 es.text = "No change is allowed in a boundary. Ask for evolution.";
497 throw SALOME::SALOME_Exception(es);
501 //=============================================================================
502 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
504 MESSAGE( "InvalideHypo : nomHypo = " << nomHypo );
505 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
506 if (CORBA::is_nil(myHypo))
508 SALOME::ExceptionStruct es;
509 es.type = SALOME::BAD_PARAM;
510 es.text = "Invalid Hypothesis ";
511 throw SALOME::SALOME_Exception(es);
515 HOMARD::listeIters* maListe = myHypo->GetIterations();
516 int numberOfIter = maListe->length();
517 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
519 std::string nomIter = std::string((*maListe)[NumeIter]);
520 MESSAGE( ".. nomIter = " << nomIter );
521 InvalideIter(nomIter.c_str());
524 //=============================================================================
525 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
527 MESSAGE("InvalideIter : nomIter = " << nomIter);
528 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
529 if (CORBA::is_nil(myIteration))
531 SALOME::ExceptionStruct es;
532 es.type = SALOME::BAD_PARAM;
533 es.text = "Invalid Iteration ";
534 throw SALOME::SALOME_Exception(es);
538 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
539 int numberOfIter = maListe->length();
540 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
542 std::string nomIterFille = std::string((*maListe)[NumeIter]);
543 MESSAGE ( ".. appel recursif de InvalideIter pour nomIter = " << nomIterFille.c_str() );
544 InvalideIter(nomIterFille.c_str());
547 // On arrive ici pour une iteration sans fille
548 MESSAGE ( "Invalidation effective de " << nomIter );
549 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
550 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
551 for (; aIter->More(); aIter->Next())
553 SALOMEDS::SObject_var so = aIter->Value();
554 SALOMEDS::GenericAttribute_var anAttr;
555 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
556 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
557 std::string value (aCommentAttr->Value());
558 if(value == std::string("HypoHomard")) continue;
559 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
560 aStudyBuilder->RemoveObject(so);
563 int number = myIteration->GetNumber();
566 SetEtatIter(nomIter,false);
567 const char * nomCas = myIteration->GetCaseName();
568 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
569 if (CORBA::is_nil(myCase))
571 SALOME::ExceptionStruct es;
572 es.type = SALOME::BAD_PARAM;
573 es.text = "Invalid Case Context ";
574 throw SALOME::SALOME_Exception(es);
577 const char* dirCase = myCase->GetDirName();
578 const char* nomDir = myIteration->GetDirName();
579 const char* nomFichier = myIteration->GetMeshFile();
580 std::string commande= "rm -rf " + std::string(dirCase) + "/" + std::string(nomDir);
581 commande = commande + ";rm -rf " + std::string(nomFichier);
582 MESSAGE ( "commande = " << commande );
583 if ((system(commande.c_str())) != 0)
585 SALOME::ExceptionStruct es;
586 es.type = SALOME::BAD_PARAM;
587 es.text = "Menage du repertoire de calcul impossible" ;
588 throw SALOME::SALOME_Exception(es);
591 // Suppression du maillage publie dans SMESH
592 const char* MeshName = myIteration->GetMeshName();
593 DeleteResultInSmesh(nomFichier, MeshName) ;
597 //=============================================================================
598 void HOMARD_Gen_i::InvalideIterInfo(const char* nomIter)
600 MESSAGE("InvalideIterInfo : nomIter = " << nomIter);
601 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
602 if (CORBA::is_nil(myIteration))
604 SALOME::ExceptionStruct es;
605 es.type = SALOME::BAD_PARAM;
606 es.text = "Invalid Iteration ";
607 throw SALOME::SALOME_Exception(es);
611 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
612 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
613 for (; aIter->More(); aIter->Next())
615 SALOMEDS::SObject_var so = aIter->Value();
616 SALOMEDS::GenericAttribute_var anAttr;
617 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
618 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
619 std::string value (aCommentAttr->Value());
620 /* MESSAGE("... value = " << value);*/
621 if( (value == std::string("logInfo")) or ( value == std::string("SummaryInfo")) )
623 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
624 aStudyBuilder->RemoveObject(so);
628 const char * nomCas = myIteration->GetCaseName();
629 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
630 if (CORBA::is_nil(myCase))
632 SALOME::ExceptionStruct es;
633 es.type = SALOME::BAD_PARAM;
634 es.text = "Invalid Case Context ";
635 throw SALOME::SALOME_Exception(es);
638 const char* dirCase = myCase->GetDirName();
639 const char* nomDir = myIteration->GetDirName();
640 std::string commande = "rm -f " + std::string(dirCase) + "/" + std::string(nomDir) + "/info* " ;
641 commande += std::string(dirCase) + "/" + std::string(nomDir) + "/Liste.*info" ;
642 /* MESSAGE ( "commande = " << commande );*/
643 if ((system(commande.c_str())) != 0)
645 SALOME::ExceptionStruct es;
646 es.type = SALOME::BAD_PARAM;
647 es.text = "Menage du repertoire de calcul impossible" ;
648 throw SALOME::SALOME_Exception(es);
653 //=============================================================================
654 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
656 MESSAGE( "InvalideZone : ZoneName = " << ZoneName );
657 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
658 if (CORBA::is_nil(myZone))
660 SALOME::ExceptionStruct es;
661 es.type = SALOME::BAD_PARAM;
662 es.text = "Invalid Zone ";
663 throw SALOME::SALOME_Exception(es);
666 HOMARD::listeHypo* maListe = myZone->GetHypo();
667 int numberOfHypo = maListe->length();
668 MESSAGE( ".. numberOfHypo = " << numberOfHypo );
669 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
671 std::string nomHypo = std::string((*maListe)[NumeHypo]);
672 MESSAGE( ".. nomHypo = " << nomHypo );
673 InvalideHypo(nomHypo.c_str());
676 //=============================================================================
677 //=============================================================================
679 //=============================================================================
680 //=============================================================================
681 // Association de lien entre des structures identifiees par leurs noms
682 //=============================================================================
683 //=============================================================================
684 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
686 MESSAGE( "AssociateCaseIter : " << nomCas << " ," << nomIter << "," << labelIter );
688 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
689 if (CORBA::is_nil(myCase))
691 SALOME::ExceptionStruct es;
692 es.type = SALOME::BAD_PARAM;
693 es.text = "Invalid Case ";
694 throw SALOME::SALOME_Exception(es);
698 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
699 if (CORBA::is_nil(myIteration))
701 SALOME::ExceptionStruct es;
702 es.type = SALOME::BAD_PARAM;
703 es.text = "Invalid iteration ";
704 throw SALOME::SALOME_Exception(es);
708 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
709 SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
710 if (CORBA::is_nil(aCasSO))
712 SALOME::ExceptionStruct es;
713 es.type = SALOME::BAD_PARAM;
714 es.text = "Invalid Case ";
715 throw SALOME::SALOME_Exception(es);
719 aStudyBuilder->NewCommand();
720 SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
721 PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
722 "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
723 aStudyBuilder->CommitCommand();
725 myCase->AddIteration(nomIter);
726 myIteration->SetCaseName(nomCas);
728 //=====================================================================================
729 void HOMARD_Gen_i::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
731 MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
733 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
734 ASSERT(!CORBA::is_nil(myHypo));
735 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
736 ASSERT(!CORBA::is_nil(aHypoSO));
738 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
739 ASSERT(!CORBA::is_nil(myZone));
740 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
741 ASSERT(!CORBA::is_nil(aZoneSO));
743 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
745 aStudyBuilder->NewCommand();
747 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
748 aStudyBuilder->Addreference(aSubSO, aZoneSO);
750 aStudyBuilder->CommitCommand();
752 myZone->AddHypo(nomHypothesis);
753 myHypo->AddZone0(ZoneName, TypeUse);
755 //=============================================================================
756 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
758 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
760 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
761 ASSERT(!CORBA::is_nil(myHypo));
762 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
763 ASSERT(!CORBA::is_nil(aHypoSO));
765 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
766 ASSERT(!CORBA::is_nil(myIteration));
767 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
768 ASSERT(!CORBA::is_nil(aIterSO));
770 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
772 aStudyBuilder->NewCommand();
774 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
775 aStudyBuilder->Addreference(aSubSO, aHypoSO);
777 aStudyBuilder->CommitCommand();
779 myIteration->SetHypoName(nomHypo);
780 myHypo->LinkIteration(nomIter);
782 //=============================================================================
783 //=============================================================================
785 //=============================================================================
786 //=============================================================================
787 // Dissociation de lien entre des structures identifiees par leurs noms
788 //=============================================================================
789 //=============================================================================
790 void HOMARD_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
792 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
794 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
795 ASSERT(!CORBA::is_nil(myHypo));
796 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
797 ASSERT(!CORBA::is_nil(aHypoSO));
799 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
800 ASSERT(!CORBA::is_nil(myZone));
801 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
802 ASSERT(!CORBA::is_nil(aZoneSO));
804 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
806 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator(aHypoSO);
807 for (; it->More(); it->Next())
809 SALOMEDS::SObject_var aHypObj = it->Value();
810 SALOMEDS::SObject_var ptrObj;
811 if (aHypObj->ReferencedObject(ptrObj))
813 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
815 aStudyBuilder->NewCommand();
816 aStudyBuilder->RemoveObject(aHypObj);
817 aStudyBuilder->CommitCommand();
823 myZone->SupprHypo(nomHypothesis);
824 myHypo->SupprZone(ZoneName);
826 //=============================================================================
827 //=============================================================================
830 //=============================================================================
831 //=============================================================================
832 // Recuperation des listes
833 //=============================================================================
834 //=============================================================================
835 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
837 MESSAGE("GetAllCasesName");
840 HOMARD::listeCases_var ret = new HOMARD::listeCases;
841 ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
842 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
844 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
845 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
847 ret[i++] = CORBA::string_dup((*it).first.c_str());
852 //=============================================================================
853 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
855 MESSAGE("GetAllHypothesesName");
858 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
859 ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
860 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
862 for (it = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
863 it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
865 ret[i++] = CORBA::string_dup((*it).first.c_str());
870 //=============================================================================
871 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
873 MESSAGE("GetAllZonesName");
876 HOMARD::listeZones_var ret = new HOMARD::listeZones;
877 ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
878 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
880 for (it = myContextMap[GetCurrentStudyID()]._mesZones.begin();
881 it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
883 ret[i++] = CORBA::string_dup((*it).first.c_str());
888 //=============================================================================
889 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
891 MESSAGE("GetAllIterationsName");
894 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
895 ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
896 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
898 for (it = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
899 it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
901 ret[i++] = CORBA::string_dup((*it).first.c_str());
906 //=============================================================================
907 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
909 MESSAGE("GetAllBoundarysName");
912 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
913 ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
914 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
916 for (it = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
917 it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
919 ret[i++] = CORBA::string_dup((*it).first.c_str());
924 //=============================================================================
925 //=============================================================================
927 //=============================================================================
928 //=============================================================================
929 // Recuperation des structures identifiees par leurs noms
930 //=============================================================================
931 //=============================================================================
932 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
934 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
935 ASSERT(!CORBA::is_nil(myCase));
936 return HOMARD::HOMARD_Cas::_duplicate(myCase);
938 //=============================================================================
939 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
941 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
942 ASSERT(!CORBA::is_nil(myZone));
943 return HOMARD::HOMARD_Zone::_duplicate(myZone);
945 //=============================================================================
946 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
948 HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
949 ASSERT(!CORBA::is_nil(myHypothesis));
950 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
952 //=============================================================================
953 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* NomIterationation)
955 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIterationation];
956 ASSERT(!CORBA::is_nil(myIteration));
957 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
959 //=============================================================================
960 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
962 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
963 ASSERT(!CORBA::is_nil(myBoundary));
964 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
966 //=============================================================================
967 //=============================================================================
969 //=============================================================================
970 //=============================================================================
972 //=============================================================================
973 //=============================================================================
974 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)
976 MESSAGE ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
977 MESSAGE ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte );
981 HOMARD::HOMARD_Cas_ptr myCase = CreateCase(nomCas, MeshName, MeshFile) ;
982 myCase->SetDirName(DirName) ;
984 myCase->MeshInfo(Qual, Diam, Conn, Tail, Inte) ;
988 //=============================================================================
989 //=============================================================================
991 //=============================================================================
992 //=============================================================================
993 // Recuperation des structures par le contexte
994 //=============================================================================
995 //=============================================================================
996 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::LastIteration(const char* nomCas)
998 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
999 ASSERT(!CORBA::is_nil(myCase));
1001 HOMARD::HOMARD_Iteration_var myIteration = myCase->LastIteration();
1002 ASSERT(!CORBA::is_nil(myIteration));
1004 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1006 //=============================================================================
1007 //=============================================================================
1009 //=============================================================================
1010 //=============================================================================
1011 // Nouvelles structures
1012 //=============================================================================
1013 //=============================================================================
1014 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1016 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1017 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
1018 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
1019 return aCase._retn();
1021 //=============================================================================
1022 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
1024 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1025 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
1026 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
1027 return aHypo._retn();
1029 //=============================================================================
1030 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
1032 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1033 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
1034 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
1035 return aIter._retn();
1037 //=============================================================================
1038 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1040 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1041 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
1042 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1043 return aBoundary._retn();
1045 //=============================================================================
1046 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
1048 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1049 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
1050 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
1051 return aZone._retn();
1053 //=============================================================================
1054 //=============================================================================
1056 //=============================================================================
1057 //=============================================================================
1058 // Creation des structures identifiees par leurs noms
1059 //=============================================================================
1060 //=============================================================================
1061 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
1063 MESSAGE ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1066 if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
1068 SALOME::ExceptionStruct es;
1069 es.type = SALOME::BAD_PARAM;
1070 es.text = "This case has already been defined";
1071 throw SALOME::SALOME_Exception(es);
1075 int existe = MEDFileExist ( MeshFile ) ;
1078 SALOME::ExceptionStruct es;
1079 es.type = SALOME::BAD_PARAM;
1080 es.text = "The mesh file does not exist.";
1081 throw SALOME::SALOME_Exception(es);
1085 HOMARD::HOMARD_Cas_var myCase = newCase();
1086 myCase->SetName(nomCas);
1087 SALOMEDS::SObject_var aSO;
1088 PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
1089 myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
1091 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile);
1092 HOMARD::extrema_var aSeq = new HOMARD::extrema();
1093 if (LesExtremes.size()!=10) { return false; }
1095 for (int i =0; i< LesExtremes.size(); i++)
1096 aSeq[i]=LesExtremes[i];
1097 myCase->SetBoundingBox(aSeq);
1099 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile);
1100 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType;
1101 aSeqGroupe->length(LesGroupes.size());
1102 std::set<std::string>::const_iterator it;
1104 for (it=LesGroupes.begin() ; it != LesGroupes.end(); it++)
1105 aSeqGroupe[i++]=(*it).c_str();
1106 myCase->SetGroups(aSeqGroupe);
1108 // Recherche d'un nom pour l'iteration 0. Par defaut, on prend le nom
1109 // du maillage du cas. Si ce nom existe deja, on incremente avec 0, 1, 2, etc.
1111 std::string NomIteration = std::string(MeshName) ;
1112 while ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()))
1114 std::ostringstream nom;
1115 nom << MeshName << monNum;
1116 NomIteration=nom.str();
1119 MESSAGE ( "CreateCase : NomIteration = " << NomIteration );
1121 HOMARD::HOMARD_Iteration_var anIter = newIteration();
1122 myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration] = anIter;
1123 std::ostringstream DirName;
1126 anIter->SetDirName(DirName.str().c_str());
1127 anIter->SetName(NomIteration.c_str());
1128 anIter->SetMeshFile(MeshFile);
1129 anIter->SetMeshName(MeshName);
1130 anIter->SetNumber(0);
1132 AssociateCaseIter (nomCas,NomIteration.c_str(),"IterationHomard");
1133 SetEtatIter(NomIteration.c_str(),true);
1135 PublishResultInSmesh(MeshFile, 0);
1137 // Valeurs par defaut des filtrages
1138 myCase->SetPyram(0);
1140 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1142 //=============================================================================
1143 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1145 MESSAGE ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1148 if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
1150 SALOME::ExceptionStruct es;
1151 es.type = SALOME::BAD_PARAM;
1152 es.text = "This hypothesis is already defined.";
1153 throw SALOME::SALOME_Exception(es);
1157 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1158 myHypothesis->SetName(nomHypothesis);
1159 myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
1160 SALOMEDS::SObject_var aSO;
1161 PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
1163 // Valeurs par defaut des options avancees
1164 myHypothesis->SetNivMax(-1);
1165 myHypothesis->SetDiamMin(-1.0);
1166 myHypothesis->SetAdapInit(0);
1167 myHypothesis->SetLevelOutput(0);
1169 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1172 //=============================================================================
1173 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1174 //=============================================================================
1176 MESSAGE ("CreateIteration : NomIteration = " << NomIteration << ", nomIterParent = " << nomIterParent);
1179 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
1180 if (CORBA::is_nil(myIterationParent))
1182 SALOME::ExceptionStruct es;
1183 es.type = SALOME::BAD_PARAM;
1184 es.text = "The parent iteration is not defined.";
1185 throw SALOME::SALOME_Exception(es);
1189 const char* nomCas = myIterationParent->GetCaseName();
1190 MESSAGE ("CreateIteration : nomCas = " << nomCas);
1191 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1192 if (CORBA::is_nil(myCase))
1194 SALOME::ExceptionStruct es;
1195 es.type = SALOME::BAD_PARAM;
1196 es.text = "Invalid Case Context ";
1197 throw SALOME::SALOME_Exception(es);
1201 if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
1203 SALOME::ExceptionStruct es;
1204 es.type = SALOME::BAD_PARAM;
1205 es.text = "This iteration is already defined. ";
1206 throw SALOME::SALOME_Exception(es);
1210 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1211 if (CORBA::is_nil(myIteration))
1213 SALOME::ExceptionStruct es;
1214 es.type = SALOME::BAD_PARAM;
1215 es.text = "Unable to create Iteration ";
1216 throw SALOME::SALOME_Exception(es);
1219 myContextMap[GetCurrentStudyID()]._mesIterations[std::string(NomIteration)] = myIteration;
1220 // Nom de l'iteration et du maillage
1221 myIteration->SetName(NomIteration);
1222 myIteration->SetMeshName(NomIteration);
1224 int numero = myIterationParent->GetNumber() + 1;
1225 myIteration->SetNumber(numero);
1227 // Nombre d'iterations deja connues pour le cas, permettant
1228 // la creation d'un sous-repertoire unique
1229 int nbitercase = myCase->GetNumber();
1230 std::ostringstream iaux ;
1231 iaux << std::setw(2) << std::setfill('0') << nbitercase ;
1232 std::stringstream DirName;
1233 DirName << "I" << iaux.str();
1234 myIteration->SetDirName(DirName.str().c_str());
1236 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1237 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1238 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1239 // situation la plus frequente.
1240 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1241 // le nombre d'iterations du cas permet d'eviter les collisions.
1242 std::stringstream MeshFile;
1243 const char* nomDir = myCase->GetDirName();
1244 MeshFile << nomDir << "/maill." << iaux.str() << ".med";
1245 myIteration->SetMeshFile(MeshFile.str().c_str());
1247 // Association avec le cas
1248 std::string label = "IterationHomard_" + std::string(nomIterParent);
1249 AssociateCaseIter(nomCas, NomIteration, label.c_str());
1250 // Lien avec l'iteration precedente
1251 myIterationParent->LinkNextIteration(NomIteration);
1252 myIteration->SetIterParentName(nomIterParent);
1254 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1256 //=============================================================================
1257 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1259 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1262 if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
1264 SALOME::ExceptionStruct es;
1265 es.type = SALOME::BAD_PARAM;
1266 es.text = "This boundary has already been defined";
1267 throw SALOME::SALOME_Exception(es);
1271 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1272 myBoundary->SetName(BoundaryName);
1273 myBoundary->SetType(BoundaryType);
1275 myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
1277 SALOMEDS::SObject_var aSO;
1278 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
1280 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1282 //=============================================================================
1283 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1285 MESSAGE ("CreateBoundaryDi : BoundaryName = " << BoundaryName << "MeshName = " << MeshName );
1286 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1287 myBoundary->SetMeshFile( MeshFile ) ;
1288 myBoundary->SetMeshName( MeshName ) ;
1290 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1292 //=============================================================================
1293 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1294 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1295 CORBA::Double Xaxis, CORBA::Double Yaxis, CORBA::Double Zaxis,
1296 CORBA::Double Rayon)
1298 MESSAGE ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
1299 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1300 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxis, Yaxis, Zaxis, Rayon ) ;
1302 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1304 //=============================================================================
1305 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1306 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1307 CORBA::Double Rayon)
1309 MESSAGE ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
1310 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1311 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1313 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1315 //=============================================================================
1316 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
1318 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
1321 if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
1323 SALOME::ExceptionStruct es;
1324 es.type = SALOME::BAD_PARAM;
1325 es.text = "This zone has already been defined";
1326 throw SALOME::SALOME_Exception(es);
1330 HOMARD::HOMARD_Zone_var myZone = newZone();
1331 myZone->SetName(ZoneName);
1332 myZone->SetType(ZoneType);
1334 myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
1336 SALOMEDS::SObject_var aSO;
1337 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
1339 return HOMARD::HOMARD_Zone::_duplicate(myZone);
1341 //=============================================================================
1342 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
1343 CORBA::Double Xmini, CORBA::Double Xmaxi,
1344 CORBA::Double Ymini, CORBA::Double Ymaxi,
1345 CORBA::Double Zmini, CORBA::Double Zmaxi)
1347 MESSAGE ("CreateZoneBox : ZoneName = " << ZoneName ) ;
1348 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
1349 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
1351 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1353 //=============================================================================
1354 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
1355 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
1357 MESSAGE ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
1358 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
1359 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1361 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1363 //=============================================================================
1364 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
1365 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1366 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1367 CORBA::Double Rayon, CORBA::Double Haut)
1369 MESSAGE ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
1370 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
1371 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
1373 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1375 //=============================================================================
1376 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
1377 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1378 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1379 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
1381 MESSAGE ("CreateZonePipe : ZoneName = " << ZoneName ) ;
1382 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
1383 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
1385 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1387 //=============================================================================
1388 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
1389 CORBA::Double Umini, CORBA::Double Umaxi,
1390 CORBA::Double Vmini, CORBA::Double Vmaxi,
1393 MESSAGE ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
1394 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
1395 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
1396 // MESSAGE ("Orient = " << Orient ) ;
1398 double Xmini, Xmaxi ;
1399 double Ymini, Ymaxi ;
1400 double Zmini, Zmaxi ;
1408 else if ( Orient == 2 )
1415 else if ( Orient == 3 )
1422 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
1424 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
1425 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
1427 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1429 //=============================================================================
1430 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
1431 CORBA::Double Ucentre, CORBA::Double Vcentre,
1432 CORBA::Double Rayon,
1435 MESSAGE ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
1440 { Xcentre = Ucentre ;
1443 else if ( Orient == 2 )
1446 Zcentre = Vcentre ; }
1447 else if ( Orient == 3 )
1448 { Xcentre = Vcentre ;
1450 Zcentre = Ucentre ; }
1451 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
1453 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
1454 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
1456 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1458 //=============================================================================
1459 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
1460 CORBA::Double Ucentre, CORBA::Double Vcentre,
1461 CORBA::Double Rayon, CORBA::Double Rayonint,
1464 MESSAGE ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
1469 { Xcentre = Ucentre ;
1472 else if ( Orient == 2 )
1475 Zcentre = Vcentre ; }
1476 else if ( Orient == 3 )
1477 { Xcentre = Vcentre ;
1479 Zcentre = Ucentre ; }
1480 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
1482 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
1483 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
1485 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1487 //=============================================================================
1488 //=============================================================================
1493 //=============================================================================
1494 //=============================================================================
1495 // Traitement d'une iteration
1496 // etatMenage = 1 : destruction du repertoire d'execution
1497 // modeHOMARD = 1 : adaptation
1498 // != 1 : information avec les options modeHOMARD
1499 // Option >0 : appel depuis python
1500 // <0 : appel depuis GUI
1501 //=============================================================================
1502 //=============================================================================
1503 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option)
1505 MESSAGE ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", avec Option = " << Option );
1510 // A.1. L'objet iteration
1511 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
1512 ASSERT(!CORBA::is_nil(myIteration));
1514 // A.2. Numero de l'iteration
1515 // siterp1 : numero de l'iteration a traiter
1517 // siter : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
1518 // Ou si information :
1520 int NumeIter = myIteration->GetNumber();
1521 std::string siterp1 ;
1522 std::stringstream saux1 ;
1524 siterp1 = saux1.str() ;
1525 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
1528 if ( modeHOMARD==1 )
1530 std::stringstream saux0 ;
1531 int iaux = max(0, NumeIter-1) ;
1533 siter = saux0.str() ;
1534 if (NumeIter < 11) { siter = "0" + siter ; }
1537 { siter = siterp1 ; }
1540 const char* nomCas = myIteration->GetCaseName();
1541 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1542 ASSERT(!CORBA::is_nil(myCase));
1544 // B. Les repertoires
1545 // B.1. Le repertoire courant
1546 char* nomDirWork = getenv("PWD") ;
1547 // B.2. Le sous-repertoire de l'iteration a traiter
1548 char* DirCompute = ComputeDir(myCase, myIteration, etatMenage);
1549 MESSAGE( ". DirCompute = " << DirCompute );
1551 // C. Le fichier des messages
1552 // C.1. Le deroulement de l'execution de HOMARD
1553 std::string LogFile = DirCompute ;
1554 LogFile += "/Liste" ;
1555 if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
1557 MESSAGE (". LogFile = " << LogFile);
1558 if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
1559 // C.2. Le bilan de l'analyse du maillage
1560 std::string FileInfo = DirCompute ;
1562 if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
1564 { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
1565 else { FileInfo += "info_ap" ; }
1567 FileInfo += "." + siterp1 + ".bilan" ;
1568 myIteration->SetFileInfo(FileInfo.c_str());
1570 // D. On passe dans le repertoire de l'iteration a calculer
1571 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
1574 // E. Les donnees de l'execution HOMARD
1575 // E.1. L'objet du texte du fichier de configuration
1576 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
1577 myDriver->TexteInit(DirCompute, LogFile);
1579 // E.2. Le maillage associe a l'iteration
1580 const char* NomMesh = myIteration->GetMeshName();
1581 MESSAGE ( ". NomMesh = " << NomMesh );
1582 const char* MeshFile = myIteration->GetMeshFile();
1583 MESSAGE ( ". MeshFile = " << MeshFile );
1585 // E.3. Les donnees du traitement HOMARD
1587 if ( modeHOMARD == 1 )
1590 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
1591 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
1592 codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option) ;
1596 InvalideIterInfo(NomIteration);
1597 myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
1599 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
1600 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
1601 myDriver->CreeFichierDonn();
1604 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
1605 DriverTexteBoundary(myCase, myDriver) ;
1607 // E.5. Ecriture du texte dans le fichier
1609 { myDriver->CreeFichier(); }
1613 int codretexec = 12 ;
1616 codretexec = myDriver->ExecuteHomard(Option);
1618 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
1619 if ( modeHOMARD == 1 )
1621 if (codretexec == 0) { SetEtatIter(NomIteration,true); }
1622 else { SetEtatIter(NomIteration,false); }
1623 // GERALD -- QMESSAGE BOX
1627 // H. Gestion des resultats
1630 std::string Commentaire ;
1631 // H.1. Le fichier des messages, dans tous les cas
1632 Commentaire = "log" ;
1633 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
1634 else { Commentaire += "Info" ; }
1635 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
1637 // H.2. Si tout s'est bien passe :
1638 if (codretexec == 0)
1640 // H.2.1. Le fichier de bilan
1641 Commentaire = "Summary" ;
1642 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
1643 else { Commentaire += "Info" ; }
1644 PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
1645 // H.2.2. Le fichier de maillage obtenu
1646 if ( modeHOMARD == 1 )
1648 std::stringstream saux0 ;
1649 Commentaire = "Iteration" ;
1650 Commentaire += " " + siter ;
1651 PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
1652 PublishResultInSmesh(MeshFile, 1);
1655 // H.3 Message d'erreur en cas de probleme
1658 SALOME::ExceptionStruct es;
1659 es.type = SALOME::BAD_PARAM;
1660 std::string text = "Error during the adaptation.\n" ;
1663 ifstream fichier(LogFile.c_str(), ios::in);
1665 while(getline(fichier, ligne) and (ligne != "===== HOMARD ===== STOP ====="));
1666 while (getline(fichier, ligne)) { text += ligne+ "\n";};
1669 text += "no log file ....";
1671 es.text = CORBA::string_dup(text.c_str());
1672 throw SALOME::SALOME_Exception(es);
1676 // I. Menage et retour dans le repertoire du cas
1680 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
1686 //=============================================================================
1687 // Calcul d'une iteration : partie specifique a l'adaptation
1688 //=============================================================================
1689 CORBA::Long HOMARD_Gen_i::ComputeAdap(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage, HomardDriver* myDriver, CORBA::Long Option)
1691 MESSAGE ( "ComputeAdap" );
1696 // Numero de l'iteration
1697 int NumeIter = myIteration->GetNumber();
1698 std::stringstream saux0 ;
1699 saux0 << NumeIter-1 ;
1700 std::string siter = saux0.str() ;
1701 if (NumeIter < 11) { siter = "0" + siter ; }
1703 // A.2. On ne calcule pas l iteration 0
1704 if ( NumeIter == 0 )
1706 SALOME::ExceptionStruct es;
1707 es.type = SALOME::BAD_PARAM;
1708 es.text = "This iteration is the first of the case and cannot be computed.";
1709 throw SALOME::SALOME_Exception(es);
1713 // A.3. On verifie qu il y a une hypothese (erreur improbable);
1714 const char* nomHypo = myIteration->GetHypoName();
1715 if (std::string(nomHypo) == std::string(""))
1717 SALOME::ExceptionStruct es;
1718 es.type = SALOME::BAD_PARAM;
1719 es.text= "This iteration does not have any associated hypothesis.";
1720 throw SALOME::SALOME_Exception(es);
1723 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
1724 ASSERT(!CORBA::is_nil(myHypo));
1726 // B. L'iteration parent
1727 const char* nomIterationParent = myIteration->GetIterParentName();
1728 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
1729 ASSERT(!CORBA::is_nil(myIterationParent));
1730 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
1731 if ( ! myIterationParent->GetEtat() )
1734 int codret = Compute(nomIterationParent, etatMenage, iaux, Option);
1737 // GERALD -- QMESSAGE BOX
1738 ASSERT("Pb au calcul de l'iteration precedente" == 0);
1742 // C. Le sous-repertoire de l'iteration precedente
1743 char* DirComputePa = ComputeDirPa(myCase, myIteration);
1744 MESSAGE( ". DirComputePa = " << DirComputePa );
1746 // D. Les donnees de l'adaptation HOMARD
1747 // D.1. Le type de conformite
1748 int ConfType = myCase->GetConfType();
1749 MESSAGE ( ". ConfType = " << ConfType );
1751 // D.2. Le maillage de depart
1752 const char* NomMeshParent = myIterationParent->GetMeshName();
1753 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
1754 const char* MeshFileParent = myIterationParent->GetMeshFile();
1755 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
1757 // D.3. Le maillage associe a l'iteration
1758 const char* MeshFile = myIteration->GetMeshFile();
1759 MESSAGE ( ". MeshFile = " << MeshFile );
1760 FILE *file = fopen(MeshFile,"r");
1764 if (etatMenage == 0)
1766 SALOME::ExceptionStruct es;
1767 es.type = SALOME::BAD_PARAM;
1768 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
1769 es.text = CORBA::string_dup(text.c_str());
1770 throw SALOME::SALOME_Exception(es);
1775 std::string commande = "rm -f " + std::string(MeshFile);
1776 codret = system(commande.c_str());
1779 SALOME::ExceptionStruct es;
1780 es.type = SALOME::BAD_PARAM;
1781 std::string text = "PB with meshfile destruction ";
1782 es.text = CORBA::string_dup(text.c_str());
1783 throw SALOME::SALOME_Exception(es);
1789 // D.4. Les types de raffinement et de deraffinement
1790 // Les appels corba sont lourds, il vaut mieux les grouper
1791 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
1792 ASSERT(ListTypes->length() == 3);
1793 int TypeAdap = (*ListTypes)[0];
1794 int TypeRaff = (*ListTypes)[1];
1795 int TypeDera = (*ListTypes)[2];
1797 // E. Texte du fichier de configuration
1798 // E.1. Incontournables du texte
1799 myDriver->TexteAdap();
1801 myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
1802 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
1803 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
1805 // E.2. Ajout des informations liees aux zones eventuelles
1806 if ( TypeAdap == 0 )
1807 { DriverTexteZone(myHypo, myDriver) ; }
1809 // E.3. Ajout des informations liees aux champs eventuels
1810 if ( TypeAdap == 1 )
1811 { DriverTexteField(myIteration, myHypo, myDriver) ; }
1813 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
1814 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
1815 int numberOfGroups = listeGroupes->length();
1816 MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
1817 if (numberOfGroups > 0)
1819 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
1821 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
1822 MESSAGE( "... GroupName = " << GroupName );
1823 myDriver->TexteGroup(GroupName);
1827 // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
1828 DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
1830 // E.6. Ajout des options avancees
1831 int Pyram = myCase->GetPyram();
1832 MESSAGE ( ". Pyram = " << Pyram );
1833 int NivMax = myHypo->GetNivMax();
1834 MESSAGE ( ". NivMax = " << NivMax );
1835 double DiamMin = myHypo->GetDiamMin() ;
1836 MESSAGE ( ". DiamMin = " << DiamMin );
1837 int AdapInit = myHypo->GetAdapInit();
1838 MESSAGE ( ". AdapInit = " << AdapInit );
1839 int LevelOutput = myHypo->GetLevelOutput();
1840 MESSAGE ( ". LevelOutput = " << LevelOutput );
1841 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
1845 //=============================================================================
1846 // Calcul d'une iteration : gestion du repertoire de calcul
1847 // Si le sous-repertoire existe :
1848 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
1849 // etatMenage = 1 : on fait le menage du repertoire
1850 // etatMenage = -1 : on ne fait rien
1851 //=============================================================================
1852 char* HOMARD_Gen_i::ComputeDir(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
1854 MESSAGE ( "ComputeDir : repertoires pour le calcul" );
1855 // B.2. Le repertoire du cas
1856 const char* nomDirCase = myCase->GetDirName();
1857 MESSAGE ( ". nomDirCase = " << nomDirCase );
1859 // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
1860 // B.3.1. Le nom du sous-repertoire
1861 const char* nomDirIt = myIteration->GetDirName();
1863 // B.3.2. Le nom complet du sous-repertoire
1864 std::stringstream DirCompute ;
1865 DirCompute << nomDirCase << "/" << nomDirIt;
1866 MESSAGE (". DirCompute = " << DirCompute.str() );
1868 // B.3.3. Si le sous-repertoire n'existe pas, on le cree
1869 if (chdir(DirCompute.str().c_str()) != 0)
1871 // Creation du repertoire car il n'existe pas :
1872 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1874 // GERALD -- QMESSAGE BOX
1875 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
1876 ASSERT("Pb a la creation du repertoire" == 0);
1881 // Le repertoire existe
1882 // On demande de faire le menage de son contenu :
1883 if (etatMenage == 1)
1885 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
1886 std::string commande= "rm -rf " + DirCompute.str()+"/*" ;
1887 int codret = system(commande.c_str());
1890 // GERALD -- QMESSAGE BOX
1891 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
1892 ASSERT("Pb au menage du repertoire de calcul" == 0);
1895 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
1898 if (etatMenage == 0)
1901 struct dirent *dirp;
1902 dp = opendir(DirCompute.str().c_str());
1904 while ((dirp = readdir(dp)) != NULL && result )
1906 std::string file_name(dirp->d_name);
1907 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
1910 if ( result == false)
1912 SALOME::ExceptionStruct es;
1913 es.type = SALOME::BAD_PARAM;
1914 std::string text = "Directory : " + DirCompute.str() + "is not empty";
1915 es.text = CORBA::string_dup(text.c_str());
1916 throw SALOME::SALOME_Exception(es);
1917 ASSERT("Directory is not empty" == 0);
1923 return CORBA::string_dup( DirCompute.str().c_str() );
1925 //=============================================================================
1926 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
1927 //=============================================================================
1928 char* HOMARD_Gen_i::ComputeDirPa(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
1930 MESSAGE ( "ComputeDirPa : repertoires pour le calcul" );
1931 // Le repertoire du cas
1932 const char* nomDirCase = myCase->GetDirName();
1933 MESSAGE ( ". nomDirCase = " << nomDirCase );
1935 // Le sous-repertoire de l'iteration precedente
1937 const char* nomIterationParent = myIteration->GetIterParentName();
1938 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
1939 const char* nomDirItPa = myIterationParent->GetDirName();
1940 std::stringstream DirComputePa ;
1941 DirComputePa << nomDirCase << "/" << nomDirItPa;
1942 MESSAGE( ". nomDirItPa = " << nomDirItPa);
1943 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
1945 return CORBA::string_dup( DirComputePa.str().c_str() );
1947 //=============================================================================
1948 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
1949 //=============================================================================
1950 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
1952 MESSAGE ( "... DriverTexteZone" );
1953 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
1954 int numberOfZonesx2 = ListZone->length();
1957 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
1959 std::string ZoneName = std::string((*ListZone)[iaux]);
1960 MESSAGE ( "... ZoneName = " << ZoneName);
1961 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1962 ASSERT(!CORBA::is_nil(myZone));
1964 int ZoneType = myZone->GetType();
1965 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
1966 int TypeUse = atoi( TypeUsestr.c_str() );
1967 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
1968 NumZone = iaux/2 + 1 ;
1969 HOMARD::double_array* zone = myZone->GetCoords();
1970 if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
1972 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.);
1974 else if ( ZoneType == 4 ) // Cas d une sphere
1976 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.);
1978 else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
1980 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.);
1982 else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
1984 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]);
1986 else { ASSERT("ZoneType est incorrect." == 0) ; }
1991 //=============================================================================
1992 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
1993 //=============================================================================
1994 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
1996 MESSAGE ( "... DriverTexteField" );
1997 // Le fichier du champ
1998 char* FieldFile = myIteration->GetFieldFile();
1999 MESSAGE ( ". FieldFile = " << FieldFile );
2000 if (strlen(FieldFile) == 0)
2002 // GERALD -- QMESSAGE BOX
2003 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
2004 ASSERT("The file for the field is not given." == 0);
2006 // Les caracteristiques d'instants
2007 int TimeStep = myIteration->GetTimeStep();
2008 MESSAGE( ". TimeStep = " << TimeStep );
2009 int Rank = myIteration->GetRank();
2010 MESSAGE( ". Rank = " << Rank );
2011 // Les informations sur les champ
2012 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
2014 const char* FieldName = aInfosHypo->FieldName;
2016 int TypeThR = aInfosHypo->TypeThR;
2017 double ThreshR = aInfosHypo->ThreshR;
2018 int TypeThC = aInfosHypo->TypeThC;
2019 double ThreshC = aInfosHypo->ThreshC;
2020 // Saut entre mailles ou non ?
2021 int UsField = aInfosHypo->UsField;
2022 MESSAGE( ". UsField = " << UsField );
2023 // L'usage des composantes
2024 int UsCmpI = aInfosHypo->UsCmpI;
2025 MESSAGE( ". UsCmpI = " << UsCmpI );
2027 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
2030 HOMARD::listeComposantsHypo* mescompo = myHypo->GetListComp();
2031 int numberOfCompos = mescompo->length();
2032 MESSAGE( ". numberOfCompos = " << numberOfCompos );
2033 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
2035 std::string nomCompo = std::string((*mescompo)[NumeComp]);
2036 MESSAGE( "... nomCompo = " << nomCompo );
2037 myDriver->TexteCompo(NumeComp, nomCompo);
2041 //=============================================================================
2042 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
2043 //=============================================================================
2044 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
2046 MESSAGE ( "... DriverTexteBoundary" );
2047 // On ecrit d'abord la definition des frontieres, puis les liens avec les groupes
2048 std::list<std::string> ListeBoundaryTraitees ;
2049 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2050 int numberOfitems = ListBoundaryGroupType->length();
2051 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
2052 int BoundaryOption = 1 ;
2053 int NumBoundaryAnalytical = 0 ;
2054 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2056 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2057 MESSAGE ( "... BoundaryName = " << BoundaryName);
2059 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
2060 while (it != ListeBoundaryTraitees.end())
2062 MESSAGE ( "... BoundaryNameTraitee = " << *it);
2063 if ( BoundaryName == *it ) { A_faire = 0 ; }
2068 // Caracteristiques de la frontiere
2069 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2070 ASSERT(!CORBA::is_nil(myBoundary));
2071 int BoundaryType = myBoundary->GetType();
2072 MESSAGE ( "... BoundaryType = " << BoundaryType );
2073 // Ecriture selon le type
2074 if (BoundaryType == 0) // Cas d une frontiere discrete
2076 const char* MeshName = myBoundary->GetMeshName() ;
2077 const char* MeshFile = myBoundary->GetMeshFile() ;
2078 myDriver->TexteBoundaryDi( MeshName, MeshFile);
2079 BoundaryOption = BoundaryOption*2 ;
2081 else // Cas d une frontiere analytique
2083 NumBoundaryAnalytical++ ;
2084 HOMARD::double_array* coor = myBoundary->GetCoords();
2085 if (BoundaryType == 1) // Cas d un cylindre
2087 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6]);
2088 BoundaryOption = BoundaryOption*3 ;
2090 else if (BoundaryType == 2) // Cas d une sphere
2092 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0.);
2093 BoundaryOption = BoundaryOption*3 ;
2096 // Memorisation du traitement
2097 ListeBoundaryTraitees.push_back( BoundaryName );
2100 NumBoundaryAnalytical = 0 ;
2101 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2103 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2104 MESSAGE ( "... BoundaryName = " << BoundaryName);
2105 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2106 ASSERT(!CORBA::is_nil(myBoundary));
2107 int BoundaryType = myBoundary->GetType();
2108 MESSAGE ( "... BoundaryType = " << BoundaryType );
2109 // Recuperation du nom du groupe
2110 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
2111 MESSAGE ( "... GroupName = " << GroupName);
2112 if (BoundaryType == 0) // Cas d une frontiere discrete
2114 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
2116 else // Cas d une frontiere analytique
2118 NumBoundaryAnalytical++ ;
2119 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
2122 myDriver->TexteBoundaryOption(BoundaryOption);
2125 //=============================================================================
2126 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
2127 //=============================================================================
2128 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2130 MESSAGE ( "... DriverTexteFieldInterp" );
2131 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
2132 if (TypeFieldInterp != 0)
2134 // Le fichier des champs
2135 char* FieldFile = myIteration->GetFieldFile();
2136 MESSAGE ( ". FieldFile = " << FieldFile );
2137 if (strlen(FieldFile) == 0)
2139 // GERALD -- QMESSAGE BOX
2140 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
2141 ASSERT("The file for the field is not given." == 0);
2143 // Les caracteristiques d'instants
2144 int TimeStep = myIteration->GetTimeStep();
2145 MESSAGE( ". TimeStep = " << TimeStep );
2146 int Rank = myIteration->GetRank();
2147 MESSAGE( ". Rank = " << Rank );
2149 const char* MeshFile = myIteration->GetMeshFile();
2150 myDriver->TexteFieldInterp(TypeFieldInterp, FieldFile, MeshFile, TimeStep, Rank);
2152 if (TypeFieldInterp == 2)
2154 HOMARD::listFieldInterpHypo* meschamps = myHypo->GetListFieldInterp();
2155 int numberOfFields = meschamps->length();
2156 MESSAGE( ". numberOfFields = " << numberOfFields );
2157 for (int NumeChamp = 0; NumeChamp< numberOfFields; NumeChamp++)
2159 std::string nomChamp = std::string((*meschamps)[NumeChamp]);
2160 MESSAGE( "... nomChamp = " << nomChamp );
2161 myDriver->TexteFieldInterpName(NumeChamp, nomChamp);
2167 //===========================================================================
2168 //===========================================================================
2171 //===========================================================================
2172 //===========================================================================
2174 //===========================================================================
2175 //===========================================================================
2176 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
2177 SALOMEDS::SObject_ptr theSObject,
2178 CORBA::Object_ptr theObject,
2179 const char* theName)
2181 MESSAGE("PublishInStudy pour " << theName);
2182 SALOMEDS::SObject_var aResultSO;
2183 if (CORBA::is_nil(theStudy))
2185 SALOME::ExceptionStruct es;
2186 es.type = SALOME::BAD_PARAM;
2187 es.text = "Invalid Study Context ";
2188 throw SALOME::SALOME_Exception(es);
2192 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
2193 // Rq : Iteration est publiee ailleurs
2194 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
2195 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
2196 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
2197 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
2199 addInStudy(theStudy);
2201 // Controle de la non publication d'un objet de meme nom
2202 if ((!aHypo->_is_nil()) or (!aZone->_is_nil()) or (!aBoundary->_is_nil()))
2204 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
2205 if (listSO->length() >= 1)
2207 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
2208 std::cerr <<"This name "<<theName<<" is already used "<<listSO->length()<<" time(s)" << std::endl;
2209 aResultSO = listSO[0];
2210 return aResultSO._retn();
2214 // Caracteristiques de l'etude
2215 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
2216 aStudyBuilder->NewCommand();
2217 if(!aCase->_is_nil())
2218 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
2219 else if(!aHypo->_is_nil())
2220 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
2221 else if(!aZone->_is_nil())
2222 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
2223 else if(!aBoundary->_is_nil())
2224 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
2226 aStudyBuilder->CommitCommand();
2227 return aResultSO._retn();
2229 //=============================================================================
2230 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
2231 SALOMEDS::StudyBuilder_var aStudyBuilder,
2232 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
2234 MESSAGE("PublishCaseInStudy pour "<<theName);
2235 SALOMEDS::SObject_var aResultSO;
2236 SALOMEDS::GenericAttribute_var anAttr;
2238 if (CORBA::is_nil(theObject)) {
2239 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
2240 return aResultSO._retn();
2242 if (theStudy->_is_nil()) {
2243 MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
2244 return aResultSO._retn();
2247 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2248 if (theFatherHomard->_is_nil())
2250 MESSAGE("theFatherHomard->_is_nil()");
2251 return aResultSO._retn();
2254 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
2255 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
2256 _orb->object_to_string(theObject) ) ;
2257 return aResultSO._retn();
2260 //=============================================================================
2261 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
2262 SALOMEDS::StudyBuilder_var aStudyBuilder,
2263 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
2265 MESSAGE("PublishZoneStudy pour "<<theName);
2266 SALOMEDS::SObject_var aResultSO;
2267 SALOMEDS::GenericAttribute_var anAttr;
2269 if (CORBA::is_nil(theObject))
2271 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
2272 return aResultSO._retn();
2274 if (theStudy->_is_nil())
2276 MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
2277 return aResultSO._retn();
2279 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2280 if (theFatherHomard->_is_nil())
2282 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
2283 return aResultSO._retn();
2286 // Caracteristique de la zone
2287 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
2288 CORBA::Long ZoneType = myZone->GetType();
2290 // On ajoute la categorie des zones dans l etude si necessaire
2291 SALOMEDS::SObject_var aSOZone;
2292 if (!theFatherHomard->FindSubObject(100, aSOZone))
2294 MESSAGE("Ajout de la categorie des zones");
2295 aSOZone = aStudyBuilder->NewObjectToTag(theFatherHomard, 100);
2296 PublishInStudyAttr(aStudyBuilder, aSOZone, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
2298 else { MESSAGE("La categorie des zones existe deja."); }
2300 aResultSO = aStudyBuilder->NewObject(aSOZone);
2309 { icone = "boxdxy_2.png" ;
2313 { icone = "boxdxyz_2.png" ;
2321 { icone = "disk_2.png" ;
2325 { icone = "spherepoint_2.png" ;
2329 { icone = "cylinderpointvector_2.png" ;
2337 { icone = "diskwithhole_2.png" ;
2341 { icone = "pipe_2.png" ;
2345 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone, _orb->object_to_string(theObject) ) ;
2347 return aResultSO._retn();
2349 //=============================================================================
2350 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
2351 SALOMEDS::StudyBuilder_var aStudyBuilder,
2352 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
2354 MESSAGE("PublishBoundaryStudy pour "<<theName);
2355 SALOMEDS::SObject_var aResultSO;
2356 SALOMEDS::GenericAttribute_var anAttr;
2358 // Caracteristique de la Boundary
2359 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
2361 // On recupere le module pere dans l etude
2362 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2363 if (theFatherHomard->_is_nil())
2365 MESSAGE("theFatherHomard->_is_nil()");
2366 return aResultSO._retn();
2369 // On ajoute la categorie des boundarys dans l etude si necessaire
2370 SALOMEDS::SObject_var aSOBoundary;
2371 if (!theFatherHomard->FindSubObject(101, aSOBoundary))
2373 MESSAGE("Ajout de la categorie des boundarys");
2374 aSOBoundary = aStudyBuilder->NewObjectToTag(theFatherHomard, 101);
2375 PublishInStudyAttr(aStudyBuilder, aSOBoundary, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
2377 else { MESSAGE("La categorie des boundarys existe deja."); }
2379 aResultSO = aStudyBuilder->NewObject(aSOBoundary);
2380 CORBA::Long BoundaryType = myBoundary->GetType();
2381 // MESSAGE("BoundaryType : "<<BoundaryType);
2384 switch (BoundaryType)
2387 { value = "BoundaryDiHomard" ;
2388 icone = "mesh_tree_mesh.png" ;
2392 { value = "BoundaryAnHomard" ;
2393 icone = "cylinderpointvector_2.png" ;
2397 { value = "BoundaryAnHomard" ;
2398 icone = "spherepoint_2.png" ;
2402 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value, icone, _orb->object_to_string(theObject));
2403 return aResultSO._retn();
2406 //=============================================================================
2407 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
2408 SALOMEDS::StudyBuilder_var aStudyBuilder,
2409 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
2411 MESSAGE("PublishHypotheseInStudy pour "<<theName);
2412 SALOMEDS::SObject_var aResultSO;
2413 SALOMEDS::GenericAttribute_var anAttr;
2415 // On recupere le module pere dans l etude
2416 // On ajoute la categorie des hypotheses dans l etude si necessaire
2417 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2418 if (theFatherHomard->_is_nil())
2420 MESSAGE("theFatherHomard->_is_nil()");
2421 return aResultSO._retn();
2423 SALOMEDS::SObject_var aSOHypothese;
2424 if (!theFatherHomard->FindSubObject(0, aSOHypothese))
2426 MESSAGE("Ajout de la categorie des hypotheses");
2427 aSOHypothese = aStudyBuilder->NewObjectToTag(theFatherHomard, 0);
2428 PublishInStudyAttr(aStudyBuilder, aSOHypothese, "Hypothesis", "HypoList","hypotheses.png", NULL);
2430 else { MESSAGE("La categorie des hypotheses existe deja."); }
2432 // Creation du resultat dans l'etude
2433 aResultSO = aStudyBuilder->NewObject(aSOHypothese);
2434 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
2436 return aResultSO._retn();
2438 //===========================================================================
2439 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
2440 SALOMEDS::SObject_var aResultSO,
2441 const char* name, const char* value, const char* icone, const char* ior)
2443 SALOMEDS::GenericAttribute_var anAttr ;
2447 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
2448 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
2449 aNameAttrib->SetValue(name);
2452 // Ajout du commentaire
2453 if ( value != NULL )
2455 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
2456 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
2457 aCommentAttrib->SetValue(value);
2461 if ( icone != NULL )
2463 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO,"AttributePixMap");
2464 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
2465 aPixmap->SetPixMap(icone);
2471 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
2472 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2473 anIOR->SetValue(ior);
2477 //=====================================================================================
2478 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
2480 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
2482 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
2483 ASSERT(!CORBA::is_nil(myCase));
2484 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
2485 ASSERT(!CORBA::is_nil(aCaseSO));
2487 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2488 ASSERT(!CORBA::is_nil(myBoundary));
2489 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
2490 ASSERT(!CORBA::is_nil(aBoundarySO));
2492 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2494 aStudyBuilder->NewCommand();
2496 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
2497 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
2499 aStudyBuilder->CommitCommand();
2502 //=============================================================================
2503 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long IconeType)
2505 MESSAGE( "PublishResultInSmesh " << NomFich);
2506 if (CORBA::is_nil(myCurrentStudy))
2508 SALOME::ExceptionStruct es;
2509 es.type = SALOME::BAD_PARAM;
2510 es.text = "Invalid Study Context ";
2511 throw SALOME::SALOME_Exception(es);
2515 // Le module SMESH est-il actif ?
2516 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
2518 if (!CORBA::is_nil(aSmeshSO))
2520 // On verifie que le fichier n est pas deja publie
2521 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
2522 for (; aIter->More(); aIter->Next())
2524 SALOMEDS::SObject_var aSO = aIter->Value();
2525 SALOMEDS::GenericAttribute_var aGAttr;
2526 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
2528 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2529 CORBA::String_var value=anAttr->Value();
2530 if (strcmp((const char*)value,NomFich) == 0)
2532 // GERALD -- QMESSAGE BOX
2533 std::cerr << "fichier : "<< NomFich << " deja publie "<< std::endl;
2540 // On enregistre le fichier
2541 MESSAGE( "Enregistrement du fichier");
2542 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
2543 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
2544 ASSERT(!CORBA::is_nil(aSmeshEngine));
2545 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
2546 SMESH::DriverMED_ReadStatus theStatus;
2547 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
2549 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
2550 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
2551 for (int i = 0; i < mesMaillages->length(); i++)
2553 MESSAGE( ". Mise a jour des attributs du maillage");
2554 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
2555 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
2556 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2557 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
2558 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2559 anAttr->SetValue(NomFich);
2560 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
2561 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
2562 // IconeType = 0 : fichier issu d'une importation
2563 // IconeType = 1 : fichier issu d'une execution HOMARD
2565 if ( IconeType == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
2566 else { icone = "mesh_tree_mesh.png" ; }
2567 anAttr2->SetPixMap( icone );
2571 //=============================================================================
2572 void HOMARD_Gen_i::DeleteResultInSmesh(const char* NomFich, const char* MeshName)
2574 MESSAGE (" DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
2575 if (CORBA::is_nil(myCurrentStudy))
2577 SALOME::ExceptionStruct es;
2578 es.type = SALOME::BAD_PARAM;
2579 es.text = "Invalid Study Context ";
2580 throw SALOME::SALOME_Exception(es);
2584 // Le module SMESH est-il actif ?
2585 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
2587 if (CORBA::is_nil(aSmeshSO))
2591 // On verifie que le fichier est deja publie
2592 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
2593 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
2594 for (; aIter->More(); aIter->Next())
2596 SALOMEDS::SObject_var aSO = aIter->Value();
2597 SALOMEDS::GenericAttribute_var aGAttr;
2598 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
2600 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2601 CORBA::String_var value=anAttr->Value();
2602 if (strcmp((const char*)value,NomFich) == 0)
2604 if (aSO->FindAttribute(aGAttr,"AttributeName"))
2606 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
2607 CORBA::String_var value2=anAttr2->Value();
2608 if (strcmp((const char*)value2,MeshName) == 0)
2610 myBuilder->RemoveObjectWithChildren( aSO ) ;
2618 //=============================================================================
2619 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
2621 // MESSAGE (" PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
2622 if (CORBA::is_nil(myCurrentStudy))
2624 SALOME::ExceptionStruct es;
2625 es.type = SALOME::BAD_PARAM;
2626 es.text = "Invalid Study Context ";
2627 throw SALOME::SALOME_Exception(es);
2631 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
2632 if (CORBA::is_nil(myIteration))
2634 SALOME::ExceptionStruct es;
2635 es.type = SALOME::BAD_PARAM;
2636 es.text = "Invalid Iteration ";
2637 throw SALOME::SALOME_Exception(es);
2640 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
2641 if (CORBA::is_nil(myIteration))
2643 SALOME::ExceptionStruct es;
2644 es.type = SALOME::BAD_PARAM;
2645 es.text = "Invalid Iteration Study Object";
2646 throw SALOME::SALOME_Exception(es);
2650 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2652 aStudyBuilder->NewCommand();
2654 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
2655 // Pour les fichiers med, on affiche une icone de maillage
2656 // Pour les fichiers qui sont texte, on affiche une icone de fichier texte 'texte'
2657 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
2659 const char* ior = " " ;
2660 if ( Commentaire[0] == 'I' )
2661 { icone = "med.png" ; }
2663 { icone = "texte_2.png" ; }
2664 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone, ior ) ;
2666 aStudyBuilder->CommitCommand();
2668 //=============================================================================
2669 //=============================================================================
2671 //=============================================================================
2672 //=============================================================================
2673 // Next functions are inherited from SALOMEDS::Driver interface
2674 //=============================================================================
2675 //=============================================================================
2676 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
2678 CORBA::Boolean isMultiFile)
2680 MESSAGE (" Save for theURL = "<< theURL);
2681 SALOMEDS::TMPFile_var aStreamFile;
2683 // get temporary directory name
2684 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2686 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2687 StudyContext& context = myContextMap[ aStudy->StudyId() ];
2689 // HOMARD data file name
2690 std::string aFileName = "";
2692 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2693 aFileName += "_HOMARD.dat";
2695 // initialize sequence of file names
2696 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
2697 aFileSeq->length(1);
2698 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
2700 // get full path to the data file
2701 aFileName = tmpDir + aFileName;
2705 std::ofstream f(aFileName.c_str());
2707 // clear temporary id map
2708 context._idmap.clear();
2713 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
2714 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
2715 HOMARD::HOMARD_Cas_var aCas = it_case->second;
2716 PortableServer::ServantBase_var aServant = GetServant(aCas);
2717 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2719 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
2720 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
2724 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2725 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
2726 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
2727 PortableServer::ServantBase_var aServant = GetServant(aZone);
2728 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2730 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
2731 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2734 // -> save hypotheses
2735 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2736 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
2737 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
2738 PortableServer::ServantBase_var aServant = GetServant(aHypo);
2739 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2741 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
2742 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2745 // -> save iterations
2746 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2747 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
2748 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
2749 PortableServer::ServantBase_var aServant = GetServant(aIter);
2750 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2752 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
2753 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2756 // -> save boundaries
2757 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2758 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
2759 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
2760 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2761 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2762 if (aBoundaryServant) {
2763 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
2764 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2768 MESSAGE ("close file");
2771 // put temporary files to the stream
2772 MESSAGE ("put temporary files to the stream");
2773 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
2775 // remove temporary files
2776 MESSAGE ("remove temporary files");
2777 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2779 // return data stream
2780 MESSAGE ("return data stream");
2781 return aStreamFile._retn();
2784 //===========================================================================
2785 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
2787 CORBA::Boolean isMultiFile)
2789 // No specific ASCII persistence
2790 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
2791 return aStreamFile._retn();
2794 //===========================================================================
2795 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
2796 const SALOMEDS::TMPFile& theStream,
2798 CORBA::Boolean isMultiFile)
2800 MESSAGE (" Load pour theURL = "<< theURL);
2801 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2803 // set current study
2804 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
2805 SetCurrentStudy(aStudy);
2807 // get temporary directory name
2808 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2810 // Convert the stream into sequence of files to process
2811 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
2814 // HOMARD data file name
2815 std::string aFileName = "";
2817 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2818 aFileName = tmpDir + aFileName + "_HOMARD.dat";
2820 StudyContext& context = myContextMap[ aStudy->StudyId() ];
2824 std::ifstream f(aFileName.c_str());
2827 context._mesCas.clear();
2828 context._mesHypotheses.clear();
2829 context._mesIterations.clear();
2830 context._mesZones.clear();
2831 context._mesBoundarys.clear();
2832 context._idmap.clear();
2838 std::getline(f, line);
2839 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
2840 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
2841 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
2842 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
2843 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
2844 if (line.substr(0, caseSignature.size()) == caseSignature) {
2846 MESSAGE (" Recreation du cas" );
2847 HOMARD::HOMARD_Cas_var aCase = newCase();
2848 PortableServer::ServantBase_var aServant = GetServant(aCase);
2849 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2850 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
2851 context._mesCas[aCase->GetName()] = aCase;
2852 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
2855 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
2856 MESSAGE (" Recreation de la zone" );
2858 HOMARD::HOMARD_Zone_var aZone = newZone();
2859 PortableServer::ServantBase_var aServant = GetServant(aZone);
2860 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2861 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
2862 context._mesZones[aZone->GetName()] = aZone;
2863 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2866 else if (line.substr(0, iterSignature.size()) == iterSignature) {
2867 // re-create iteration
2868 MESSAGE (" Recreation de l iteration" );
2869 HOMARD::HOMARD_Iteration_var aIter = newIteration();
2870 PortableServer::ServantBase_var aServant = GetServant(aIter);
2871 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2872 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
2873 context._mesIterations[aIter->GetName()] = aIter;
2874 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2877 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
2878 // re-create hypothesis
2879 MESSAGE (" Recreation de l hypothese" );
2880 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
2881 PortableServer::ServantBase_var aServant = GetServant(aHypo);
2882 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2883 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
2884 context._mesHypotheses[aHypo->GetName()] = aHypo;
2885 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2888 else if (line.substr(0, bounSignature.size()) == bounSignature) {
2889 // re-create boundary
2890 MESSAGE (" Recreation de la frontiere" );
2891 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
2892 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2893 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2894 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
2895 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
2896 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2905 // Remove temporary files created from the stream
2907 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2912 //===========================================================================
2913 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
2914 const SALOMEDS::TMPFile& theStream,
2916 CORBA::Boolean isMultiFile)
2918 // No specific ASCII persistence
2919 return Load(theComponent, theStream, theURL, isMultiFile);
2922 //===========================================================================
2923 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
2925 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
2926 // clearing study context should be done here:
2927 // - destroy all servants and related CORBA objects
2929 // - remove context from myContextMap
2930 myContextMap.erase(theComponent->GetStudy()->StudyId());
2931 // - nullify myCurrentStudy
2932 myCurrentStudy = SALOMEDS::Study::_nil();
2936 //===========================================================================
2937 char* HOMARD_Gen_i::ComponentDataType()
2939 return CORBA::string_dup("HOMARD");
2942 //===========================================================================
2943 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
2944 const char* IORString,
2945 CORBA::Boolean isMultiFile,
2946 CORBA::Boolean isASCII)
2948 CORBA::String_var aString("");
2949 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
2950 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2951 CORBA::Object_var anObj = _orb->string_to_object(IORString);
2952 if (!CORBA::is_nil(anObj)) {
2953 PortableServer::ServantBase_var aServant = GetServant(anObj);
2954 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
2956 std::map<int, PortableServer::ServantBase*>::const_iterator it;
2957 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
2958 if (it->second == aStorable) {
2959 std::stringstream os;
2961 aString = CORBA::string_dup(os.str().c_str());
2967 return aString._retn();
2970 //===========================================================================
2971 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
2972 const char* aLocalPersistentID,
2973 CORBA::Boolean isMultiFile,
2974 CORBA::Boolean isASCII)
2976 CORBA::String_var aString("");
2977 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
2978 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2979 int id = atoi(aLocalPersistentID);
2980 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
2981 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
2982 if (!CORBA::is_nil(object)) {
2983 aString = _orb->object_to_string(object);
2987 return aString._retn();
2990 //===========================================================================
2991 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
2993 if(CORBA::is_nil(myCurrentStudy))
2996 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
2997 if(!aCas->_is_nil())
3000 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
3001 if(!aHypo->_is_nil())
3004 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
3005 if(!aZone->_is_nil())
3008 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
3009 if(!aBoundary->_is_nil())
3012 /* Iteration is not published directly
3013 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
3014 if(!aIter->_is_nil())
3020 //===========================================================================
3021 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
3023 // No Copy/Paste support
3027 //===========================================================================
3028 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
3029 CORBA::Long& theObjectID)
3031 // No Copy/Paste support
3032 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
3033 return aStreamFile._retn();
3036 //===========================================================================
3037 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
3038 CORBA::Long theObjectID)
3040 // No Copy/Paste support
3044 //===========================================================================
3045 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
3046 CORBA::Long theObjectID,
3047 SALOMEDS::SObject_ptr theSObject)
3049 // No Copy/Paste support
3050 SALOMEDS::SObject_var aResultSO;
3051 return aResultSO._retn();
3054 //===========================================================================
3055 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
3057 PortableServer::Servant aServant = 0;
3058 if (!CORBA::is_nil(theObject)) {
3060 aServant = _poa->reference_to_servant(theObject);
3068 //==========================================================================
3069 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
3070 CORBA::Boolean isPublished,
3071 CORBA::Boolean isMultiFile,
3072 CORBA::Boolean& isValidScript)
3074 MESSAGE ("Entree dans DumpPython");
3076 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
3077 if(CORBA::is_nil(aStudy))
3078 return new Engines::TMPFile(0);
3080 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
3081 if(CORBA::is_nil(aSO))
3082 return new Engines::TMPFile(0);
3084 std::string aScript = "\"\"\"\n";
3085 aScript += "Python script for HOMARD\n";
3086 aScript += "Copyright EDF-R&D 2013\n";
3087 aScript += "\"\"\"\n";
3088 aScript += "__revision__ = \"V1.2\"\n";
3089 aScript += "import HOMARD\n";
3091 aScript += "import salome\n";
3092 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
3094 aScript += "def RebuildData(theStudy):\n";
3095 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
3098 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
3099 MESSAGE (". Au depart \n"<<aScript);
3102 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
3104 MESSAGE (". Ecritures des frontieres");
3105 aScript += "#\n# Creation of the boundaries";
3106 aScript += "\n# ==========================";
3108 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
3109 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
3110 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
3112 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
3113 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
3114 std::string dumpBoundary = dumpCorbaBoundary.in();
3115 MESSAGE (dumpBoundary<<"\n");
3116 aScript += dumpBoundary;
3120 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
3122 MESSAGE (". Ecritures des zones");
3123 aScript += "#\n# Creation of the zones";
3124 aScript += "\n# =====================";
3126 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
3127 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
3128 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
3130 HOMARD::HOMARD_Zone_var maZone = (*it_zone).second;
3131 CORBA::String_var dumpCorbaZone = maZone->GetDumpPython();
3132 std::string dumpZone = dumpCorbaZone.in();
3133 MESSAGE (dumpZone<<"\n");
3134 aScript += dumpZone;
3138 if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
3140 MESSAGE (". Ecritures des hypotheses");
3141 aScript += "#\n# Creation of the hypotheses";
3142 aScript += "\n# ==========================";
3144 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
3145 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
3146 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
3148 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
3149 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
3150 std::string dumpHypo = dumpCorbaHypo.in();
3151 MESSAGE (dumpHypo<<"\n");
3152 aScript += dumpHypo;
3156 if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
3158 MESSAGE (". Ecritures des cas");
3159 aScript += "#\n# Creation of the cases";
3160 aScript += "\n# =====================";
3162 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
3163 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
3164 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
3166 std::string nomCas = (*it_cas).first;
3167 std::string dumpCas = std::string("\n# Creation of the case ") ;
3168 dumpCas += nomCas + std::string("\n");
3169 dumpCas += std::string("\t") + nomCas;
3170 dumpCas += std::string(" = homard.CreateCase('") + nomCas + std::string("', '");
3172 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
3173 CORBA::String_var cIter0= myCase->GetIter0Name();
3174 std::string iter0 = cIter0.in();
3176 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
3177 CORBA::String_var cMesh0= myIteration->GetMeshFile();
3178 std::string mesh0 = cMesh0.in();
3179 CORBA::String_var cMeshName0= myIteration->GetMeshName();
3180 std::string meshName0 = cMeshName0.in();
3181 dumpCas += meshName0 + std::string("', '")+ mesh0 + std::string("')\n");
3182 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
3183 std::string dumpCas2= dumpCorbaCase.in();
3185 MESSAGE (dumpCas<<dumpCas2<<"\n");
3186 aScript += dumpCas + dumpCas2;
3190 if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
3192 MESSAGE (". Ecritures des iterations");
3193 aScript += "#\n# Creation of the iterations" ;
3194 aScript += "\n# ==========================";
3196 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
3197 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
3198 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
3200 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
3201 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
3202 std::string dumpIter = dumpCorbaIter.in();
3203 MESSAGE (dumpIter<<"\n");
3204 aScript += dumpIter;
3207 MESSAGE (". Ecritures finales");
3209 aScript += "\n\tpass";
3212 if( !isMultiFile ) // remove unnecessary tabulation
3213 aScript = RemoveTabulation( aScript );
3215 // MESSAGE ("A ecrire \n"<<aScript);
3216 const size_t aLen = strlen(aScript.c_str());
3217 char* aBuffer = new char[aLen+1];
3218 strcpy(aBuffer, aScript.c_str());
3220 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
3221 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
3223 MESSAGE ("Sortie de DumpPython");
3224 return aStreamFile._retn();
3228 //=============================================================================
3229 //=============================================================================
3231 //=============================================================================
3232 //=============================================================================
3233 void HOMARD_Gen_i::IsValidStudy( )
3235 // MESSAGE( "IsValidStudy" );
3236 if (CORBA::is_nil(myCurrentStudy))
3238 SALOME::ExceptionStruct es;
3239 es.type = SALOME::BAD_PARAM;
3240 es.text = "Invalid Study Context";
3241 throw SALOME::SALOME_Exception(es);
3246 //=============================================================================
3247 CORBA::Boolean HOMARD_Gen_i::VerifieDir(const char* nomDir)
3249 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
3250 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
3251 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
3253 if (std::string(nomDir) == std::string(it->second->GetDirName())) return false;
3257 /*//=============================================================================
3258 void SALOMEException( std::string message )
3260 SALOME::ExceptionStruct es;
3261 es.type = SALOME::BAD_PARAM;
3263 throw SALOME::SALOME_Exception(es);
3266 //=============================================================================
3267 char* HOMARD_Gen_i::getVersion()
3269 #if HOMARD_DEVELOPMENT
3270 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
3272 return CORBA::string_dup(HOMARD_VERSION_STR);
3276 //=============================================================================
3279 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
3280 PortableServer::POA_ptr poa,
3281 PortableServer::ObjectId* contId,
3282 const char* instanceName,
3283 const char* interfaceName)
3285 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
3286 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
3287 return myHOMARD_Gen->getId();