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::InvalideZone(const char* ZoneName)
504 MESSAGE( "InvalideZone : ZoneName = " << ZoneName );
505 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
506 if (CORBA::is_nil(myZone))
508 SALOME::ExceptionStruct es;
509 es.type = SALOME::BAD_PARAM;
510 es.text = "Invalid Zone ";
511 throw SALOME::SALOME_Exception(es);
514 HOMARD::listeHypo* maListe = myZone->GetHypo();
515 int numberOfHypo = maListe->length();
516 MESSAGE( ".. numberOfHypo = " << numberOfHypo );
517 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
519 std::string nomHypo = std::string((*maListe)[NumeHypo]);
520 MESSAGE( ".. nomHypo = " << nomHypo );
521 InvalideHypo(nomHypo.c_str());
524 //=============================================================================
525 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
527 MESSAGE( "InvalideHypo : nomHypo = " << nomHypo );
528 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
529 if (CORBA::is_nil(myHypo))
531 SALOME::ExceptionStruct es;
532 es.type = SALOME::BAD_PARAM;
533 es.text = "Invalid Hypothesis ";
534 throw SALOME::SALOME_Exception(es);
538 HOMARD::listeIters* maListe = myHypo->GetIterations();
539 int numberOfIter = maListe->length();
540 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
542 std::string nomIter = std::string((*maListe)[NumeIter]);
543 MESSAGE( ".. nomIter = " << nomIter );
544 InvalideIter(nomIter.c_str());
547 //=============================================================================
548 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
550 MESSAGE("InvalideIter : nomIter = " << nomIter);
551 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
552 if (CORBA::is_nil(myIteration))
554 SALOME::ExceptionStruct es;
555 es.type = SALOME::BAD_PARAM;
556 es.text = "Invalid Iteration ";
557 throw SALOME::SALOME_Exception(es);
561 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
562 int numberOfIter = maListe->length();
563 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
565 std::string nomIterFille = std::string((*maListe)[NumeIter]);
566 MESSAGE ( ".. appel recursif de InvalideIter pour nomIter = " << nomIterFille.c_str() );
567 InvalideIter(nomIterFille.c_str());
570 // On arrive ici pour une iteration sans fille
571 MESSAGE ( "Invalidation effective de " << nomIter );
572 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
573 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
574 for (; aIter->More(); aIter->Next())
576 SALOMEDS::SObject_var so = aIter->Value();
577 SALOMEDS::GenericAttribute_var anAttr;
578 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
579 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
580 std::string value (aCommentAttr->Value());
581 if(value == std::string("HypoHomard")) continue;
582 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
583 aStudyBuilder->RemoveObject(so);
586 int number = myIteration->GetNumber();
589 SetEtatIter(nomIter,false);
590 const char * nomCas = myIteration->GetCaseName();
591 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
592 if (CORBA::is_nil(myCase))
594 SALOME::ExceptionStruct es;
595 es.type = SALOME::BAD_PARAM;
596 es.text = "Invalid Case Context ";
597 throw SALOME::SALOME_Exception(es);
600 const char* dirParent = myCase->GetDirName();
601 const char* nomDir = myIteration->GetDirName();
602 const char* nomFichier = myIteration->GetMeshFile();
603 std::string commande= "rm -rf " + std::string(dirParent) + "/" + std::string(nomDir);
604 commande = commande + ";rm -rf " + std::string(nomFichier);
605 if ((system(commande.c_str())) != 0)
607 SALOME::ExceptionStruct es;
608 es.type = SALOME::BAD_PARAM;
609 es.text = "Menage du repertoire de calcul impossible" ;
610 throw SALOME::SALOME_Exception(es);
613 // Suppression du maillage publie dans SMESH
614 const char* MeshName = myIteration->GetMeshName();
615 DeleteResultInSmesh(nomFichier, MeshName) ;
619 //=============================================================================
620 //=============================================================================
622 //=============================================================================
623 //=============================================================================
624 // Association de lien entre des structures identifiees par leurs noms
625 //=============================================================================
626 //=============================================================================
627 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
629 MESSAGE( "AssociateCaseIter : " << nomCas << " ," << nomIter << "," << labelIter );
631 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
632 if (CORBA::is_nil(myCase))
634 SALOME::ExceptionStruct es;
635 es.type = SALOME::BAD_PARAM;
636 es.text = "Invalid Case ";
637 throw SALOME::SALOME_Exception(es);
641 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
642 if (CORBA::is_nil(myIteration))
644 SALOME::ExceptionStruct es;
645 es.type = SALOME::BAD_PARAM;
646 es.text = "Invalid iteration ";
647 throw SALOME::SALOME_Exception(es);
651 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
652 SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
653 if (CORBA::is_nil(aCasSO))
655 SALOME::ExceptionStruct es;
656 es.type = SALOME::BAD_PARAM;
657 es.text = "Invalid Case ";
658 throw SALOME::SALOME_Exception(es);
662 aStudyBuilder->NewCommand();
663 SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
664 PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
665 "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
666 aStudyBuilder->CommitCommand();
668 myCase->AddIteration(nomIter);
669 myIteration->SetCaseName(nomCas);
671 //=====================================================================================
672 void HOMARD_Gen_i::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
674 MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
676 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
677 ASSERT(!CORBA::is_nil(myHypo));
678 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
679 ASSERT(!CORBA::is_nil(aHypoSO));
681 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
682 ASSERT(!CORBA::is_nil(myZone));
683 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
684 ASSERT(!CORBA::is_nil(aZoneSO));
686 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
688 aStudyBuilder->NewCommand();
690 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
691 aStudyBuilder->Addreference(aSubSO, aZoneSO);
693 aStudyBuilder->CommitCommand();
695 myZone->AddHypo(nomHypothesis);
696 myHypo->AddZone0(ZoneName, TypeUse);
698 //=============================================================================
699 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
701 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
703 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
704 ASSERT(!CORBA::is_nil(myHypo));
705 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
706 ASSERT(!CORBA::is_nil(aHypoSO));
708 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
709 ASSERT(!CORBA::is_nil(myIteration));
710 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
711 ASSERT(!CORBA::is_nil(aIterSO));
713 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
715 aStudyBuilder->NewCommand();
717 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
718 aStudyBuilder->Addreference(aSubSO, aHypoSO);
720 aStudyBuilder->CommitCommand();
722 myIteration->SetHypoName(nomHypo);
723 myHypo->LinkIteration(nomIter);
725 //=============================================================================
726 //=============================================================================
728 //=============================================================================
729 //=============================================================================
730 // Dissociation de lien entre des structures identifiees par leurs noms
731 //=============================================================================
732 //=============================================================================
733 void HOMARD_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
735 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
737 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
738 ASSERT(!CORBA::is_nil(myHypo));
739 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
740 ASSERT(!CORBA::is_nil(aHypoSO));
742 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
743 ASSERT(!CORBA::is_nil(myZone));
744 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
745 ASSERT(!CORBA::is_nil(aZoneSO));
747 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
749 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator(aHypoSO);
750 for (; it->More(); it->Next())
752 SALOMEDS::SObject_var aHypObj = it->Value();
753 SALOMEDS::SObject_var ptrObj;
754 if (aHypObj->ReferencedObject(ptrObj))
756 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
758 aStudyBuilder->NewCommand();
759 aStudyBuilder->RemoveObject(aHypObj);
760 aStudyBuilder->CommitCommand();
766 myZone->SupprHypo(nomHypothesis);
767 myHypo->SupprZone(ZoneName);
769 //=============================================================================
770 //=============================================================================
773 //=============================================================================
774 //=============================================================================
775 // Recuperation des listes
776 //=============================================================================
777 //=============================================================================
778 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
780 MESSAGE("GetAllCasesName");
783 HOMARD::listeCases_var ret = new HOMARD::listeCases;
784 ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
785 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
787 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
788 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
790 ret[i++] = CORBA::string_dup((*it).first.c_str());
795 //=============================================================================
796 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
798 MESSAGE("GetAllHypothesesName");
801 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
802 ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
803 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
805 for (it = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
806 it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
808 ret[i++] = CORBA::string_dup((*it).first.c_str());
813 //=============================================================================
814 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
816 MESSAGE("GetAllZonesName");
819 HOMARD::listeZones_var ret = new HOMARD::listeZones;
820 ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
821 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
823 for (it = myContextMap[GetCurrentStudyID()]._mesZones.begin();
824 it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
826 ret[i++] = CORBA::string_dup((*it).first.c_str());
831 //=============================================================================
832 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
834 MESSAGE("GetAllIterationsName");
837 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
838 ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
839 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
841 for (it = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
842 it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
844 ret[i++] = CORBA::string_dup((*it).first.c_str());
849 //=============================================================================
850 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
852 MESSAGE("GetAllBoundarysName");
855 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
856 ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
857 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
859 for (it = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
860 it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
862 ret[i++] = CORBA::string_dup((*it).first.c_str());
867 //=============================================================================
868 //=============================================================================
870 //=============================================================================
871 //=============================================================================
872 // Recuperation des structures identifiees par leurs noms
873 //=============================================================================
874 //=============================================================================
875 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
877 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
878 ASSERT(!CORBA::is_nil(myCase));
879 return HOMARD::HOMARD_Cas::_duplicate(myCase);
881 //=============================================================================
882 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
884 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
885 ASSERT(!CORBA::is_nil(myZone));
886 return HOMARD::HOMARD_Zone::_duplicate(myZone);
888 //=============================================================================
889 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
891 HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
892 ASSERT(!CORBA::is_nil(myHypothesis));
893 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
895 //=============================================================================
896 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* NomIterationation)
898 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIterationation];
899 ASSERT(!CORBA::is_nil(myIteration));
900 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
902 //=============================================================================
903 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
905 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
906 ASSERT(!CORBA::is_nil(myBoundary));
907 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
909 //=============================================================================
910 //=============================================================================
912 //=============================================================================
913 //=============================================================================
914 // Recuperation des structures par le contexte
915 //=============================================================================
916 //=============================================================================
917 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::LastIteration(const char* nomCas)
919 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
920 ASSERT(!CORBA::is_nil(myCase));
922 HOMARD::HOMARD_Iteration_var myIteration = myCase->LastIteration();
923 ASSERT(!CORBA::is_nil(myIteration));
925 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
927 //=============================================================================
928 //=============================================================================
930 //=============================================================================
931 //=============================================================================
932 // Nouvelles structures
933 //=============================================================================
934 //=============================================================================
935 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
937 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
938 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
939 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
940 return aCase._retn();
942 //=============================================================================
943 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
945 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
946 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
947 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
948 return aHypo._retn();
950 //=============================================================================
951 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
953 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
954 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
955 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
956 return aIter._retn();
958 //=============================================================================
959 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
961 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
962 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
963 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
964 return aBoundary._retn();
966 //=============================================================================
967 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
969 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
970 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
971 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
972 return aZone._retn();
974 //=============================================================================
975 //=============================================================================
977 //=============================================================================
978 //=============================================================================
979 // Creation des structures identifiees par leurs noms
980 //=============================================================================
981 //=============================================================================
982 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
984 MESSAGE ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
987 if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
989 SALOME::ExceptionStruct es;
990 es.type = SALOME::BAD_PARAM;
991 es.text = "This case has already been defined";
992 throw SALOME::SALOME_Exception(es);
996 int existe = MEDFileExist ( MeshFile ) ;
999 SALOME::ExceptionStruct es;
1000 es.type = SALOME::BAD_PARAM;
1001 es.text = "The mesh file does not exist.";
1002 throw SALOME::SALOME_Exception(es);
1006 HOMARD::HOMARD_Cas_var myCase = newCase();
1007 myCase->SetName(nomCas);
1008 SALOMEDS::SObject_var aSO;
1009 PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
1010 myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
1012 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile);
1013 HOMARD::extrema_var aSeq = new HOMARD::extrema();
1014 if (LesExtremes.size()!=10) { return false; }
1016 for (int i =0; i< LesExtremes.size(); i++)
1017 aSeq[i]=LesExtremes[i];
1018 myCase->SetBoundingBox(aSeq);
1020 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile);
1021 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType;
1022 aSeqGroupe->length(LesGroupes.size());
1023 std::set<std::string>::const_iterator it;
1025 for (it=LesGroupes.begin() ; it != LesGroupes.end(); it++)
1026 aSeqGroupe[i++]=(*it).c_str();
1027 myCase->SetGroups(aSeqGroupe);
1029 // Recherche d'un nom pour l'iteration 0. Par defaut, on prend le nom
1030 // du maillage du cas. Si ce nom existe deja, on incremente avec 0, 1, 2, etc.
1032 std::string NomIteration = std::string(MeshName) ;
1033 while ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()))
1035 std::ostringstream nom;
1036 nom << MeshName << monNum;
1037 NomIteration=nom.str();
1040 MESSAGE ( "CreateCase : NomIteration = " << NomIteration );
1042 HOMARD::HOMARD_Iteration_var anIter = newIteration();
1043 myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration] = anIter;
1044 std::ostringstream DirName;
1047 anIter->SetDirName(DirName.str().c_str());
1048 anIter->SetName(NomIteration.c_str());
1049 anIter->SetMeshFile(MeshFile);
1050 anIter->SetMeshName(MeshName);
1051 anIter->SetNumber(0);
1053 AssociateCaseIter (nomCas,NomIteration.c_str(),"IterationHomard");
1054 SetEtatIter(NomIteration.c_str(),true);
1056 PublishResultInSmesh(MeshFile, 0);
1058 // Valeurs par defaut des filtrages
1059 myCase->SetPyram(0);
1061 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1063 //=============================================================================
1064 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1066 MESSAGE ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1069 if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
1071 SALOME::ExceptionStruct es;
1072 es.type = SALOME::BAD_PARAM;
1073 es.text = "This hypothesis is already defined.";
1074 throw SALOME::SALOME_Exception(es);
1078 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1079 myHypothesis->SetName(nomHypothesis);
1080 myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
1081 SALOMEDS::SObject_var aSO;
1082 PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
1084 // Valeurs par defaut des options avancees
1085 myHypothesis->SetNivMax(-1);
1086 myHypothesis->SetDiamMin(-1.0);
1087 myHypothesis->SetAdapInit(0);
1088 myHypothesis->SetLevelOutput(0);
1090 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1093 //=============================================================================
1094 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1095 //=============================================================================
1097 MESSAGE ("CreateIteration : NomIteration = " << NomIteration << ", nomIterParent = " << nomIterParent);
1100 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
1101 if (CORBA::is_nil(myIterationParent))
1103 SALOME::ExceptionStruct es;
1104 es.type = SALOME::BAD_PARAM;
1105 es.text = "The parent iteration is not defined.";
1106 throw SALOME::SALOME_Exception(es);
1110 const char* nomCas = myIterationParent->GetCaseName();
1111 MESSAGE ("CreateIteration : nomCas = " << nomCas);
1112 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1113 if (CORBA::is_nil(myCase))
1115 SALOME::ExceptionStruct es;
1116 es.type = SALOME::BAD_PARAM;
1117 es.text = "Invalid Case Context ";
1118 throw SALOME::SALOME_Exception(es);
1122 if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
1124 SALOME::ExceptionStruct es;
1125 es.type = SALOME::BAD_PARAM;
1126 es.text = "This iteration is already defined. ";
1127 throw SALOME::SALOME_Exception(es);
1131 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1132 if (CORBA::is_nil(myIteration))
1134 SALOME::ExceptionStruct es;
1135 es.type = SALOME::BAD_PARAM;
1136 es.text = "Unable to create Iteration ";
1137 throw SALOME::SALOME_Exception(es);
1140 myContextMap[GetCurrentStudyID()]._mesIterations[std::string(NomIteration)] = myIteration;
1141 // Nom de l'iteration et du maillage
1142 myIteration->SetName(NomIteration);
1143 myIteration->SetMeshName(NomIteration);
1145 int numero = myIterationParent->GetNumber() + 1;
1146 myIteration->SetNumber(numero);
1148 // Nombre d'iterations deja connues pour le cas, permettant
1149 // la creation d'un sous-repertoire unique
1150 int nbitercase = myCase->GetNumber();
1151 std::ostringstream iaux ;
1152 iaux << std::setw(2) << std::setfill('0') << nbitercase ;
1153 std::stringstream DirName;
1154 DirName << "I" << iaux.str();
1155 myIteration->SetDirName(DirName.str().c_str());
1157 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1158 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1159 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1160 // situation la plus frequente.
1161 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1162 // le nombre d'iterations du cas permet d'eviter les collisions.
1163 std::stringstream MeshFile;
1164 const char* nomDir = myCase->GetDirName();
1165 MeshFile << nomDir << "/maill." << iaux.str() << ".med";
1166 myIteration->SetMeshFile(MeshFile.str().c_str());
1168 // Association avec le cas
1169 std::string label = "IterationHomard_" + std::string(nomIterParent);
1170 AssociateCaseIter(nomCas, NomIteration, label.c_str());
1171 // Lien avec l'iteration precedente
1172 myIterationParent->LinkNextIteration(NomIteration);
1173 myIteration->SetIterParentName(nomIterParent);
1175 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1177 //=============================================================================
1178 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1180 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1183 if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
1185 SALOME::ExceptionStruct es;
1186 es.type = SALOME::BAD_PARAM;
1187 es.text = "This boundary has already been defined";
1188 throw SALOME::SALOME_Exception(es);
1192 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1193 myBoundary->SetName(BoundaryName);
1194 myBoundary->SetType(BoundaryType);
1196 myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
1198 SALOMEDS::SObject_var aSO;
1199 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
1201 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1203 //=============================================================================
1204 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1206 MESSAGE ("CreateBoundaryDi : BoundaryName = " << BoundaryName << "MeshName = " << MeshName );
1207 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1208 myBoundary->SetMeshFile( MeshFile ) ;
1209 myBoundary->SetMeshName( MeshName ) ;
1211 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1213 //=============================================================================
1214 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1215 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1216 CORBA::Double Xaxis, CORBA::Double Yaxis, CORBA::Double Zaxis,
1217 CORBA::Double Rayon)
1219 MESSAGE ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
1220 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1221 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxis, Yaxis, Zaxis, Rayon ) ;
1223 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1225 //=============================================================================
1226 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1227 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1228 CORBA::Double Rayon)
1230 MESSAGE ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
1231 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1232 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1234 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1236 //=============================================================================
1237 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
1239 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
1242 if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
1244 SALOME::ExceptionStruct es;
1245 es.type = SALOME::BAD_PARAM;
1246 es.text = "This zone has already been defined";
1247 throw SALOME::SALOME_Exception(es);
1251 HOMARD::HOMARD_Zone_var myZone = newZone();
1252 myZone->SetName(ZoneName);
1253 myZone->SetType(ZoneType);
1255 myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
1257 SALOMEDS::SObject_var aSO;
1258 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
1260 return HOMARD::HOMARD_Zone::_duplicate(myZone);
1262 //=============================================================================
1263 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
1264 CORBA::Double Xmini, CORBA::Double Xmaxi,
1265 CORBA::Double Ymini, CORBA::Double Ymaxi,
1266 CORBA::Double Zmini, CORBA::Double Zmaxi)
1268 MESSAGE ("CreateZoneBox : ZoneName = " << ZoneName ) ;
1269 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
1270 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
1272 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1274 //=============================================================================
1275 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
1276 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
1278 MESSAGE ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
1279 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
1280 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1282 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1284 //=============================================================================
1285 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
1286 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1287 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1288 CORBA::Double Rayon, CORBA::Double Haut)
1290 MESSAGE ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
1291 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
1292 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
1294 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1296 //=============================================================================
1297 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
1298 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1299 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1300 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
1302 MESSAGE ("CreateZonePipe : ZoneName = " << ZoneName ) ;
1303 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
1304 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
1306 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1308 //=============================================================================
1309 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
1310 CORBA::Double Umini, CORBA::Double Umaxi,
1311 CORBA::Double Vmini, CORBA::Double Vmaxi,
1314 MESSAGE ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
1315 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
1316 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
1317 // MESSAGE ("Orient = " << Orient ) ;
1319 double Xmini, Xmaxi ;
1320 double Ymini, Ymaxi ;
1321 double Zmini, Zmaxi ;
1329 else if ( Orient == 2 )
1336 else if ( Orient == 3 )
1343 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
1345 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
1346 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
1348 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1350 //=============================================================================
1351 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
1352 CORBA::Double Ucentre, CORBA::Double Vcentre,
1353 CORBA::Double Rayon,
1356 MESSAGE ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
1361 { Xcentre = Ucentre ;
1364 else if ( Orient == 2 )
1367 Zcentre = Vcentre ; }
1368 else if ( Orient == 3 )
1369 { Xcentre = Vcentre ;
1371 Zcentre = Ucentre ; }
1372 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
1374 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
1375 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
1377 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1379 //=============================================================================
1380 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
1381 CORBA::Double Ucentre, CORBA::Double Vcentre,
1382 CORBA::Double Rayon, CORBA::Double Rayonint,
1385 MESSAGE ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
1390 { Xcentre = Ucentre ;
1393 else if ( Orient == 2 )
1396 Zcentre = Vcentre ; }
1397 else if ( Orient == 3 )
1398 { Xcentre = Vcentre ;
1400 Zcentre = Ucentre ; }
1401 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
1403 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
1404 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
1406 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1408 //=============================================================================
1409 //=============================================================================
1414 //=============================================================================
1415 //=============================================================================
1416 // Calcul d'une iteration
1417 //=============================================================================
1418 //=============================================================================
1419 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage)
1421 MESSAGE ( "Compute : calcul de " << NomIteration );
1423 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
1424 ASSERT(!CORBA::is_nil(myIteration));
1426 // on ne calcule pas l iteration 0
1427 int NumeIter = myIteration->GetNumber();
1428 if ( NumeIter == 0 )
1430 SALOME::ExceptionStruct es;
1431 es.type = SALOME::BAD_PARAM;
1432 es.text = "This iteration is the first of the case and cannot be computed.";
1433 throw SALOME::SALOME_Exception(es);
1437 // on verifie qu il y a une hypothese (erreur improbable);
1438 const char* nomHypo = myIteration->GetHypoName();
1439 if (std::string(nomHypo) == std::string(""))
1441 SALOME::ExceptionStruct es;
1442 es.type = SALOME::BAD_PARAM;
1443 es.text= "This iteration does not have any associated hypothesis.";
1444 throw SALOME::SALOME_Exception(es);
1447 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
1448 ASSERT(!CORBA::is_nil(myHypo));
1450 // A.4. L'iteration parent
1451 const char* nomIterationParent = myIteration->GetIterParentName();
1452 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
1453 ASSERT(!CORBA::is_nil(myIterationParent));
1454 if ( ! myIterationParent->GetEtat() )
1456 int codret = Compute(nomIterationParent, etatMenage);
1459 // GERALD -- QMESSAGE BOX
1460 ASSERT("Pb au calcul de l'iteration precedente" == 0);
1464 const char* nomCas = myIteration->GetCaseName();
1465 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1466 ASSERT(!CORBA::is_nil(myCase));
1469 std::stringstream saux0 ;
1470 saux0 << NumeIter - 1 ;
1471 std::string siter = saux0.str() ;
1472 if (NumeIter < 11) { siter = "0" + siter ; }
1474 std::stringstream saux1 ;
1476 std::string siterp1 = saux1.str() ;
1477 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
1479 // B. Les repertoires
1480 // B.1. Le repertoire du cas
1481 const char* nomDirCase = myCase->GetDirName();
1482 MESSAGE ( ". nomDirCase = " << nomDirCase );
1484 // B.2. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
1485 // B.2.1. Le nom du sous-repertoire
1486 const char* nomDirIt = myIteration->GetDirName();
1488 // B.2.2. Le nom complet du sous-repertoire
1489 std::stringstream DirCompute ;
1490 DirCompute << nomDirCase << "/" << nomDirIt;
1491 MESSAGE (". DirCompute = " << DirCompute.str() );
1493 // B.2.3. Si le sous-repertoire n'existe pas, on le cree
1494 // Si le sous-repertoire existe :
1495 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
1496 // etatMenage = 1 : on fait le menage du repertoire
1497 if (chdir(DirCompute.str().c_str()) != 0)
1499 // Creation du repertoire car il n'existe pas :
1500 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1502 // GERALD -- QMESSAGE BOX
1503 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
1504 ASSERT("Pb a la creation du repertoire" == 0);
1509 // Le repertoire existe et on fait le menage de son contenu :
1510 if (etatMenage != 0)
1512 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
1513 std::string commande= "rm -rf " + DirCompute.str()+"/*" ;
1514 int codret = system(commande.c_str());
1517 // GERALD -- QMESSAGE BOX
1518 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
1519 ASSERT("Pb au menage du repertoire de calcul" == 0);
1524 // Le repertoire existe et s'il n'est pas vide, on sort en erreur :
1526 struct dirent *dirp;
1527 dp = opendir(DirCompute.str().c_str());
1529 while ((dirp = readdir(dp)) != NULL && result )
1531 std::string file_name(dirp->d_name);
1532 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
1535 if ( result == false)
1537 SALOME::ExceptionStruct es;
1538 es.type = SALOME::BAD_PARAM;
1539 std::string text = "Directory : " + DirCompute.str() + "is not empty";
1540 es.text = CORBA::string_dup(text.c_str());
1541 throw SALOME::SALOME_Exception(es);
1547 // B.3. Le sous-repertoire de l'iteration precedente
1548 const char* nomDirItPa ;
1549 std::stringstream DirComputePa ;
1552 nomDirItPa = nomDirIt;
1553 DirComputePa << DirCompute.str();
1557 nomDirItPa = myIterationParent->GetDirName();
1558 DirComputePa << nomDirCase << "/" << nomDirItPa;
1560 MESSAGE( ". nomDirItPa = " << nomDirItPa);
1561 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
1563 // B.4. Le fichier des messages
1564 chdir(DirCompute.str().c_str()) ;
1565 std::string MessFile = DirCompute.str() + "/Liste." + siter + ".vers." + siterp1 ;
1566 MESSAGE (". MessFile = " << MessFile);
1567 myIteration->SetMessFile(MessFile.c_str());
1569 // C. On passe dans le repertoire de l'iteration a calculer
1570 chdir(DirCompute.str().c_str()) ;
1572 // D. Les donnees du calcul HOMARD
1573 // D.1. Le type de conformite
1574 int ConfType = myCase->GetConfType();
1575 MESSAGE ( ". ConfType = " << ConfType );
1577 // D.2. Le maillage n
1578 const char* NomMeshParent = myIterationParent->GetMeshName();
1579 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
1580 const char* MeshFileParent = myIterationParent->GetMeshFile();
1581 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
1583 // D.3. Le maillage n+1
1584 const char* NomMesh = myIteration->GetMeshName();
1585 MESSAGE ( ". NomMesh = " << NomMesh );
1586 const char* MeshFile = myIteration->GetMeshFile();
1587 MESSAGE ( ". MeshFile = " << MeshFile );
1588 FILE *file = fopen(MeshFile,"r");
1592 if (etatMenage == 0)
1594 SALOME::ExceptionStruct es;
1595 es.type = SALOME::BAD_PARAM;
1596 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
1597 es.text = CORBA::string_dup(text.c_str());
1598 throw SALOME::SALOME_Exception(es);
1603 std::string commande = "rm -f " + std::string(MeshFile);
1604 codret = system(commande.c_str());
1607 SALOME::ExceptionStruct es;
1608 es.type = SALOME::BAD_PARAM;
1609 std::string text = "PB with meshfile destruction ";
1610 es.text = CORBA::string_dup(text.c_str());
1611 throw SALOME::SALOME_Exception(es);
1621 // D.4. Les types de raffinement et de deraffinement
1622 // Les appels corba sont lourds, il vaut mieux les grouper
1623 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
1624 ASSERT(ListTypes->length() == 3);
1625 int TypeAdap = (*ListTypes)[0];
1626 int TypeRaff = (*ListTypes)[1];
1627 int TypeDera = (*ListTypes)[2];
1629 // D.6. L'option d'interpolation des champs
1630 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
1632 // E. Texte du fichier de configuration
1633 // E.1. Incontournables du texte
1634 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
1635 myDriver->TexteInit(DirCompute.str(), DirComputePa.str(),MessFile);
1636 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
1637 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
1638 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
1640 // E.2. Ajout des informations liees aux zones eventuelles
1643 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
1644 int numberOfZonesx2 = ListZone->length();
1647 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
1649 std::string ZoneName = std::string((*ListZone)[iaux]);
1650 MESSAGE ( "... ZoneName = " << ZoneName);
1651 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1652 ASSERT(!CORBA::is_nil(myZone));
1654 int ZoneType = myZone->GetType();
1655 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
1656 int TypeUse = atoi( TypeUsestr.c_str() );
1657 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
1658 NumZone = iaux/2 + 1 ;
1659 HOMARD::double_array* zone = myZone->GetCoords();
1660 if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
1662 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.);
1664 else if ( ZoneType == 4 ) // Cas d une sphere
1666 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.);
1668 else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
1670 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.);
1672 else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
1674 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]);
1676 else { ASSERT("ZoneType est incorrect." == 0) ; }
1680 // E.3. Ajout des informations liees aux champs eventuels
1683 // Le fichier du champ
1684 char* FieldFile = myIteration->GetFieldFile();
1685 MESSAGE ( ". FieldFile = " << FieldFile );
1686 if (strlen(FieldFile) == 0)
1688 // GERALD -- QMESSAGE BOX
1689 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1690 ASSERT("The file for the field is not given." == 0);
1692 // Les caracteristiques d'instants
1693 int TimeStep = myIteration->GetTimeStep();
1694 MESSAGE( ". TimeStep = " << TimeStep );
1695 int Rank = myIteration->GetRank();
1696 MESSAGE( ". Rank = " << Rank );
1697 // Les informations sur les champ
1698 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
1700 const char* FieldName = aInfosHypo->FieldName;
1702 int TypeThR = aInfosHypo->TypeThR;
1703 double ThreshR = aInfosHypo->ThreshR;
1704 int TypeThC = aInfosHypo->TypeThC;
1705 double ThreshC = aInfosHypo->ThreshC;
1706 // Saut entre mailles ou non ?
1707 int UsField = aInfosHypo->UsField;
1708 MESSAGE( ". UsField = " << UsField );
1709 // L'usage des composantes
1710 int UsCmpI = aInfosHypo->UsCmpI;
1711 MESSAGE( ". UsCmpI = " << UsCmpI );
1713 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
1716 HOMARD::listeComposantsHypo* mescompo = myHypo->GetListComp();
1717 int numberOfCompos = mescompo->length();
1718 MESSAGE( ". numberOfCompos = " << numberOfCompos );
1719 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
1721 std::string nomCompo = std::string((*mescompo)[NumeComp]);
1722 MESSAGE( "... nomCompo = " << nomCompo );
1723 myDriver->TexteCompo(NumeComp, nomCompo);
1726 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
1727 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
1728 int numberOfGroups = listeGroupes->length();
1729 MESSAGE( ". numberOfGroups = " << numberOfGroups );
1730 if (numberOfGroups > 0)
1733 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
1735 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
1736 MESSAGE( "... GroupName = " << GroupName );
1737 myDriver->TexteGroup(GroupName);
1741 // E.5. Ajout des informations liees a l'eventuel suivi de frontiere
1742 // On ecrit d'abord la definition des frontieres, puis les liens avec les groupes
1743 std::list<std::string> ListeBoundaryTraitees ;
1744 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
1745 int numberOfitems = ListBoundaryGroupType->length();
1746 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
1747 int BoundaryOption = 1 ;
1748 int NumBoundaryAnalytical = 0 ;
1749 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1751 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1752 MESSAGE ( "... BoundaryName = " << BoundaryName);
1754 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
1755 while (it != ListeBoundaryTraitees.end())
1757 MESSAGE ( "... BoundaryNameTraitee = " << *it);
1758 if ( BoundaryName == *it ) { A_faire = 0 ; }
1763 // Caracteristiques de la frontiere
1764 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1765 ASSERT(!CORBA::is_nil(myBoundary));
1766 int BoundaryType = myBoundary->GetType();
1767 MESSAGE ( "... BoundaryType = " << BoundaryType );
1768 // Ecriture selon le type
1769 if (BoundaryType == 0) // Cas d une frontiere discrete
1771 const char* MeshName = myBoundary->GetMeshName() ;
1772 const char* MeshFile = myBoundary->GetMeshFile() ;
1773 myDriver->TexteBoundaryDi( MeshName, MeshFile);
1774 BoundaryOption = BoundaryOption*2 ;
1776 else // Cas d une frontiere analytique
1778 NumBoundaryAnalytical++ ;
1779 HOMARD::double_array* coor = myBoundary->GetCoords();
1780 if (BoundaryType == 1) // Cas d un cylindre
1782 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6]);
1783 BoundaryOption = BoundaryOption*3 ;
1785 else if (BoundaryType == 2) // Cas d une sphere
1787 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0.);
1788 BoundaryOption = BoundaryOption*3 ;
1791 // Memorisation du traitement
1792 ListeBoundaryTraitees.push_back( BoundaryName );
1795 NumBoundaryAnalytical = 0 ;
1796 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1798 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1799 MESSAGE ( "... BoundaryName = " << BoundaryName);
1800 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1801 ASSERT(!CORBA::is_nil(myBoundary));
1802 int BoundaryType = myBoundary->GetType();
1803 MESSAGE ( "... BoundaryType = " << BoundaryType );
1804 // Recuperation du nom du groupe
1805 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
1806 MESSAGE ( "... GroupName = " << GroupName);
1807 if (BoundaryType == 0) // Cas d une frontiere discrete
1809 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
1811 else // Cas d une frontiere analytique
1813 NumBoundaryAnalytical++ ;
1814 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
1817 myDriver->TexteBoundaryOption(BoundaryOption);
1819 // E.6. Ajout des informations liees a l'eventuelle interpolation des champs
1820 MESSAGE( "... TypeFieldInterp = " << TypeFieldInterp );
1821 if (TypeFieldInterp != 0)
1823 // Le fichier des champs
1824 char* FieldFile = myIteration->GetFieldFile();
1825 MESSAGE ( ". FieldFile = " << FieldFile );
1826 if (strlen(FieldFile) == 0)
1828 // GERALD -- QMESSAGE BOX
1829 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1830 ASSERT("The file for the field is not given." == 0);
1832 // Les caracteristiques d'instants
1833 int TimeStep = myIteration->GetTimeStep();
1834 MESSAGE( ". TimeStep = " << TimeStep );
1835 int Rank = myIteration->GetRank();
1836 MESSAGE( ". Rank = " << Rank );
1838 myDriver->TexteFieldInterp(TypeFieldInterp, FieldFile, MeshFile, TimeStep, Rank);
1840 if (TypeFieldInterp == 2)
1842 HOMARD::listFieldInterpHypo* meschamps = myHypo->GetListFieldInterp();
1843 int numberOfFields = meschamps->length();
1844 MESSAGE( ". numberOfFields = " << numberOfFields );
1845 for (int NumeChamp = 0; NumeChamp< numberOfFields; NumeChamp++)
1847 std::string nomChamp = std::string((*meschamps)[NumeChamp]);
1848 MESSAGE( "... nomChamp = " << nomChamp );
1849 myDriver->TexteFieldInterpName(NumeChamp, nomChamp);
1853 // E.7. Ajout des options avancees
1854 int Pyram = myCase->GetPyram();
1855 MESSAGE ( ". Pyram = " << Pyram );
1856 int NivMax = myHypo->GetNivMax();
1857 MESSAGE ( ". NivMax = " << NivMax );
1858 double DiamMin = myHypo->GetDiamMin() ;
1859 MESSAGE ( ". DiamMin = " << DiamMin );
1860 int AdapInit = myHypo->GetAdapInit();
1861 MESSAGE ( ". AdapInit = " << AdapInit );
1862 int LevelOutput = myHypo->GetLevelOutput();
1863 MESSAGE ( ". LevelOutput = " << LevelOutput );
1864 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
1866 // F. Ecriture du texte dans le fichier
1869 myDriver->CreeFichier();
1874 int codretexec = 12 ;
1877 codretexec = myDriver->ExecuteHomard();
1879 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
1880 if (codretexec == 0)
1882 SetEtatIter(NomIteration,true);
1886 // GERALD -- QMESSAGE BOX
1887 SetEtatIter(NomIteration,false);
1891 // H. Gestion des resultats
1894 // H.1. Le fichier des messages, dans tous les cas
1895 std::stringstream saux1 ;
1896 saux1 << "Mess " << NumeIter ;
1897 PublishFileUnderIteration(NomIteration, MessFile.c_str(), saux1.str().c_str());
1899 // H.2. Si tout s'est bien passe :
1900 if (codretexec == 0)
1902 // H.2.1. Le fichier de bilan
1903 std::stringstream saux2 ;
1904 saux2 << "Summary " << NumeIter ;
1905 std::string SummaryFile = DirCompute.str() + "/apad." + siterp1 + ".bilan" ;
1906 PublishFileUnderIteration(NomIteration, SummaryFile.c_str(), saux2.str().c_str());
1907 // H.2.2. Le fichier de maillage obtenu
1908 std::stringstream saux0 ;
1909 saux0 <<"Iteration " << NumeIter ;
1910 PublishFileUnderIteration(NomIteration, MeshFile, saux0.str().c_str());
1911 PublishResultInSmesh(MeshFile, 1);
1913 // H.3 Message d'erreur en cas de probleme
1916 SALOME::ExceptionStruct es;
1917 es.type = SALOME::BAD_PARAM;
1918 std::string text = "Error during the adaptation.\n" ;
1921 ifstream fichier(MessFile.c_str(), ios::in);
1923 while(getline(fichier, ligne) and (ligne != "===== HOMARD ===== STOP ====="));
1924 while (getline(fichier, ligne)) { text += ligne+ "\n";};
1927 text += "no log file ....";
1929 es.text = CORBA::string_dup(text.c_str());
1930 throw SALOME::SALOME_Exception(es);
1934 // I. Menage et retour dans le repertoire du cas
1943 //===========================================================================
1945 //===========================================================================
1946 //===========================================================================
1948 //===========================================================================
1949 //===========================================================================
1950 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
1951 SALOMEDS::SObject_ptr theSObject,
1952 CORBA::Object_ptr theObject,
1953 const char* theName)
1955 MESSAGE("PublishInStudy pour " << theName);
1956 SALOMEDS::SObject_var aResultSO;
1957 if (CORBA::is_nil(theStudy))
1959 SALOME::ExceptionStruct es;
1960 es.type = SALOME::BAD_PARAM;
1961 es.text = "Invalid Study Context ";
1962 throw SALOME::SALOME_Exception(es);
1966 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
1967 // Rq : Iteration est publiee ailleurs
1968 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
1969 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
1970 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
1971 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
1973 addInStudy(theStudy);
1975 // Controle de la non publication d'un objet de meme nom
1976 if ((!aHypo->_is_nil()) or (!aZone->_is_nil()) or (!aBoundary->_is_nil()))
1978 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
1979 if (listSO->length() >= 1)
1981 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
1982 std::cerr <<"This name "<<theName<<" is already used "<<listSO->length()<<" time(s)" << std::endl;
1983 aResultSO = listSO[0];
1984 return aResultSO._retn();
1988 // Caracteristiques de l'etude
1989 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1990 aStudyBuilder->NewCommand();
1991 if(!aCase->_is_nil())
1992 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
1993 else if(!aHypo->_is_nil())
1994 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
1995 else if(!aZone->_is_nil())
1996 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
1997 else if(!aBoundary->_is_nil())
1998 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
2000 aStudyBuilder->CommitCommand();
2001 return aResultSO._retn();
2003 //=============================================================================
2004 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
2005 SALOMEDS::StudyBuilder_var aStudyBuilder,
2006 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
2008 MESSAGE("PublishCaseInStudy pour "<<theName);
2009 SALOMEDS::SObject_var aResultSO;
2010 SALOMEDS::GenericAttribute_var anAttr;
2012 if (CORBA::is_nil(theObject)) {
2013 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
2014 return aResultSO._retn();
2016 if (theStudy->_is_nil()) {
2017 MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
2018 return aResultSO._retn();
2021 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2022 if (theFatherHomard->_is_nil())
2024 MESSAGE("theFatherHomard->_is_nil()");
2025 return aResultSO._retn();
2028 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
2029 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
2030 _orb->object_to_string(theObject) ) ;
2031 return aResultSO._retn();
2034 //=============================================================================
2035 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
2036 SALOMEDS::StudyBuilder_var aStudyBuilder,
2037 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
2039 MESSAGE("PublishZoneStudy pour "<<theName);
2040 SALOMEDS::SObject_var aResultSO;
2041 SALOMEDS::GenericAttribute_var anAttr;
2043 if (CORBA::is_nil(theObject))
2045 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
2046 return aResultSO._retn();
2048 if (theStudy->_is_nil())
2050 MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
2051 return aResultSO._retn();
2053 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2054 if (theFatherHomard->_is_nil())
2056 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
2057 return aResultSO._retn();
2060 // Caracteristique de la zone
2061 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
2062 CORBA::Long ZoneType = myZone->GetType();
2064 // On ajoute la categorie des zones dans l etude si necessaire
2065 SALOMEDS::SObject_var aSOZone;
2066 if (!theFatherHomard->FindSubObject(100, aSOZone))
2068 MESSAGE("Ajout de la categorie des zones");
2069 aSOZone = aStudyBuilder->NewObjectToTag(theFatherHomard, 100);
2070 PublishInStudyAttr(aStudyBuilder, aSOZone, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
2072 else { MESSAGE("La categorie des zones existe deja."); }
2074 aResultSO = aStudyBuilder->NewObject(aSOZone);
2083 { icone = "boxdxy_2.png" ;
2087 { icone = "boxdxyz_2.png" ;
2095 { icone = "disk_2.png" ;
2099 { icone = "spherepoint_2.png" ;
2103 { icone = "cylinderpointvector_2.png" ;
2111 { icone = "diskwithhole_2.png" ;
2115 { icone = "pipe_2.png" ;
2119 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone, _orb->object_to_string(theObject) ) ;
2121 return aResultSO._retn();
2123 //=============================================================================
2124 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
2125 SALOMEDS::StudyBuilder_var aStudyBuilder,
2126 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
2128 MESSAGE("PublishBoundaryStudy pour "<<theName);
2129 SALOMEDS::SObject_var aResultSO;
2130 SALOMEDS::GenericAttribute_var anAttr;
2132 // Caracteristique de la Boundary
2133 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
2135 // On recupere le module pere dans l etude
2136 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2137 if (theFatherHomard->_is_nil())
2139 MESSAGE("theFatherHomard->_is_nil()");
2140 return aResultSO._retn();
2143 // On ajoute la categorie des boundarys dans l etude si necessaire
2144 SALOMEDS::SObject_var aSOBoundary;
2145 if (!theFatherHomard->FindSubObject(101, aSOBoundary))
2147 MESSAGE("Ajout de la categorie des boundarys");
2148 aSOBoundary = aStudyBuilder->NewObjectToTag(theFatherHomard, 101);
2149 PublishInStudyAttr(aStudyBuilder, aSOBoundary, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
2151 else { MESSAGE("La categorie des boundarys existe deja."); }
2153 aResultSO = aStudyBuilder->NewObject(aSOBoundary);
2154 CORBA::Long BoundaryType = myBoundary->GetType();
2155 // MESSAGE("BoundaryType : "<<BoundaryType);
2158 switch (BoundaryType)
2161 { value = "BoundaryDiHomard" ;
2162 icone = "mesh_tree_mesh.png" ;
2166 { value = "BoundaryAnHomard" ;
2167 icone = "cylinderpointvector_2.png" ;
2171 { value = "BoundaryAnHomard" ;
2172 icone = "spherepoint_2.png" ;
2176 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value, icone, _orb->object_to_string(theObject));
2177 return aResultSO._retn();
2180 //=============================================================================
2181 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
2182 SALOMEDS::StudyBuilder_var aStudyBuilder,
2183 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
2185 MESSAGE("PublishHypotheseInStudy pour "<<theName);
2186 SALOMEDS::SObject_var aResultSO;
2187 SALOMEDS::GenericAttribute_var anAttr;
2189 // On recupere le module pere dans l etude
2190 // On ajoute la categorie des hypotheses dans l etude si necessaire
2191 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2192 if (theFatherHomard->_is_nil())
2194 MESSAGE("theFatherHomard->_is_nil()");
2195 return aResultSO._retn();
2197 SALOMEDS::SObject_var aSOHypothese;
2198 if (!theFatherHomard->FindSubObject(0, aSOHypothese))
2200 MESSAGE("Ajout de la categorie des hypotheses");
2201 aSOHypothese = aStudyBuilder->NewObjectToTag(theFatherHomard, 0);
2202 PublishInStudyAttr(aStudyBuilder, aSOHypothese, "Hypothesis", "HypoList","hypotheses.png", NULL);
2204 else { MESSAGE("La categorie des hypotheses existe deja."); }
2206 // Creation du resultat dans l'etude
2207 aResultSO = aStudyBuilder->NewObject(aSOHypothese);
2208 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
2210 return aResultSO._retn();
2212 //===========================================================================
2213 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
2214 SALOMEDS::SObject_var aResultSO,
2215 const char* name, const char* value, const char* icone, const char* ior)
2217 SALOMEDS::GenericAttribute_var anAttr ;
2221 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
2222 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
2223 aNameAttrib->SetValue(name);
2226 // Ajout du commentaire
2227 if ( value != NULL )
2229 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
2230 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
2231 aCommentAttrib->SetValue(value);
2235 if ( icone != NULL )
2237 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO,"AttributePixMap");
2238 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
2239 aPixmap->SetPixMap(icone);
2245 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
2246 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2247 anIOR->SetValue(ior);
2251 //=====================================================================================
2252 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
2254 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
2256 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
2257 ASSERT(!CORBA::is_nil(myCase));
2258 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
2259 ASSERT(!CORBA::is_nil(aCaseSO));
2261 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2262 ASSERT(!CORBA::is_nil(myBoundary));
2263 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
2264 ASSERT(!CORBA::is_nil(aBoundarySO));
2266 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2268 aStudyBuilder->NewCommand();
2270 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
2271 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
2273 aStudyBuilder->CommitCommand();
2276 //=============================================================================
2277 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long IconeType)
2279 MESSAGE( "PublishResultInSmesh " << NomFich);
2280 if (CORBA::is_nil(myCurrentStudy))
2282 SALOME::ExceptionStruct es;
2283 es.type = SALOME::BAD_PARAM;
2284 es.text = "Invalid Study Context ";
2285 throw SALOME::SALOME_Exception(es);
2289 // Le module SMESH est-il actif ?
2290 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
2292 if (!CORBA::is_nil(aSmeshSO))
2294 // On verifie que le fichier n est pas deja publie
2295 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
2296 for (; aIter->More(); aIter->Next())
2298 SALOMEDS::SObject_var aSO = aIter->Value();
2299 SALOMEDS::GenericAttribute_var aGAttr;
2300 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
2302 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2303 CORBA::String_var value=anAttr->Value();
2304 if (strcmp((const char*)value,NomFich) == 0)
2306 // GERALD -- QMESSAGE BOX
2307 std::cerr << "fichier : "<< NomFich << " deja publie "<< std::endl;
2315 // On enregistre le fichier
2316 MESSAGE( "Enregistrement du fichier");
2317 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
2318 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
2319 ASSERT(!CORBA::is_nil(aSmeshEngine));
2320 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
2321 SMESH::DriverMED_ReadStatus theStatus;
2322 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
2324 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
2325 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
2326 for (int i = 0; i < mesMaillages->length(); i++)
2328 MESSAGE( ". Mise a jour des attributs du maillage");
2329 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
2330 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
2331 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2332 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
2333 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2334 anAttr->SetValue(NomFich);
2335 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
2336 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
2337 // IconeType = 0 : fichier issu d'une importation
2338 // IconeType = 1 : fichier issu d'une execution HOMARD
2340 if ( IconeType == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
2341 else { icone = "mesh_tree_mesh.png" ; }
2342 anAttr2->SetPixMap( icone );
2346 //=============================================================================
2347 void HOMARD_Gen_i::DeleteResultInSmesh(const char* NomFich, const char* MeshName)
2349 MESSAGE (" DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
2350 if (CORBA::is_nil(myCurrentStudy))
2352 SALOME::ExceptionStruct es;
2353 es.type = SALOME::BAD_PARAM;
2354 es.text = "Invalid Study Context ";
2355 throw SALOME::SALOME_Exception(es);
2359 // Le module SMESH est-il actif ?
2360 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
2362 if (CORBA::is_nil(aSmeshSO))
2366 // On verifie que le fichier est deja publie
2367 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
2368 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
2369 for (; aIter->More(); aIter->Next())
2371 SALOMEDS::SObject_var aSO = aIter->Value();
2372 SALOMEDS::GenericAttribute_var aGAttr;
2373 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
2375 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2376 CORBA::String_var value=anAttr->Value();
2377 if (strcmp((const char*)value,NomFich) == 0)
2379 if (aSO->FindAttribute(aGAttr,"AttributeName"))
2381 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
2382 CORBA::String_var value2=anAttr2->Value();
2383 if (strcmp((const char*)value2,MeshName) == 0)
2385 myBuilder->RemoveObjectWithChildren( aSO ) ;
2393 //=============================================================================
2394 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
2396 if (CORBA::is_nil(myCurrentStudy))
2398 SALOME::ExceptionStruct es;
2399 es.type = SALOME::BAD_PARAM;
2400 es.text = "Invalid Study Context ";
2401 throw SALOME::SALOME_Exception(es);
2405 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
2406 if (CORBA::is_nil(myIteration))
2408 SALOME::ExceptionStruct es;
2409 es.type = SALOME::BAD_PARAM;
2410 es.text = "Invalid Iteration ";
2411 throw SALOME::SALOME_Exception(es);
2414 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
2415 if (CORBA::is_nil(myIteration))
2417 SALOME::ExceptionStruct es;
2418 es.type = SALOME::BAD_PARAM;
2419 es.text = "Invalid Iteration Study Object";
2420 throw SALOME::SALOME_Exception(es);
2424 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2426 aStudyBuilder->NewCommand();
2428 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
2429 // Pour les fichiers med, on affiche une icone de maillage
2430 // Pour les fichiers qui sont texte, on affiche une icone de fichier texte 'texte'
2431 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
2433 const char* ior = " " ;
2434 if ( Commentaire[0] == 'I' )
2435 { icone = "med.png" ; }
2437 { icone = "texte_2.png" ; }
2438 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone, ior ) ;
2440 aStudyBuilder->CommitCommand();
2442 //=============================================================================
2443 //=============================================================================
2445 //=============================================================================
2446 //=============================================================================
2447 // Next functions are inherited from SALOMEDS::Driver interface
2448 //=============================================================================
2449 //=============================================================================
2450 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
2452 CORBA::Boolean isMultiFile)
2454 MESSAGE (" Save for theURL = "<< theURL);
2455 SALOMEDS::TMPFile_var aStreamFile;
2457 // get temporary directory name
2458 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2460 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2461 StudyContext& context = myContextMap[ aStudy->StudyId() ];
2463 // HOMARD data file name
2464 std::string aFileName = "";
2466 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2467 aFileName += "_HOMARD.dat";
2469 // initialize sequence of file names
2470 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
2471 aFileSeq->length(1);
2472 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
2474 // get full path to the data file
2475 aFileName = tmpDir + aFileName;
2479 std::ofstream f(aFileName.c_str());
2481 // clear temporary id map
2482 context._idmap.clear();
2487 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
2488 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
2489 HOMARD::HOMARD_Cas_var aCas = it_case->second;
2490 PortableServer::ServantBase_var aServant = GetServant(aCas);
2491 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2493 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
2494 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
2498 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2499 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
2500 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
2501 PortableServer::ServantBase_var aServant = GetServant(aZone);
2502 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2504 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
2505 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2508 // -> save hypotheses
2509 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2510 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
2511 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
2512 PortableServer::ServantBase_var aServant = GetServant(aHypo);
2513 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2515 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
2516 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2519 // -> save iterations
2520 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2521 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
2522 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
2523 PortableServer::ServantBase_var aServant = GetServant(aIter);
2524 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2526 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
2527 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2530 // -> save boundaries
2531 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2532 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
2533 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
2534 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2535 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2536 if (aBoundaryServant) {
2537 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
2538 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2542 MESSAGE ("close file");
2545 // put temporary files to the stream
2546 MESSAGE ("put temporary files to the stream");
2547 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
2549 // remove temporary files
2550 MESSAGE ("remove temporary files");
2551 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2553 // return data stream
2554 MESSAGE ("return data stream");
2555 return aStreamFile._retn();
2558 //===========================================================================
2559 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
2561 CORBA::Boolean isMultiFile)
2563 // No specific ASCII persistence
2564 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
2565 return aStreamFile._retn();
2568 //===========================================================================
2569 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
2570 const SALOMEDS::TMPFile& theStream,
2572 CORBA::Boolean isMultiFile)
2574 MESSAGE (" Load pour theURL = "<< theURL);
2575 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2577 // set current study
2578 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
2579 SetCurrentStudy(aStudy);
2581 // get temporary directory name
2582 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2584 // Convert the stream into sequence of files to process
2585 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
2588 // HOMARD data file name
2589 std::string aFileName = "";
2591 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2592 aFileName = tmpDir + aFileName + "_HOMARD.dat";
2594 StudyContext& context = myContextMap[ aStudy->StudyId() ];
2598 std::ifstream f(aFileName.c_str());
2601 context._mesCas.clear();
2602 context._mesHypotheses.clear();
2603 context._mesIterations.clear();
2604 context._mesZones.clear();
2605 context._mesBoundarys.clear();
2606 context._idmap.clear();
2612 std::getline(f, line);
2613 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
2614 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
2615 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
2616 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
2617 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
2618 if (line.substr(0, caseSignature.size()) == caseSignature) {
2620 MESSAGE (" Recreation du cas" );
2621 HOMARD::HOMARD_Cas_var aCase = newCase();
2622 PortableServer::ServantBase_var aServant = GetServant(aCase);
2623 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2624 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
2625 context._mesCas[aCase->GetName()] = aCase;
2626 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
2629 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
2630 MESSAGE (" Recreation de la zone" );
2632 HOMARD::HOMARD_Zone_var aZone = newZone();
2633 PortableServer::ServantBase_var aServant = GetServant(aZone);
2634 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2635 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
2636 context._mesZones[aZone->GetName()] = aZone;
2637 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2640 else if (line.substr(0, iterSignature.size()) == iterSignature) {
2641 // re-create iteration
2642 MESSAGE (" Recreation de l iteration" );
2643 HOMARD::HOMARD_Iteration_var aIter = newIteration();
2644 PortableServer::ServantBase_var aServant = GetServant(aIter);
2645 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2646 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
2647 context._mesIterations[aIter->GetName()] = aIter;
2648 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2651 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
2652 // re-create hypothesis
2653 MESSAGE (" Recreation de l hypothese" );
2654 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
2655 PortableServer::ServantBase_var aServant = GetServant(aHypo);
2656 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2657 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
2658 context._mesHypotheses[aHypo->GetName()] = aHypo;
2659 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2662 else if (line.substr(0, bounSignature.size()) == bounSignature) {
2663 // re-create boundary
2664 MESSAGE (" Recreation de la frontiere" );
2665 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
2666 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2667 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2668 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
2669 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
2670 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2679 // Remove temporary files created from the stream
2681 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2686 //===========================================================================
2687 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
2688 const SALOMEDS::TMPFile& theStream,
2690 CORBA::Boolean isMultiFile)
2692 // No specific ASCII persistence
2693 return Load(theComponent, theStream, theURL, isMultiFile);
2696 //===========================================================================
2697 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
2699 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
2700 // clearing study context should be done here:
2701 // - destroy all servants and related CORBA objects
2703 // - remove context from myContextMap
2704 myContextMap.erase(theComponent->GetStudy()->StudyId());
2705 // - nullify myCurrentStudy
2706 myCurrentStudy = SALOMEDS::Study::_nil();
2710 //===========================================================================
2711 char* HOMARD_Gen_i::ComponentDataType()
2713 return CORBA::string_dup("HOMARD");
2716 //===========================================================================
2717 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
2718 const char* IORString,
2719 CORBA::Boolean isMultiFile,
2720 CORBA::Boolean isASCII)
2722 CORBA::String_var aString("");
2723 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
2724 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2725 CORBA::Object_var anObj = _orb->string_to_object(IORString);
2726 if (!CORBA::is_nil(anObj)) {
2727 PortableServer::ServantBase_var aServant = GetServant(anObj);
2728 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
2730 std::map<int, PortableServer::ServantBase*>::const_iterator it;
2731 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
2732 if (it->second == aStorable) {
2733 std::stringstream os;
2735 aString = CORBA::string_dup(os.str().c_str());
2741 return aString._retn();
2744 //===========================================================================
2745 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
2746 const char* aLocalPersistentID,
2747 CORBA::Boolean isMultiFile,
2748 CORBA::Boolean isASCII)
2750 CORBA::String_var aString("");
2751 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
2752 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2753 int id = atoi(aLocalPersistentID);
2754 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
2755 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
2756 if (!CORBA::is_nil(object)) {
2757 aString = _orb->object_to_string(object);
2761 return aString._retn();
2764 //===========================================================================
2765 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
2767 if(CORBA::is_nil(myCurrentStudy))
2770 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
2771 if(!aCas->_is_nil())
2774 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
2775 if(!aHypo->_is_nil())
2778 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
2779 if(!aZone->_is_nil())
2782 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
2783 if(!aBoundary->_is_nil())
2786 /* Iteration is not published directly
2787 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
2788 if(!aIter->_is_nil())
2794 //===========================================================================
2795 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
2797 // No Copy/Paste support
2801 //===========================================================================
2802 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
2803 CORBA::Long& theObjectID)
2805 // No Copy/Paste support
2806 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
2807 return aStreamFile._retn();
2810 //===========================================================================
2811 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
2812 CORBA::Long theObjectID)
2814 // No Copy/Paste support
2818 //===========================================================================
2819 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
2820 CORBA::Long theObjectID,
2821 SALOMEDS::SObject_ptr theSObject)
2823 // No Copy/Paste support
2824 SALOMEDS::SObject_var aResultSO;
2825 return aResultSO._retn();
2828 //===========================================================================
2829 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
2831 PortableServer::Servant aServant = 0;
2832 if (!CORBA::is_nil(theObject)) {
2834 aServant = _poa->reference_to_servant(theObject);
2842 //==========================================================================
2843 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
2844 CORBA::Boolean isPublished,
2845 CORBA::Boolean isMultiFile,
2846 CORBA::Boolean& isValidScript)
2848 MESSAGE ("Entree dans DumpPython");
2850 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
2851 if(CORBA::is_nil(aStudy))
2852 return new Engines::TMPFile(0);
2854 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
2855 if(CORBA::is_nil(aSO))
2856 return new Engines::TMPFile(0);
2858 std::string aScript = "\"\"\"\n";
2859 aScript += "Python script for HOMARD\n";
2860 aScript += "Copyright EDF-R&D 2013\n";
2861 aScript += "\"\"\"\n";
2862 aScript += "__revision__ = \"V1.2\"\n";
2863 aScript += "import HOMARD\n";
2865 aScript += "import salome\n";
2866 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
2868 aScript += "def RebuildData(theStudy):\n";
2869 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
2872 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
2873 MESSAGE (". Au depart \n"<<aScript);
2876 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
2878 MESSAGE (". Ecritures des frontieres");
2879 aScript += "#\n# Creation of the boundaries";
2880 aScript += "\n# ==========================";
2882 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2883 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
2884 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
2886 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
2887 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
2888 std::string dumpBoundary = dumpCorbaBoundary.in();
2889 MESSAGE (dumpBoundary<<"\n");
2890 aScript += dumpBoundary;
2894 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
2896 MESSAGE (". Ecritures des zones");
2897 aScript += "#\n# Creation of the zones";
2898 aScript += "\n# =====================";
2900 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2901 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
2902 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
2904 HOMARD::HOMARD_Zone_var maZone = (*it_zone).second;
2905 CORBA::String_var dumpCorbaZone = maZone->GetDumpPython();
2906 std::string dumpZone = dumpCorbaZone.in();
2907 MESSAGE (dumpZone<<"\n");
2908 aScript += dumpZone;
2912 if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
2914 MESSAGE (". Ecritures des hypotheses");
2915 aScript += "#\n# Creation of the hypotheses";
2916 aScript += "\n# ==========================";
2918 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2919 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
2920 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
2922 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
2923 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
2924 std::string dumpHypo = dumpCorbaHypo.in();
2925 MESSAGE (dumpHypo<<"\n");
2926 aScript += dumpHypo;
2930 if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
2932 MESSAGE (". Ecritures des cas");
2933 aScript += "#\n# Creation of the cases";
2934 aScript += "\n# =====================";
2936 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
2937 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
2938 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
2940 std::string nomCas = (*it_cas).first;
2941 std::string dumpCas = std::string("\n# Creation of the case ") ;
2942 dumpCas += nomCas + std::string("\n");
2943 dumpCas += std::string("\t") + nomCas;
2944 dumpCas += std::string(" = homard.CreateCase('") + nomCas + std::string("', '");
2946 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
2947 CORBA::String_var cIter0= myCase->GetIter0Name();
2948 std::string iter0 = cIter0.in();
2950 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
2951 CORBA::String_var cMesh0= myIteration->GetMeshFile();
2952 std::string mesh0 = cMesh0.in();
2953 CORBA::String_var cMeshName0= myIteration->GetMeshName();
2954 std::string meshName0 = cMeshName0.in();
2955 dumpCas += meshName0 + std::string("', '")+ mesh0 + std::string("')\n");
2956 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
2957 std::string dumpCas2= dumpCorbaCase.in();
2959 MESSAGE (dumpCas<<dumpCas2<<"\n");
2960 aScript += dumpCas + dumpCas2;
2964 if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
2966 MESSAGE (". Ecritures des iterations");
2967 aScript += "#\n# Creation of the iterations" ;
2968 aScript += "\n# ==========================";
2970 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2971 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
2972 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
2974 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
2975 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
2976 std::string dumpIter = dumpCorbaIter.in();
2977 MESSAGE (dumpIter<<"\n");
2978 aScript += dumpIter;
2981 MESSAGE (". Ecritures finales");
2983 aScript += "\n\tpass";
2986 if( !isMultiFile ) // remove unnecessary tabulation
2987 aScript = RemoveTabulation( aScript );
2989 // MESSAGE ("A ecrire \n"<<aScript);
2990 const size_t aLen = strlen(aScript.c_str());
2991 char* aBuffer = new char[aLen+1];
2992 strcpy(aBuffer, aScript.c_str());
2994 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
2995 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
2997 MESSAGE ("Sortie de DumpPython");
2998 return aStreamFile._retn();
3002 //=============================================================================
3003 //=============================================================================
3005 //=============================================================================
3006 //=============================================================================
3007 void HOMARD_Gen_i::IsValidStudy( )
3009 // MESSAGE( "IsValidStudy" );
3010 if (CORBA::is_nil(myCurrentStudy))
3012 SALOME::ExceptionStruct es;
3013 es.type = SALOME::BAD_PARAM;
3014 es.text = "Invalid Study Context";
3015 throw SALOME::SALOME_Exception(es);
3020 //=============================================================================
3021 CORBA::Boolean HOMARD_Gen_i::VerifieDir(const char* nomDir)
3023 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
3024 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
3025 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
3027 if (std::string(nomDir) == std::string(it->second->GetDirName())) return false;
3031 /*//=============================================================================
3032 void SALOMEException( std::string message )
3034 SALOME::ExceptionStruct es;
3035 es.type = SALOME::BAD_PARAM;
3037 throw SALOME::SALOME_Exception(es);
3040 //=============================================================================
3041 char* HOMARD_Gen_i::getVersion()
3043 #if HOMARD_DEVELOPMENT
3044 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
3046 return CORBA::string_dup(HOMARD_VERSION_STR);
3050 //=============================================================================
3053 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
3054 PortableServer::POA_ptr poa,
3055 PortableServer::ObjectId* contId,
3056 const char* instanceName,
3057 const char* interfaceName)
3059 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
3060 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
3061 return myHOMARD_Gen->getId();