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 );
1425 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
1426 ASSERT(!CORBA::is_nil(myIteration));
1428 // A.2. On ne calcule pas l iteration 0
1429 int NumeIter = myIteration->GetNumber();
1430 if ( NumeIter == 0 )
1432 SALOME::ExceptionStruct es;
1433 es.type = SALOME::BAD_PARAM;
1434 es.text = "This iteration is the first of the case and cannot be computed.";
1435 throw SALOME::SALOME_Exception(es);
1439 // A.3. On verifie qu il y a une hypothese (erreur improbable);
1440 const char* nomHypo = myIteration->GetHypoName();
1441 if (std::string(nomHypo) == std::string(""))
1443 SALOME::ExceptionStruct es;
1444 es.type = SALOME::BAD_PARAM;
1445 es.text= "This iteration does not have any associated hypothesis.";
1446 throw SALOME::SALOME_Exception(es);
1449 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
1450 ASSERT(!CORBA::is_nil(myHypo));
1452 // A.4. L'iteration parent
1453 const char* nomIterationParent = myIteration->GetIterParentName();
1454 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
1455 ASSERT(!CORBA::is_nil(myIterationParent));
1456 if ( ! myIterationParent->GetEtat() )
1458 int codret = Compute(nomIterationParent, etatMenage);
1461 // GERALD -- QMESSAGE BOX
1462 ASSERT("Pb au calcul de l'iteration precedente" == 0);
1467 const char* nomCas = myIteration->GetCaseName();
1468 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1469 ASSERT(!CORBA::is_nil(myCase));
1471 // A.6. Les numeros d'iterations
1473 std::stringstream saux0 ;
1474 saux0 << NumeIter - 1 ;
1475 std::string siter = saux0.str() ;
1476 if (NumeIter < 11) { siter = "0" + siter ; }
1478 std::stringstream saux1 ;
1480 std::string siterp1 = saux1.str() ;
1481 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
1483 // B. Les repertoires
1484 // B.1. Le repertoire courant
1485 char* nomDirWork = getenv("PWD") ;
1486 // B.2. Le repertoire du cas
1487 const char* nomDirCase = myCase->GetDirName();
1488 MESSAGE ( ". nomDirCase = " << nomDirCase );
1490 // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
1491 // B.3.1. Le nom du sous-repertoire
1492 const char* nomDirIt = myIteration->GetDirName();
1494 // B.3.2. Le nom complet du sous-repertoire
1495 std::stringstream DirCompute ;
1496 DirCompute << nomDirCase << "/" << nomDirIt;
1497 MESSAGE (". DirCompute = " << DirCompute.str() );
1499 // B.3.3. Si le sous-repertoire n'existe pas, on le cree
1500 // Si le sous-repertoire existe :
1501 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
1502 // etatMenage = 1 : on fait le menage du repertoire
1503 if (chdir(DirCompute.str().c_str()) != 0)
1505 // Creation du repertoire car il n'existe pas :
1506 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1508 // GERALD -- QMESSAGE BOX
1509 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
1510 ASSERT("Pb a la creation du repertoire" == 0);
1515 // Le repertoire existe
1516 // On demande de faire le menage de son contenu :
1517 if (etatMenage != 0)
1519 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
1520 std::string commande= "rm -rf " + DirCompute.str()+"/*" ;
1521 int codret = system(commande.c_str());
1524 // GERALD -- QMESSAGE BOX
1525 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
1526 ASSERT("Pb au menage du repertoire de calcul" == 0);
1529 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
1533 struct dirent *dirp;
1534 dp = opendir(DirCompute.str().c_str());
1536 while ((dirp = readdir(dp)) != NULL && result )
1538 std::string file_name(dirp->d_name);
1539 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
1542 if ( result == false)
1544 SALOME::ExceptionStruct es;
1545 es.type = SALOME::BAD_PARAM;
1546 std::string text = "Directory : " + DirCompute.str() + "is not empty";
1547 es.text = CORBA::string_dup(text.c_str());
1548 throw SALOME::SALOME_Exception(es);
1554 // B.4. Le sous-repertoire de l'iteration precedente
1555 const char* nomDirItPa ;
1556 std::stringstream DirComputePa ;
1559 nomDirItPa = nomDirIt;
1560 DirComputePa << DirCompute.str();
1564 nomDirItPa = myIterationParent->GetDirName();
1565 DirComputePa << nomDirCase << "/" << nomDirItPa;
1567 MESSAGE( ". nomDirItPa = " << nomDirItPa);
1568 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
1570 // B.5. Le fichier des messages
1571 std::string MessFile = DirCompute.str() + "/Liste." + siter + ".vers." + siterp1 ;
1572 MESSAGE (". MessFile = " << MessFile);
1573 myIteration->SetMessFile(MessFile.c_str());
1575 // C. On passe dans le repertoire de l'iteration a calculer
1576 MESSAGE ( ". On passe dans DirCompute = " << DirCompute.str() );
1577 chdir(DirCompute.str().c_str()) ;
1579 // D. Les donnees du calcul HOMARD
1580 // D.1. Le type de conformite
1581 int ConfType = myCase->GetConfType();
1582 MESSAGE ( ". ConfType = " << ConfType );
1584 // D.2. Le maillage n
1585 const char* NomMeshParent = myIterationParent->GetMeshName();
1586 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
1587 const char* MeshFileParent = myIterationParent->GetMeshFile();
1588 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
1590 // D.3. Le maillage n+1
1591 const char* NomMesh = myIteration->GetMeshName();
1592 MESSAGE ( ". NomMesh = " << NomMesh );
1593 const char* MeshFile = myIteration->GetMeshFile();
1594 MESSAGE ( ". MeshFile = " << MeshFile );
1595 FILE *file = fopen(MeshFile,"r");
1599 if (etatMenage == 0)
1601 SALOME::ExceptionStruct es;
1602 es.type = SALOME::BAD_PARAM;
1603 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
1604 es.text = CORBA::string_dup(text.c_str());
1605 throw SALOME::SALOME_Exception(es);
1610 std::string commande = "rm -f " + std::string(MeshFile);
1611 codret = system(commande.c_str());
1614 SALOME::ExceptionStruct es;
1615 es.type = SALOME::BAD_PARAM;
1616 std::string text = "PB with meshfile destruction ";
1617 es.text = CORBA::string_dup(text.c_str());
1618 throw SALOME::SALOME_Exception(es);
1628 // D.4. Les types de raffinement et de deraffinement
1629 // Les appels corba sont lourds, il vaut mieux les grouper
1630 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
1631 ASSERT(ListTypes->length() == 3);
1632 int TypeAdap = (*ListTypes)[0];
1633 int TypeRaff = (*ListTypes)[1];
1634 int TypeDera = (*ListTypes)[2];
1636 // D.5. L'option d'interpolation des champs
1637 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
1639 // E. Texte du fichier de configuration
1640 // E.1. Incontournables du texte
1641 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
1642 myDriver->TexteInit(DirCompute.str(), DirComputePa.str(),MessFile);
1643 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
1644 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
1645 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
1647 // E.2. Ajout des informations liees aux zones eventuelles
1650 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
1651 int numberOfZonesx2 = ListZone->length();
1654 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
1656 std::string ZoneName = std::string((*ListZone)[iaux]);
1657 MESSAGE ( "... ZoneName = " << ZoneName);
1658 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1659 ASSERT(!CORBA::is_nil(myZone));
1661 int ZoneType = myZone->GetType();
1662 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
1663 int TypeUse = atoi( TypeUsestr.c_str() );
1664 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
1665 NumZone = iaux/2 + 1 ;
1666 HOMARD::double_array* zone = myZone->GetCoords();
1667 if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
1669 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.);
1671 else if ( ZoneType == 4 ) // Cas d une sphere
1673 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.);
1675 else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
1677 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.);
1679 else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
1681 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]);
1683 else { ASSERT("ZoneType est incorrect." == 0) ; }
1687 // E.3. Ajout des informations liees aux champs eventuels
1690 // Le fichier du champ
1691 char* FieldFile = myIteration->GetFieldFile();
1692 MESSAGE ( ". FieldFile = " << FieldFile );
1693 if (strlen(FieldFile) == 0)
1695 // GERALD -- QMESSAGE BOX
1696 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1697 ASSERT("The file for the field is not given." == 0);
1699 // Les caracteristiques d'instants
1700 int TimeStep = myIteration->GetTimeStep();
1701 MESSAGE( ". TimeStep = " << TimeStep );
1702 int Rank = myIteration->GetRank();
1703 MESSAGE( ". Rank = " << Rank );
1704 // Les informations sur les champ
1705 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
1707 const char* FieldName = aInfosHypo->FieldName;
1709 int TypeThR = aInfosHypo->TypeThR;
1710 double ThreshR = aInfosHypo->ThreshR;
1711 int TypeThC = aInfosHypo->TypeThC;
1712 double ThreshC = aInfosHypo->ThreshC;
1713 // Saut entre mailles ou non ?
1714 int UsField = aInfosHypo->UsField;
1715 MESSAGE( ". UsField = " << UsField );
1716 // L'usage des composantes
1717 int UsCmpI = aInfosHypo->UsCmpI;
1718 MESSAGE( ". UsCmpI = " << UsCmpI );
1720 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
1723 HOMARD::listeComposantsHypo* mescompo = myHypo->GetListComp();
1724 int numberOfCompos = mescompo->length();
1725 MESSAGE( ". numberOfCompos = " << numberOfCompos );
1726 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
1728 std::string nomCompo = std::string((*mescompo)[NumeComp]);
1729 MESSAGE( "... nomCompo = " << nomCompo );
1730 myDriver->TexteCompo(NumeComp, nomCompo);
1733 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
1734 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
1735 int numberOfGroups = listeGroupes->length();
1736 MESSAGE( ". numberOfGroups = " << numberOfGroups );
1737 if (numberOfGroups > 0)
1740 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
1742 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
1743 MESSAGE( "... GroupName = " << GroupName );
1744 myDriver->TexteGroup(GroupName);
1748 // E.5. Ajout des informations liees a l'eventuel suivi de frontiere
1749 // On ecrit d'abord la definition des frontieres, puis les liens avec les groupes
1750 std::list<std::string> ListeBoundaryTraitees ;
1751 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
1752 int numberOfitems = ListBoundaryGroupType->length();
1753 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
1754 int BoundaryOption = 1 ;
1755 int NumBoundaryAnalytical = 0 ;
1756 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1758 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1759 MESSAGE ( "... BoundaryName = " << BoundaryName);
1761 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
1762 while (it != ListeBoundaryTraitees.end())
1764 MESSAGE ( "... BoundaryNameTraitee = " << *it);
1765 if ( BoundaryName == *it ) { A_faire = 0 ; }
1770 // Caracteristiques de la frontiere
1771 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1772 ASSERT(!CORBA::is_nil(myBoundary));
1773 int BoundaryType = myBoundary->GetType();
1774 MESSAGE ( "... BoundaryType = " << BoundaryType );
1775 // Ecriture selon le type
1776 if (BoundaryType == 0) // Cas d une frontiere discrete
1778 const char* MeshName = myBoundary->GetMeshName() ;
1779 const char* MeshFile = myBoundary->GetMeshFile() ;
1780 myDriver->TexteBoundaryDi( MeshName, MeshFile);
1781 BoundaryOption = BoundaryOption*2 ;
1783 else // Cas d une frontiere analytique
1785 NumBoundaryAnalytical++ ;
1786 HOMARD::double_array* coor = myBoundary->GetCoords();
1787 if (BoundaryType == 1) // Cas d un cylindre
1789 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6]);
1790 BoundaryOption = BoundaryOption*3 ;
1792 else if (BoundaryType == 2) // Cas d une sphere
1794 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0.);
1795 BoundaryOption = BoundaryOption*3 ;
1798 // Memorisation du traitement
1799 ListeBoundaryTraitees.push_back( BoundaryName );
1802 NumBoundaryAnalytical = 0 ;
1803 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1805 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1806 MESSAGE ( "... BoundaryName = " << BoundaryName);
1807 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1808 ASSERT(!CORBA::is_nil(myBoundary));
1809 int BoundaryType = myBoundary->GetType();
1810 MESSAGE ( "... BoundaryType = " << BoundaryType );
1811 // Recuperation du nom du groupe
1812 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
1813 MESSAGE ( "... GroupName = " << GroupName);
1814 if (BoundaryType == 0) // Cas d une frontiere discrete
1816 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
1818 else // Cas d une frontiere analytique
1820 NumBoundaryAnalytical++ ;
1821 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
1824 myDriver->TexteBoundaryOption(BoundaryOption);
1826 // E.6. Ajout des informations liees a l'eventuelle interpolation des champs
1827 MESSAGE( "... TypeFieldInterp = " << TypeFieldInterp );
1828 if (TypeFieldInterp != 0)
1830 // Le fichier des champs
1831 char* FieldFile = myIteration->GetFieldFile();
1832 MESSAGE ( ". FieldFile = " << FieldFile );
1833 if (strlen(FieldFile) == 0)
1835 // GERALD -- QMESSAGE BOX
1836 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1837 ASSERT("The file for the field is not given." == 0);
1839 // Les caracteristiques d'instants
1840 int TimeStep = myIteration->GetTimeStep();
1841 MESSAGE( ". TimeStep = " << TimeStep );
1842 int Rank = myIteration->GetRank();
1843 MESSAGE( ". Rank = " << Rank );
1845 myDriver->TexteFieldInterp(TypeFieldInterp, FieldFile, MeshFile, TimeStep, Rank);
1847 if (TypeFieldInterp == 2)
1849 HOMARD::listFieldInterpHypo* meschamps = myHypo->GetListFieldInterp();
1850 int numberOfFields = meschamps->length();
1851 MESSAGE( ". numberOfFields = " << numberOfFields );
1852 for (int NumeChamp = 0; NumeChamp< numberOfFields; NumeChamp++)
1854 std::string nomChamp = std::string((*meschamps)[NumeChamp]);
1855 MESSAGE( "... nomChamp = " << nomChamp );
1856 myDriver->TexteFieldInterpName(NumeChamp, nomChamp);
1860 // E.7. Ajout des options avancees
1861 int Pyram = myCase->GetPyram();
1862 MESSAGE ( ". Pyram = " << Pyram );
1863 int NivMax = myHypo->GetNivMax();
1864 MESSAGE ( ". NivMax = " << NivMax );
1865 double DiamMin = myHypo->GetDiamMin() ;
1866 MESSAGE ( ". DiamMin = " << DiamMin );
1867 int AdapInit = myHypo->GetAdapInit();
1868 MESSAGE ( ". AdapInit = " << AdapInit );
1869 int LevelOutput = myHypo->GetLevelOutput();
1870 MESSAGE ( ". LevelOutput = " << LevelOutput );
1871 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
1873 // F. Ecriture du texte dans le fichier
1876 myDriver->CreeFichier();
1881 int codretexec = 12 ;
1884 codretexec = myDriver->ExecuteHomard();
1886 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
1887 if (codretexec == 0)
1889 SetEtatIter(NomIteration,true);
1893 // GERALD -- QMESSAGE BOX
1894 SetEtatIter(NomIteration,false);
1898 // H. Gestion des resultats
1901 // H.1. Le fichier des messages, dans tous les cas
1902 std::stringstream saux1 ;
1903 saux1 << "Mess " << NumeIter ;
1904 PublishFileUnderIteration(NomIteration, MessFile.c_str(), saux1.str().c_str());
1906 // H.2. Si tout s'est bien passe :
1907 if (codretexec == 0)
1909 // H.2.1. Le fichier de bilan
1910 std::stringstream saux2 ;
1911 saux2 << "Summary " << NumeIter ;
1912 std::string SummaryFile = DirCompute.str() + "/apad." + siterp1 + ".bilan" ;
1913 PublishFileUnderIteration(NomIteration, SummaryFile.c_str(), saux2.str().c_str());
1914 // H.2.2. Le fichier de maillage obtenu
1915 std::stringstream saux0 ;
1916 saux0 <<"Iteration " << NumeIter ;
1917 PublishFileUnderIteration(NomIteration, MeshFile, saux0.str().c_str());
1918 PublishResultInSmesh(MeshFile, 1);
1920 // H.3 Message d'erreur en cas de probleme
1923 SALOME::ExceptionStruct es;
1924 es.type = SALOME::BAD_PARAM;
1925 std::string text = "Error during the adaptation.\n" ;
1928 ifstream fichier(MessFile.c_str(), ios::in);
1930 while(getline(fichier, ligne) and (ligne != "===== HOMARD ===== STOP ====="));
1931 while (getline(fichier, ligne)) { text += ligne+ "\n";};
1934 text += "no log file ....";
1936 es.text = CORBA::string_dup(text.c_str());
1937 throw SALOME::SALOME_Exception(es);
1941 // I. Menage et retour dans le repertoire du cas
1945 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
1951 //===========================================================================
1953 //===========================================================================
1954 //===========================================================================
1956 //===========================================================================
1957 //===========================================================================
1958 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
1959 SALOMEDS::SObject_ptr theSObject,
1960 CORBA::Object_ptr theObject,
1961 const char* theName)
1963 MESSAGE("PublishInStudy pour " << theName);
1964 SALOMEDS::SObject_var aResultSO;
1965 if (CORBA::is_nil(theStudy))
1967 SALOME::ExceptionStruct es;
1968 es.type = SALOME::BAD_PARAM;
1969 es.text = "Invalid Study Context ";
1970 throw SALOME::SALOME_Exception(es);
1974 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
1975 // Rq : Iteration est publiee ailleurs
1976 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
1977 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
1978 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
1979 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
1981 addInStudy(theStudy);
1983 // Controle de la non publication d'un objet de meme nom
1984 if ((!aHypo->_is_nil()) or (!aZone->_is_nil()) or (!aBoundary->_is_nil()))
1986 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
1987 if (listSO->length() >= 1)
1989 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
1990 std::cerr <<"This name "<<theName<<" is already used "<<listSO->length()<<" time(s)" << std::endl;
1991 aResultSO = listSO[0];
1992 return aResultSO._retn();
1996 // Caracteristiques de l'etude
1997 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1998 aStudyBuilder->NewCommand();
1999 if(!aCase->_is_nil())
2000 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
2001 else if(!aHypo->_is_nil())
2002 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
2003 else if(!aZone->_is_nil())
2004 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
2005 else if(!aBoundary->_is_nil())
2006 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
2008 aStudyBuilder->CommitCommand();
2009 return aResultSO._retn();
2011 //=============================================================================
2012 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
2013 SALOMEDS::StudyBuilder_var aStudyBuilder,
2014 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
2016 MESSAGE("PublishCaseInStudy pour "<<theName);
2017 SALOMEDS::SObject_var aResultSO;
2018 SALOMEDS::GenericAttribute_var anAttr;
2020 if (CORBA::is_nil(theObject)) {
2021 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
2022 return aResultSO._retn();
2024 if (theStudy->_is_nil()) {
2025 MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
2026 return aResultSO._retn();
2029 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2030 if (theFatherHomard->_is_nil())
2032 MESSAGE("theFatherHomard->_is_nil()");
2033 return aResultSO._retn();
2036 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
2037 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
2038 _orb->object_to_string(theObject) ) ;
2039 return aResultSO._retn();
2042 //=============================================================================
2043 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
2044 SALOMEDS::StudyBuilder_var aStudyBuilder,
2045 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
2047 MESSAGE("PublishZoneStudy pour "<<theName);
2048 SALOMEDS::SObject_var aResultSO;
2049 SALOMEDS::GenericAttribute_var anAttr;
2051 if (CORBA::is_nil(theObject))
2053 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
2054 return aResultSO._retn();
2056 if (theStudy->_is_nil())
2058 MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
2059 return aResultSO._retn();
2061 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2062 if (theFatherHomard->_is_nil())
2064 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
2065 return aResultSO._retn();
2068 // Caracteristique de la zone
2069 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
2070 CORBA::Long ZoneType = myZone->GetType();
2072 // On ajoute la categorie des zones dans l etude si necessaire
2073 SALOMEDS::SObject_var aSOZone;
2074 if (!theFatherHomard->FindSubObject(100, aSOZone))
2076 MESSAGE("Ajout de la categorie des zones");
2077 aSOZone = aStudyBuilder->NewObjectToTag(theFatherHomard, 100);
2078 PublishInStudyAttr(aStudyBuilder, aSOZone, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
2080 else { MESSAGE("La categorie des zones existe deja."); }
2082 aResultSO = aStudyBuilder->NewObject(aSOZone);
2091 { icone = "boxdxy_2.png" ;
2095 { icone = "boxdxyz_2.png" ;
2103 { icone = "disk_2.png" ;
2107 { icone = "spherepoint_2.png" ;
2111 { icone = "cylinderpointvector_2.png" ;
2119 { icone = "diskwithhole_2.png" ;
2123 { icone = "pipe_2.png" ;
2127 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone, _orb->object_to_string(theObject) ) ;
2129 return aResultSO._retn();
2131 //=============================================================================
2132 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
2133 SALOMEDS::StudyBuilder_var aStudyBuilder,
2134 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
2136 MESSAGE("PublishBoundaryStudy pour "<<theName);
2137 SALOMEDS::SObject_var aResultSO;
2138 SALOMEDS::GenericAttribute_var anAttr;
2140 // Caracteristique de la Boundary
2141 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
2143 // On recupere le module pere dans l etude
2144 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2145 if (theFatherHomard->_is_nil())
2147 MESSAGE("theFatherHomard->_is_nil()");
2148 return aResultSO._retn();
2151 // On ajoute la categorie des boundarys dans l etude si necessaire
2152 SALOMEDS::SObject_var aSOBoundary;
2153 if (!theFatherHomard->FindSubObject(101, aSOBoundary))
2155 MESSAGE("Ajout de la categorie des boundarys");
2156 aSOBoundary = aStudyBuilder->NewObjectToTag(theFatherHomard, 101);
2157 PublishInStudyAttr(aStudyBuilder, aSOBoundary, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
2159 else { MESSAGE("La categorie des boundarys existe deja."); }
2161 aResultSO = aStudyBuilder->NewObject(aSOBoundary);
2162 CORBA::Long BoundaryType = myBoundary->GetType();
2163 // MESSAGE("BoundaryType : "<<BoundaryType);
2166 switch (BoundaryType)
2169 { value = "BoundaryDiHomard" ;
2170 icone = "mesh_tree_mesh.png" ;
2174 { value = "BoundaryAnHomard" ;
2175 icone = "cylinderpointvector_2.png" ;
2179 { value = "BoundaryAnHomard" ;
2180 icone = "spherepoint_2.png" ;
2184 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value, icone, _orb->object_to_string(theObject));
2185 return aResultSO._retn();
2188 //=============================================================================
2189 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
2190 SALOMEDS::StudyBuilder_var aStudyBuilder,
2191 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
2193 MESSAGE("PublishHypotheseInStudy pour "<<theName);
2194 SALOMEDS::SObject_var aResultSO;
2195 SALOMEDS::GenericAttribute_var anAttr;
2197 // On recupere le module pere dans l etude
2198 // On ajoute la categorie des hypotheses dans l etude si necessaire
2199 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2200 if (theFatherHomard->_is_nil())
2202 MESSAGE("theFatherHomard->_is_nil()");
2203 return aResultSO._retn();
2205 SALOMEDS::SObject_var aSOHypothese;
2206 if (!theFatherHomard->FindSubObject(0, aSOHypothese))
2208 MESSAGE("Ajout de la categorie des hypotheses");
2209 aSOHypothese = aStudyBuilder->NewObjectToTag(theFatherHomard, 0);
2210 PublishInStudyAttr(aStudyBuilder, aSOHypothese, "Hypothesis", "HypoList","hypotheses.png", NULL);
2212 else { MESSAGE("La categorie des hypotheses existe deja."); }
2214 // Creation du resultat dans l'etude
2215 aResultSO = aStudyBuilder->NewObject(aSOHypothese);
2216 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
2218 return aResultSO._retn();
2220 //===========================================================================
2221 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
2222 SALOMEDS::SObject_var aResultSO,
2223 const char* name, const char* value, const char* icone, const char* ior)
2225 SALOMEDS::GenericAttribute_var anAttr ;
2229 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
2230 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
2231 aNameAttrib->SetValue(name);
2234 // Ajout du commentaire
2235 if ( value != NULL )
2237 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
2238 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
2239 aCommentAttrib->SetValue(value);
2243 if ( icone != NULL )
2245 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO,"AttributePixMap");
2246 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
2247 aPixmap->SetPixMap(icone);
2253 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
2254 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2255 anIOR->SetValue(ior);
2259 //=====================================================================================
2260 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
2262 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
2264 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
2265 ASSERT(!CORBA::is_nil(myCase));
2266 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
2267 ASSERT(!CORBA::is_nil(aCaseSO));
2269 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2270 ASSERT(!CORBA::is_nil(myBoundary));
2271 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
2272 ASSERT(!CORBA::is_nil(aBoundarySO));
2274 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2276 aStudyBuilder->NewCommand();
2278 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
2279 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
2281 aStudyBuilder->CommitCommand();
2284 //=============================================================================
2285 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long IconeType)
2287 MESSAGE( "PublishResultInSmesh " << NomFich);
2288 if (CORBA::is_nil(myCurrentStudy))
2290 SALOME::ExceptionStruct es;
2291 es.type = SALOME::BAD_PARAM;
2292 es.text = "Invalid Study Context ";
2293 throw SALOME::SALOME_Exception(es);
2297 // Le module SMESH est-il actif ?
2298 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
2300 if (!CORBA::is_nil(aSmeshSO))
2302 // On verifie que le fichier n est pas deja publie
2303 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
2304 for (; aIter->More(); aIter->Next())
2306 SALOMEDS::SObject_var aSO = aIter->Value();
2307 SALOMEDS::GenericAttribute_var aGAttr;
2308 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
2310 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2311 CORBA::String_var value=anAttr->Value();
2312 if (strcmp((const char*)value,NomFich) == 0)
2314 // GERALD -- QMESSAGE BOX
2315 std::cerr << "fichier : "<< NomFich << " deja publie "<< std::endl;
2323 // On enregistre le fichier
2324 MESSAGE( "Enregistrement du fichier");
2325 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
2326 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
2327 ASSERT(!CORBA::is_nil(aSmeshEngine));
2328 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
2329 SMESH::DriverMED_ReadStatus theStatus;
2330 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
2332 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
2333 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
2334 for (int i = 0; i < mesMaillages->length(); i++)
2336 MESSAGE( ". Mise a jour des attributs du maillage");
2337 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
2338 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
2339 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2340 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
2341 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2342 anAttr->SetValue(NomFich);
2343 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
2344 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
2345 // IconeType = 0 : fichier issu d'une importation
2346 // IconeType = 1 : fichier issu d'une execution HOMARD
2348 if ( IconeType == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
2349 else { icone = "mesh_tree_mesh.png" ; }
2350 anAttr2->SetPixMap( icone );
2354 //=============================================================================
2355 void HOMARD_Gen_i::DeleteResultInSmesh(const char* NomFich, const char* MeshName)
2357 MESSAGE (" DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
2358 if (CORBA::is_nil(myCurrentStudy))
2360 SALOME::ExceptionStruct es;
2361 es.type = SALOME::BAD_PARAM;
2362 es.text = "Invalid Study Context ";
2363 throw SALOME::SALOME_Exception(es);
2367 // Le module SMESH est-il actif ?
2368 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
2370 if (CORBA::is_nil(aSmeshSO))
2374 // On verifie que le fichier est deja publie
2375 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
2376 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
2377 for (; aIter->More(); aIter->Next())
2379 SALOMEDS::SObject_var aSO = aIter->Value();
2380 SALOMEDS::GenericAttribute_var aGAttr;
2381 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
2383 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2384 CORBA::String_var value=anAttr->Value();
2385 if (strcmp((const char*)value,NomFich) == 0)
2387 if (aSO->FindAttribute(aGAttr,"AttributeName"))
2389 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
2390 CORBA::String_var value2=anAttr2->Value();
2391 if (strcmp((const char*)value2,MeshName) == 0)
2393 myBuilder->RemoveObjectWithChildren( aSO ) ;
2401 //=============================================================================
2402 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
2404 if (CORBA::is_nil(myCurrentStudy))
2406 SALOME::ExceptionStruct es;
2407 es.type = SALOME::BAD_PARAM;
2408 es.text = "Invalid Study Context ";
2409 throw SALOME::SALOME_Exception(es);
2413 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
2414 if (CORBA::is_nil(myIteration))
2416 SALOME::ExceptionStruct es;
2417 es.type = SALOME::BAD_PARAM;
2418 es.text = "Invalid Iteration ";
2419 throw SALOME::SALOME_Exception(es);
2422 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
2423 if (CORBA::is_nil(myIteration))
2425 SALOME::ExceptionStruct es;
2426 es.type = SALOME::BAD_PARAM;
2427 es.text = "Invalid Iteration Study Object";
2428 throw SALOME::SALOME_Exception(es);
2432 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2434 aStudyBuilder->NewCommand();
2436 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
2437 // Pour les fichiers med, on affiche une icone de maillage
2438 // Pour les fichiers qui sont texte, on affiche une icone de fichier texte 'texte'
2439 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
2441 const char* ior = " " ;
2442 if ( Commentaire[0] == 'I' )
2443 { icone = "med.png" ; }
2445 { icone = "texte_2.png" ; }
2446 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone, ior ) ;
2448 aStudyBuilder->CommitCommand();
2450 //=============================================================================
2451 //=============================================================================
2453 //=============================================================================
2454 //=============================================================================
2455 // Next functions are inherited from SALOMEDS::Driver interface
2456 //=============================================================================
2457 //=============================================================================
2458 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
2460 CORBA::Boolean isMultiFile)
2462 MESSAGE (" Save for theURL = "<< theURL);
2463 SALOMEDS::TMPFile_var aStreamFile;
2465 // get temporary directory name
2466 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2468 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2469 StudyContext& context = myContextMap[ aStudy->StudyId() ];
2471 // HOMARD data file name
2472 std::string aFileName = "";
2474 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2475 aFileName += "_HOMARD.dat";
2477 // initialize sequence of file names
2478 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
2479 aFileSeq->length(1);
2480 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
2482 // get full path to the data file
2483 aFileName = tmpDir + aFileName;
2487 std::ofstream f(aFileName.c_str());
2489 // clear temporary id map
2490 context._idmap.clear();
2495 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
2496 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
2497 HOMARD::HOMARD_Cas_var aCas = it_case->second;
2498 PortableServer::ServantBase_var aServant = GetServant(aCas);
2499 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2501 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
2502 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
2506 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2507 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
2508 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
2509 PortableServer::ServantBase_var aServant = GetServant(aZone);
2510 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2512 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
2513 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2516 // -> save hypotheses
2517 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2518 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
2519 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
2520 PortableServer::ServantBase_var aServant = GetServant(aHypo);
2521 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2523 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
2524 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2527 // -> save iterations
2528 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2529 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
2530 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
2531 PortableServer::ServantBase_var aServant = GetServant(aIter);
2532 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2534 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
2535 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2538 // -> save boundaries
2539 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2540 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
2541 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
2542 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2543 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2544 if (aBoundaryServant) {
2545 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
2546 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2550 MESSAGE ("close file");
2553 // put temporary files to the stream
2554 MESSAGE ("put temporary files to the stream");
2555 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
2557 // remove temporary files
2558 MESSAGE ("remove temporary files");
2559 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2561 // return data stream
2562 MESSAGE ("return data stream");
2563 return aStreamFile._retn();
2566 //===========================================================================
2567 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
2569 CORBA::Boolean isMultiFile)
2571 // No specific ASCII persistence
2572 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
2573 return aStreamFile._retn();
2576 //===========================================================================
2577 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
2578 const SALOMEDS::TMPFile& theStream,
2580 CORBA::Boolean isMultiFile)
2582 MESSAGE (" Load pour theURL = "<< theURL);
2583 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2585 // set current study
2586 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
2587 SetCurrentStudy(aStudy);
2589 // get temporary directory name
2590 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2592 // Convert the stream into sequence of files to process
2593 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
2596 // HOMARD data file name
2597 std::string aFileName = "";
2599 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2600 aFileName = tmpDir + aFileName + "_HOMARD.dat";
2602 StudyContext& context = myContextMap[ aStudy->StudyId() ];
2606 std::ifstream f(aFileName.c_str());
2609 context._mesCas.clear();
2610 context._mesHypotheses.clear();
2611 context._mesIterations.clear();
2612 context._mesZones.clear();
2613 context._mesBoundarys.clear();
2614 context._idmap.clear();
2620 std::getline(f, line);
2621 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
2622 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
2623 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
2624 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
2625 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
2626 if (line.substr(0, caseSignature.size()) == caseSignature) {
2628 MESSAGE (" Recreation du cas" );
2629 HOMARD::HOMARD_Cas_var aCase = newCase();
2630 PortableServer::ServantBase_var aServant = GetServant(aCase);
2631 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2632 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
2633 context._mesCas[aCase->GetName()] = aCase;
2634 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
2637 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
2638 MESSAGE (" Recreation de la zone" );
2640 HOMARD::HOMARD_Zone_var aZone = newZone();
2641 PortableServer::ServantBase_var aServant = GetServant(aZone);
2642 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2643 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
2644 context._mesZones[aZone->GetName()] = aZone;
2645 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2648 else if (line.substr(0, iterSignature.size()) == iterSignature) {
2649 // re-create iteration
2650 MESSAGE (" Recreation de l iteration" );
2651 HOMARD::HOMARD_Iteration_var aIter = newIteration();
2652 PortableServer::ServantBase_var aServant = GetServant(aIter);
2653 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2654 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
2655 context._mesIterations[aIter->GetName()] = aIter;
2656 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2659 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
2660 // re-create hypothesis
2661 MESSAGE (" Recreation de l hypothese" );
2662 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
2663 PortableServer::ServantBase_var aServant = GetServant(aHypo);
2664 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2665 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
2666 context._mesHypotheses[aHypo->GetName()] = aHypo;
2667 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2670 else if (line.substr(0, bounSignature.size()) == bounSignature) {
2671 // re-create boundary
2672 MESSAGE (" Recreation de la frontiere" );
2673 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
2674 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2675 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2676 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
2677 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
2678 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2687 // Remove temporary files created from the stream
2689 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2694 //===========================================================================
2695 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
2696 const SALOMEDS::TMPFile& theStream,
2698 CORBA::Boolean isMultiFile)
2700 // No specific ASCII persistence
2701 return Load(theComponent, theStream, theURL, isMultiFile);
2704 //===========================================================================
2705 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
2707 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
2708 // clearing study context should be done here:
2709 // - destroy all servants and related CORBA objects
2711 // - remove context from myContextMap
2712 myContextMap.erase(theComponent->GetStudy()->StudyId());
2713 // - nullify myCurrentStudy
2714 myCurrentStudy = SALOMEDS::Study::_nil();
2718 //===========================================================================
2719 char* HOMARD_Gen_i::ComponentDataType()
2721 return CORBA::string_dup("HOMARD");
2724 //===========================================================================
2725 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
2726 const char* IORString,
2727 CORBA::Boolean isMultiFile,
2728 CORBA::Boolean isASCII)
2730 CORBA::String_var aString("");
2731 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
2732 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2733 CORBA::Object_var anObj = _orb->string_to_object(IORString);
2734 if (!CORBA::is_nil(anObj)) {
2735 PortableServer::ServantBase_var aServant = GetServant(anObj);
2736 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
2738 std::map<int, PortableServer::ServantBase*>::const_iterator it;
2739 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
2740 if (it->second == aStorable) {
2741 std::stringstream os;
2743 aString = CORBA::string_dup(os.str().c_str());
2749 return aString._retn();
2752 //===========================================================================
2753 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
2754 const char* aLocalPersistentID,
2755 CORBA::Boolean isMultiFile,
2756 CORBA::Boolean isASCII)
2758 CORBA::String_var aString("");
2759 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
2760 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2761 int id = atoi(aLocalPersistentID);
2762 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
2763 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
2764 if (!CORBA::is_nil(object)) {
2765 aString = _orb->object_to_string(object);
2769 return aString._retn();
2772 //===========================================================================
2773 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
2775 if(CORBA::is_nil(myCurrentStudy))
2778 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
2779 if(!aCas->_is_nil())
2782 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
2783 if(!aHypo->_is_nil())
2786 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
2787 if(!aZone->_is_nil())
2790 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
2791 if(!aBoundary->_is_nil())
2794 /* Iteration is not published directly
2795 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
2796 if(!aIter->_is_nil())
2802 //===========================================================================
2803 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
2805 // No Copy/Paste support
2809 //===========================================================================
2810 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
2811 CORBA::Long& theObjectID)
2813 // No Copy/Paste support
2814 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
2815 return aStreamFile._retn();
2818 //===========================================================================
2819 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
2820 CORBA::Long theObjectID)
2822 // No Copy/Paste support
2826 //===========================================================================
2827 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
2828 CORBA::Long theObjectID,
2829 SALOMEDS::SObject_ptr theSObject)
2831 // No Copy/Paste support
2832 SALOMEDS::SObject_var aResultSO;
2833 return aResultSO._retn();
2836 //===========================================================================
2837 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
2839 PortableServer::Servant aServant = 0;
2840 if (!CORBA::is_nil(theObject)) {
2842 aServant = _poa->reference_to_servant(theObject);
2850 //==========================================================================
2851 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
2852 CORBA::Boolean isPublished,
2853 CORBA::Boolean isMultiFile,
2854 CORBA::Boolean& isValidScript)
2856 MESSAGE ("Entree dans DumpPython");
2858 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
2859 if(CORBA::is_nil(aStudy))
2860 return new Engines::TMPFile(0);
2862 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
2863 if(CORBA::is_nil(aSO))
2864 return new Engines::TMPFile(0);
2866 std::string aScript = "\"\"\"\n";
2867 aScript += "Python script for HOMARD\n";
2868 aScript += "Copyright EDF-R&D 2013\n";
2869 aScript += "\"\"\"\n";
2870 aScript += "__revision__ = \"V1.2\"\n";
2871 aScript += "import HOMARD\n";
2873 aScript += "import salome\n";
2874 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
2876 aScript += "def RebuildData(theStudy):\n";
2877 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
2880 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
2881 MESSAGE (". Au depart \n"<<aScript);
2884 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
2886 MESSAGE (". Ecritures des frontieres");
2887 aScript += "#\n# Creation of the boundaries";
2888 aScript += "\n# ==========================";
2890 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2891 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
2892 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
2894 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
2895 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
2896 std::string dumpBoundary = dumpCorbaBoundary.in();
2897 MESSAGE (dumpBoundary<<"\n");
2898 aScript += dumpBoundary;
2902 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
2904 MESSAGE (". Ecritures des zones");
2905 aScript += "#\n# Creation of the zones";
2906 aScript += "\n# =====================";
2908 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2909 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
2910 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
2912 HOMARD::HOMARD_Zone_var maZone = (*it_zone).second;
2913 CORBA::String_var dumpCorbaZone = maZone->GetDumpPython();
2914 std::string dumpZone = dumpCorbaZone.in();
2915 MESSAGE (dumpZone<<"\n");
2916 aScript += dumpZone;
2920 if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
2922 MESSAGE (". Ecritures des hypotheses");
2923 aScript += "#\n# Creation of the hypotheses";
2924 aScript += "\n# ==========================";
2926 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2927 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
2928 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
2930 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
2931 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
2932 std::string dumpHypo = dumpCorbaHypo.in();
2933 MESSAGE (dumpHypo<<"\n");
2934 aScript += dumpHypo;
2938 if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
2940 MESSAGE (". Ecritures des cas");
2941 aScript += "#\n# Creation of the cases";
2942 aScript += "\n# =====================";
2944 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
2945 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
2946 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
2948 std::string nomCas = (*it_cas).first;
2949 std::string dumpCas = std::string("\n# Creation of the case ") ;
2950 dumpCas += nomCas + std::string("\n");
2951 dumpCas += std::string("\t") + nomCas;
2952 dumpCas += std::string(" = homard.CreateCase('") + nomCas + std::string("', '");
2954 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
2955 CORBA::String_var cIter0= myCase->GetIter0Name();
2956 std::string iter0 = cIter0.in();
2958 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
2959 CORBA::String_var cMesh0= myIteration->GetMeshFile();
2960 std::string mesh0 = cMesh0.in();
2961 CORBA::String_var cMeshName0= myIteration->GetMeshName();
2962 std::string meshName0 = cMeshName0.in();
2963 dumpCas += meshName0 + std::string("', '")+ mesh0 + std::string("')\n");
2964 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
2965 std::string dumpCas2= dumpCorbaCase.in();
2967 MESSAGE (dumpCas<<dumpCas2<<"\n");
2968 aScript += dumpCas + dumpCas2;
2972 if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
2974 MESSAGE (". Ecritures des iterations");
2975 aScript += "#\n# Creation of the iterations" ;
2976 aScript += "\n# ==========================";
2978 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2979 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
2980 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
2982 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
2983 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
2984 std::string dumpIter = dumpCorbaIter.in();
2985 MESSAGE (dumpIter<<"\n");
2986 aScript += dumpIter;
2989 MESSAGE (". Ecritures finales");
2991 aScript += "\n\tpass";
2994 if( !isMultiFile ) // remove unnecessary tabulation
2995 aScript = RemoveTabulation( aScript );
2997 // MESSAGE ("A ecrire \n"<<aScript);
2998 const size_t aLen = strlen(aScript.c_str());
2999 char* aBuffer = new char[aLen+1];
3000 strcpy(aBuffer, aScript.c_str());
3002 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
3003 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
3005 MESSAGE ("Sortie de DumpPython");
3006 return aStreamFile._retn();
3010 //=============================================================================
3011 //=============================================================================
3013 //=============================================================================
3014 //=============================================================================
3015 void HOMARD_Gen_i::IsValidStudy( )
3017 // MESSAGE( "IsValidStudy" );
3018 if (CORBA::is_nil(myCurrentStudy))
3020 SALOME::ExceptionStruct es;
3021 es.type = SALOME::BAD_PARAM;
3022 es.text = "Invalid Study Context";
3023 throw SALOME::SALOME_Exception(es);
3028 //=============================================================================
3029 CORBA::Boolean HOMARD_Gen_i::VerifieDir(const char* nomDir)
3031 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
3032 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
3033 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
3035 if (std::string(nomDir) == std::string(it->second->GetDirName())) return false;
3039 /*//=============================================================================
3040 void SALOMEException( std::string message )
3042 SALOME::ExceptionStruct es;
3043 es.type = SALOME::BAD_PARAM;
3045 throw SALOME::SALOME_Exception(es);
3048 //=============================================================================
3049 char* HOMARD_Gen_i::getVersion()
3051 #if HOMARD_DEVELOPMENT
3052 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
3054 return CORBA::string_dup(HOMARD_VERSION_STR);
3058 //=============================================================================
3061 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
3062 PortableServer::POA_ptr poa,
3063 PortableServer::ObjectId* contId,
3064 const char* instanceName,
3065 const char* interfaceName)
3067 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
3068 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
3069 return myHOMARD_Gen->getId();