1 // Copyright (C) 2011-2016 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, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "HOMARD_Gen_i.hxx"
21 #include "HOMARD_Cas_i.hxx"
22 #include "HOMARD_Hypothesis_i.hxx"
23 #include "HOMARD_Iteration_i.hxx"
24 #include "HOMARD_Boundary_i.hxx"
25 #include "HOMARD_Zone_i.hxx"
26 #include "HOMARD_YACS_i.hxx"
27 #include "HomardDriver.hxx"
28 #include "HOMARD_DriverTools.hxx"
29 #include "HomardMedCommun.h"
30 #include "YACSDriver.hxx"
33 #include "FrontTrack.hxx"
35 #include "HOMARD_version.h"
37 #include "utilities.h"
38 #include "Basics_Utils.hxx"
39 #include "Utils_SINGLETON.hxx"
40 #include "Utils_CorbaException.hxx"
41 #include "SALOMEDS_Tool.hxx"
42 #include "SALOME_LifeCycleCORBA.hxx"
43 #include "SALOMEconfig.h"
44 #include <SMESH_Gen_i.hxx>
45 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
46 #include CORBA_CLIENT_HEADER(SMESH_Gen)
69 //=============================================================================
71 //=============================================================================
72 std::string RemoveTabulation( std::string theScript )
74 std::string::size_type aPos = 0;
75 while( aPos < theScript.length() )
77 aPos = theScript.find( "\n\t", aPos );
78 if( aPos == std::string::npos )
80 theScript.replace( aPos, 2, "\n" );
85 //=============================================================================
87 * standard constructor
89 //=============================================================================
90 HOMARD_Gen_i::HOMARD_Gen_i( CORBA::ORB_ptr orb,
91 PortableServer::POA_ptr poa,
92 PortableServer::ObjectId * contId,
93 const char *instanceName,
94 const char *interfaceName) :
95 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
97 MESSAGE("constructor");
99 _id = _poa->activate_object(_thisObj);
101 myHomard = new ::HOMARD_Gen();
102 _NS = SINGLETON_<SALOME_NamingService>::Instance();
103 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
106 myStudy = SALOMEDS::Study::_duplicate( SMESH_Gen_i::getStudyServant() );
116 //=================================
118 * standard destructor
120 //================================
121 HOMARD_Gen_i::~HOMARD_Gen_i()
124 //=============================================================================
125 //=============================================================================
126 // Utilitaires pour l'étude
127 //=============================================================================
128 //=============================================================================
129 void HOMARD_Gen_i::UpdateStudy()
131 ASSERT(!CORBA::is_nil(myStudy));
132 SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
134 // Create SComponent labelled 'homard' if it doesn't already exit
135 SALOMEDS::SComponent_var homardFather = myStudy->FindComponent(ComponentDataType());
136 if (CORBA::is_nil(homardFather))
138 myBuilder->NewCommand();
139 MESSAGE("Add Component HOMARD");
141 bool aLocked = myStudy->GetProperties()->IsLocked();
142 if (aLocked) myStudy->GetProperties()->SetLocked(false);
144 homardFather = myBuilder->NewComponent(ComponentDataType());
145 SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
146 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
147 CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
148 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
149 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
150 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
151 if (!Comp->_is_nil())
153 aName->SetValue(ComponentDataType());
156 anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributePixMap");
157 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
158 aPixmap->SetPixMap("HOMARD_2.png");
159 myBuilder->DefineComponentInstance(homardFather, HOMARD_Gen::_this());
161 if (aLocked) myStudy->GetProperties()->SetLocked(true);
162 myBuilder->CommitCommand();
166 //=============================================================================
167 //=============================================================================
168 // Utilitaires pour l'iteration
169 //=============================================================================
170 //=============================================================================
171 void HOMARD_Gen_i::SetEtatIter(const char* nomIter, const CORBA::Long Etat)
172 //=====================================================================================
174 MESSAGE( "SetEtatIter : affectation de l'etat " << Etat << " a l'iteration " << nomIter );
175 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
176 if (CORBA::is_nil(myIteration))
178 SALOME::ExceptionStruct es;
179 es.type = SALOME::BAD_PARAM;
180 es.text = "Invalid iteration";
181 throw SALOME::SALOME_Exception(es);
185 myIteration->SetState(Etat);
187 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
188 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
192 icone = "iter0.png" ;
193 else if ( Etat == 2 )
194 icone = "iter_calculee.png" ;
196 icone = "iter_non_calculee.png" ;
197 PublishInStudyAttr(aStudyBuilder, aIterSO, NULL , NULL, icone.c_str(), NULL) ;
199 aStudyBuilder->CommitCommand();
202 //=============================================================================
203 //=============================================================================
205 //=============================================================================
206 //=============================================================================
207 // Destruction des structures identifiees par leurs noms
208 //=============================================================================
209 //=============================================================================
210 CORBA::Long HOMARD_Gen_i::DeleteBoundary(const char* BoundaryName)
212 MESSAGE ( "DeleteBoundary : BoundaryName = " << BoundaryName );
213 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
214 if (CORBA::is_nil(myBoundary))
216 SALOME::ExceptionStruct es;
217 es.type = SALOME::BAD_PARAM;
218 es.text = "Invalid boundary";
219 throw SALOME::SALOME_Exception(es);
223 // On verifie que la frontiere n'est plus utilisee
224 HOMARD::listeCases* maListe = GetAllCasesName();
225 int numberOfCases = maListe->length();
226 MESSAGE ( ".. Nombre de cas = " << numberOfCases );
227 std::string CaseName ;
228 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType ;
230 HOMARD::HOMARD_Cas_var myCase ;
231 for (int NumeCas = 0; NumeCas< numberOfCases; NumeCas++)
233 CaseName = std::string((*maListe)[NumeCas]);
234 MESSAGE ( "... Examen du cas = " << CaseName.c_str() );
235 myCase = myStudyContext._mesCas[CaseName];
236 ASSERT(!CORBA::is_nil(myCase));
237 ListBoundaryGroupType = myCase->GetBoundaryGroup();
238 numberOfitems = ListBoundaryGroupType->length();
239 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
240 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
242 if ( std::string((*ListBoundaryGroupType)[NumBoundary]) == BoundaryName )
244 SALOME::ExceptionStruct es;
245 es.type = SALOME::BAD_PARAM;
246 es.text = "This boundary is used in a case and cannot be deleted.";
247 throw SALOME::SALOME_Exception(es);
253 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
254 myStudyContext._mesBoundarys.erase(BoundaryName);
255 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(BoundaryName, ComponentDataType());
256 SALOMEDS::SObject_var aSO =listSO[0];
257 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
258 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
262 //=============================================================================
263 CORBA::Long HOMARD_Gen_i::DeleteCase(const char* nomCas, CORBA::Long Option)
265 // Pour detruire un cas
266 MESSAGE ( "DeleteCase : nomCas = " << nomCas << ", avec option = " << Option );
267 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
268 if (CORBA::is_nil(myCase))
270 SALOME::ExceptionStruct es;
271 es.type = SALOME::BAD_PARAM;
272 es.text = "Invalid case context";
273 throw SALOME::SALOME_Exception(es);
276 // On commence par detruire toutes les iterations en partant de l'initiale et y compris elle
277 CORBA::String_var nomIter = myCase->GetIter0Name();
278 CORBA::Long Option1 = 0 ;
279 if ( DeleteIterationOption(nomIter, Option1, Option) != 0 )
284 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
285 myStudyContext._mesCas.erase(nomCas);
286 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomCas, ComponentDataType());
287 SALOMEDS::SObject_var aSO =listSO[0];
288 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
289 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
293 //=============================================================================
294 CORBA::Long HOMARD_Gen_i::DeleteHypo(const char* nomHypo)
296 MESSAGE ( "DeleteHypo : nomHypo = " << nomHypo );
297 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
298 if (CORBA::is_nil(myHypo))
300 SALOME::ExceptionStruct es;
301 es.type = SALOME::BAD_PARAM;
302 es.text = "Invalid hypothesis";
303 throw SALOME::SALOME_Exception(es);
307 // On verifie que l'hypothese n'est plus utilisee
308 HOMARD::listeIters* maListeIter = myHypo->GetIterations();
309 int numberOfIter = maListeIter->length();
310 if ( numberOfIter > 0 )
312 SALOME::ExceptionStruct es;
313 es.type = SALOME::BAD_PARAM;
314 es.text = "This hypothesis is used in an iteration and cannot be deleted.";
315 throw SALOME::SALOME_Exception(es);
319 // suppression du lien avec les zones eventuelles
320 HOMARD::listeZonesHypo* maListe = myHypo->GetZones();
321 int numberOfZones = maListe->length();
322 MESSAGE ( ".. Nombre de zones = " << numberOfZones );
323 for (int NumeZone = 0; NumeZone< numberOfZones; NumeZone++)
325 std::string ZoneName = std::string((*maListe)[NumeZone]);
326 MESSAGE ( ".. suppression du lien avec la zone = " << ZoneName.c_str() );
327 DissociateHypoZone(nomHypo, ZoneName.c_str()) ;
331 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
332 myStudyContext._mesHypotheses.erase(nomHypo);
333 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomHypo, ComponentDataType());
334 SALOMEDS::SObject_var aSO =listSO[0];
335 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
336 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
340 //=============================================================================
341 CORBA::Long HOMARD_Gen_i::DeleteIteration(const char* nomIter, CORBA::Long Option)
343 // Option = 0 : On ne supprime pas le fichier du maillage associe
344 // Option = 1 : On supprime le fichier du maillage associe
345 // Pour detruire une iteration courante
346 MESSAGE ( "DeleteIteration : nomIter = " << nomIter << ", avec option = " << Option );
347 CORBA::Long Option1 = 1 ;
348 return DeleteIterationOption(nomIter, Option1, Option);
350 //=============================================================================
351 CORBA::Long HOMARD_Gen_i::DeleteIterationOption(const char* nomIter, CORBA::Long Option1, CORBA::Long Option2)
353 // Option1 = 0 : On autorise la destruction de l'iteration 0
354 // Option1 = 1 : On interdit la destruction de l'iteration 0
356 // Option2 = 0 : On ne supprime pas le fichier du maillage associe
357 // Option2 = 1 : On supprime le fichier du maillage associe
358 MESSAGE ( "DeleteIterationOption : nomIter = " << nomIter << ", avec options = " << Option1<< ", " << Option2 );
359 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
360 if (CORBA::is_nil(myIteration))
362 SALOME::ExceptionStruct es;
363 es.type = SALOME::BAD_PARAM;
364 es.text = "Invalid iteration";
365 throw SALOME::SALOME_Exception(es);
369 int numero = myIteration->GetNumber();
370 MESSAGE ( "DeleteIterationOption : numero = " << numero );
371 if ( numero == 0 && Option1 == 1 )
373 SALOME::ExceptionStruct es;
374 es.type = SALOME::BAD_PARAM;
375 es.text = "This iteration cannot be deleted.";
376 throw SALOME::SALOME_Exception(es);
380 // On detruit recursivement toutes les filles
381 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
382 int numberOfIter = maListe->length();
383 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
385 std::string nomIterFille = std::string((*maListe)[NumeIter]);
386 MESSAGE ( ".. appel recursif de DeleteIterationOption pour nomIter = " << nomIterFille.c_str() );
387 DeleteIterationOption(nomIterFille.c_str(), Option1, Option2);
390 // On arrive ici pour une iteration sans fille
391 MESSAGE ( "Destruction effective de " << nomIter );
392 // On commence par invalider l'iteration pour faire le menage des dependances
393 // et eventuellement du maillage associe
395 if ( numero == 0 ) { option = 0 ; }
396 else { option = Option2 ; }
397 InvalideIterOption(nomIter, option) ;
399 // Retrait dans la descendance de l'iteration parent
402 std::string nomIterationParent = myIteration->GetIterParentName();
403 MESSAGE ( "Retrait dans la descendance de nomIterationParent " << nomIterationParent );
404 HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterationParent];
405 if (CORBA::is_nil(myIterationParent))
407 SALOME::ExceptionStruct es;
408 es.type = SALOME::BAD_PARAM;
409 es.text = "Invalid iteration";
410 throw SALOME::SALOME_Exception(es);
413 myIterationParent->UnLinkNextIteration(nomIter);
416 // suppression du lien avec l'hypothese
419 std::string nomHypo = myIteration->GetHypoName();
420 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
421 ASSERT(!CORBA::is_nil(myHypo));
422 myHypo->UnLinkIteration(nomIter);
425 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
426 myStudyContext._mesIterations.erase(nomIter);
427 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomIter, ComponentDataType());
428 SALOMEDS::SObject_var aSO =listSO[0];
429 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
430 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
431 // on peut aussi faire RemoveObject
432 // MESSAGE ( "Au final" );
433 // HOMARD::listeIterations* Liste = GetAllIterationsName() ;
434 // numberOfIter = Liste->length();
435 // for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
437 // std::string nomIterFille = std::string((*Liste)[NumeIter]);
438 // MESSAGE ( ".. nomIter = " << nomIterFille.c_str() );
443 //=============================================================================
444 CORBA::Long HOMARD_Gen_i::DeleteYACS(const char* nomYACS, CORBA::Long Option)
446 // Option = 0 : On ne supprime pas le fichier du schema associe
447 // Option = 1 : On supprime le fichier du schema associe
448 MESSAGE ( "DeleteYACS : nomYACS = " << nomYACS << ", avec option = " << Option );
449 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
450 if (CORBA::is_nil(myYACS))
452 SALOME::ExceptionStruct es;
453 es.type = SALOME::BAD_PARAM;
454 es.text = "Invalid schema YACS";
455 throw SALOME::SALOME_Exception(es);
458 // Suppression eventuelle du fichier XML
461 std::string nomFichier = myYACS->GetXMLFile();
462 std::string commande = "rm -rf " + nomFichier ;
463 MESSAGE ( "commande = " << commande );
464 if ((system(commande.c_str())) != 0)
466 SALOME::ExceptionStruct es;
467 es.type = SALOME::BAD_PARAM;
468 es.text = "The xml file for the schema YACS cannot be removed." ;
469 throw SALOME::SALOME_Exception(es);
473 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
474 myStudyContext._mesYACSs.erase(nomYACS);
475 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomYACS, ComponentDataType());
476 SALOMEDS::SObject_var aSO =listSO[0];
477 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
478 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
482 //=============================================================================
483 CORBA::Long HOMARD_Gen_i::DeleteZone(const char* nomZone)
485 MESSAGE ( "DeleteZone : nomZone = " << nomZone );
486 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[nomZone];
487 if (CORBA::is_nil(myZone))
489 SALOME::ExceptionStruct es;
490 es.type = SALOME::BAD_PARAM;
491 es.text = "Invalid zone";
492 throw SALOME::SALOME_Exception(es);
496 // On verifie que la zone n'est plus utilisee
497 HOMARD::listeHypo* maListe = myZone->GetHypo();
498 int numberOfHypo = maListe->length();
499 MESSAGE ( ".. Nombre d'hypotheses = " << numberOfHypo );
500 if ( numberOfHypo > 0 )
502 SALOME::ExceptionStruct es;
503 es.type = SALOME::BAD_PARAM;
504 es.text = "This zone is used in an hypothesis and cannot be deleted.";
505 throw SALOME::SALOME_Exception(es);
509 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
510 myStudyContext._mesZones.erase(nomZone);
511 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomZone, ComponentDataType());
512 SALOMEDS::SObject_var aSO =listSO[0];
513 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
514 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
518 //=============================================================================
519 //=============================================================================
521 //=============================================================================
522 //=============================================================================
523 // Invalidation des structures identifiees par leurs noms
524 //=============================================================================
525 //=============================================================================
526 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
528 MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName );
529 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
530 if (CORBA::is_nil(myBoundary))
532 SALOME::ExceptionStruct es;
533 es.type = SALOME::BAD_PARAM;
534 es.text = "Invalid boundary";
535 throw SALOME::SALOME_Exception(es);
540 SALOME::ExceptionStruct es;
541 es.type = SALOME::BAD_PARAM;
542 es.text = "No change is allowed in a boundary. Ask for evolution.";
543 throw SALOME::SALOME_Exception(es);
547 //=============================================================================
548 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
550 MESSAGE( "InvalideHypo : nomHypo = " << nomHypo );
551 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
552 if (CORBA::is_nil(myHypo))
554 SALOME::ExceptionStruct es;
555 es.type = SALOME::BAD_PARAM;
556 es.text = "Invalid hypothesis";
557 throw SALOME::SALOME_Exception(es);
561 HOMARD::listeIters* maListe = myHypo->GetIterations();
562 int numberOfIter = maListe->length();
563 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
565 std::string nomIter = std::string((*maListe)[NumeIter]);
566 MESSAGE( ".. nomIter = " << nomIter );
567 InvalideIter(nomIter.c_str());
570 //=============================================================================
571 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
573 MESSAGE("InvalideIter : nomIter = " << nomIter);
574 // Pour invalider totalement une iteration courante
575 CORBA::Long Option = 1 ;
576 return InvalideIterOption(nomIter, Option);
578 //=============================================================================
579 void HOMARD_Gen_i::InvalideIterOption(const char* nomIter, CORBA::Long Option)
581 // Option = 0 : On ne supprime pas le fichier du maillage associe
582 // Option = 1 : On supprime le fichier du maillage associe
583 MESSAGE ( "InvalideIterOption : nomIter = " << nomIter << ", avec option = " << Option );
584 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
585 if (CORBA::is_nil(myIteration))
587 SALOME::ExceptionStruct es;
588 es.type = SALOME::BAD_PARAM;
589 es.text = "Invalid iteration";
590 throw SALOME::SALOME_Exception(es);
594 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
595 int numberOfIter = maListe->length();
596 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
598 std::string nomIterFille = std::string((*maListe)[NumeIter]);
599 MESSAGE ( ".. appel recursif de InvalideIter pour nomIter = " << nomIterFille.c_str() );
600 InvalideIter(nomIterFille.c_str());
603 // On arrive ici pour une iteration sans fille
604 MESSAGE ( "Invalidation effective de " << nomIter );
605 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
606 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aIterSO);
607 for (; aIter->More(); aIter->Next())
609 SALOMEDS::SObject_var so = aIter->Value();
610 SALOMEDS::GenericAttribute_var anAttr;
611 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
612 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
613 std::string value (aCommentAttr->Value());
614 if(value == std::string("IterationHomard")) continue;
615 if(value == std::string("HypoHomard")) continue;
616 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
617 aStudyBuilder->RemoveObject(so);
620 int etat = myIteration->GetState();
623 SetEtatIter(nomIter,1);
624 const char * nomCas = myIteration->GetCaseName();
625 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
626 if (CORBA::is_nil(myCase))
628 SALOME::ExceptionStruct es;
629 es.type = SALOME::BAD_PARAM;
630 es.text = "Invalid case context";
631 throw SALOME::SALOME_Exception(es);
634 std::string nomDir = myIteration->GetDirName();
635 std::string nomFichier = myIteration->GetMeshFile();
636 std::string commande = "rm -rf " + std::string(nomDir);
637 if ( Option == 1 ) { commande = commande + ";rm -rf " + std::string(nomFichier) ; }
638 MESSAGE ( "commande = " << commande );
639 if ((system(commande.c_str())) != 0)
641 SALOME::ExceptionStruct es;
642 es.type = SALOME::BAD_PARAM;
643 es.text = "The directory for the calculation cannot be cleared." ;
644 throw SALOME::SALOME_Exception(es);
647 // Suppression du maillage publie dans SMESH
648 std::string MeshName = myIteration->GetMeshName() ;
649 DeleteResultInSmesh(nomFichier, MeshName) ;
653 //=============================================================================
654 void HOMARD_Gen_i::InvalideIterInfo(const char* nomIter)
656 MESSAGE("InvalideIterInfo : nomIter = " << nomIter);
657 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
658 if (CORBA::is_nil(myIteration))
660 SALOME::ExceptionStruct es;
661 es.type = SALOME::BAD_PARAM;
662 es.text = "Invalid iteration";
663 throw SALOME::SALOME_Exception(es);
667 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
668 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aIterSO);
669 for (; aIter->More(); aIter->Next())
671 SALOMEDS::SObject_var so = aIter->Value();
672 SALOMEDS::GenericAttribute_var anAttr;
673 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
674 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
675 std::string value (aCommentAttr->Value());
676 /* MESSAGE("... value = " << value);*/
677 if( (value == std::string("logInfo")) || ( value == std::string("SummaryInfo")) )
679 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
680 aStudyBuilder->RemoveObject(so);
684 const char * nomCas = myIteration->GetCaseName();
685 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
686 if (CORBA::is_nil(myCase))
688 SALOME::ExceptionStruct es;
689 es.type = SALOME::BAD_PARAM;
690 es.text = "Invalid case context";
691 throw SALOME::SALOME_Exception(es);
694 const char* nomDir = myIteration->GetDirName();
695 std::string commande = "rm -f " + std::string(nomDir) + "/info* " ;
696 commande += std::string(nomDir) + "/Liste.*info" ;
697 /* MESSAGE ( "commande = " << commande );*/
698 if ((system(commande.c_str())) != 0)
700 SALOME::ExceptionStruct es;
701 es.type = SALOME::BAD_PARAM;
702 es.text = "The directory for the calculation cannot be cleared." ;
703 throw SALOME::SALOME_Exception(es);
707 //=============================================================================
708 void HOMARD_Gen_i::InvalideYACS(const char* YACSName)
710 MESSAGE( "InvalideYACS : YACSName = " << YACSName );
711 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[YACSName];
712 if (CORBA::is_nil(myYACS))
714 SALOME::ExceptionStruct es;
715 es.type = SALOME::BAD_PARAM;
716 es.text = "Invalid schema YACS";
717 throw SALOME::SALOME_Exception(es);
721 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
722 SALOMEDS::ChildIterator_var aYACS = myStudy->NewChildIterator(aYACSSO);
723 for (; aYACS->More(); aYACS->Next())
725 SALOMEDS::SObject_var so = aYACS->Value();
726 SALOMEDS::GenericAttribute_var anAttr;
727 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
728 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
729 std::string value (aCommentAttr->Value());
730 if( value == std::string("xml") )
732 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
733 aStudyBuilder->RemoveObject(so);
736 std::string nomFichier = myYACS->GetXMLFile();
737 std::string commande = "rm -rf " + std::string(nomFichier) ;
738 MESSAGE ( "commande = " << commande );
739 if ((system(commande.c_str())) != 0)
741 SALOME::ExceptionStruct es;
742 es.type = SALOME::BAD_PARAM;
743 es.text = "The XML file for the schema YACS cannot be removed." ;
744 throw SALOME::SALOME_Exception(es);
748 //=============================================================================
749 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
751 MESSAGE( "InvalideZone : ZoneName = " << ZoneName );
752 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
753 if (CORBA::is_nil(myZone))
755 SALOME::ExceptionStruct es;
756 es.type = SALOME::BAD_PARAM;
757 es.text = "Invalid zone";
758 throw SALOME::SALOME_Exception(es);
761 HOMARD::listeHypo* maListe = myZone->GetHypo();
762 int numberOfHypo = maListe->length();
763 MESSAGE( ".. numberOfHypo = " << numberOfHypo );
764 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
766 std::string nomHypo = std::string((*maListe)[NumeHypo]);
767 MESSAGE( ".. nomHypo = " << nomHypo );
768 InvalideHypo(nomHypo.c_str());
771 //=============================================================================
772 //=============================================================================
774 //=============================================================================
775 //=============================================================================
776 // Association de lien entre des structures identifiees par leurs noms
777 //=============================================================================
778 //=============================================================================
779 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
781 MESSAGE( "AssociateCaseIter : " << nomCas << ", " << nomIter << ", " << labelIter );
783 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
784 if (CORBA::is_nil(myCase))
786 SALOME::ExceptionStruct es;
787 es.type = SALOME::BAD_PARAM;
788 es.text = "Invalid case";
789 throw SALOME::SALOME_Exception(es);
793 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
794 if (CORBA::is_nil(myIteration))
796 SALOME::ExceptionStruct es;
797 es.type = SALOME::BAD_PARAM;
798 es.text = "Invalid iteration";
799 throw SALOME::SALOME_Exception(es);
803 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
804 SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myCase)));
805 if (CORBA::is_nil(aCasSO))
807 SALOME::ExceptionStruct es;
808 es.type = SALOME::BAD_PARAM;
809 es.text = "Invalid case";
810 throw SALOME::SALOME_Exception(es);
814 aStudyBuilder->NewCommand();
815 SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
816 PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
817 "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
818 aStudyBuilder->CommitCommand();
820 myCase->AddIteration(nomIter);
821 myIteration->SetCaseName(nomCas);
823 //=====================================================================================
824 void HOMARD_Gen_i::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
826 MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
828 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypothesis];
829 ASSERT(!CORBA::is_nil(myHypo));
830 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
831 ASSERT(!CORBA::is_nil(aHypoSO));
833 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
834 ASSERT(!CORBA::is_nil(myZone));
835 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myZone)));
836 ASSERT(!CORBA::is_nil(aZoneSO));
838 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
840 aStudyBuilder->NewCommand();
842 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
843 aStudyBuilder->Addreference(aSubSO, aZoneSO);
845 aStudyBuilder->CommitCommand();
847 myZone->AddHypo(nomHypothesis);
848 myHypo->AddZone0(ZoneName, TypeUse);
850 //=============================================================================
851 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
853 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
855 // Verification de l'existence de l'hypothese
856 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
857 ASSERT(!CORBA::is_nil(myHypo));
858 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
859 ASSERT(!CORBA::is_nil(aHypoSO));
861 // Verification de l'existence de l'iteration
862 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
863 ASSERT(!CORBA::is_nil(myIteration));
864 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
865 ASSERT(!CORBA::is_nil(aIterSO));
867 // Gestion de l'arbre d'etudes
868 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
869 aStudyBuilder->NewCommand();
870 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
871 aStudyBuilder->Addreference(aSubSO, aHypoSO);
872 aStudyBuilder->CommitCommand();
875 myIteration->SetHypoName(nomHypo);
876 myHypo->LinkIteration(nomIter);
878 // On stocke les noms des champ a interpoler pour le futur controle de la donnée des pas de temps
879 myIteration->SupprFieldInterps() ;
880 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
881 int numberOfFieldsx2 = ListField->length();
882 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
884 std::string FieldName = std::string((*ListField)[iaux]) ;
885 myIteration->SetFieldInterp(FieldName.c_str()) ;
889 //=============================================================================
890 //=============================================================================
892 //=============================================================================
893 //=============================================================================
894 // Dissociation de lien entre des structures identifiees par leurs noms
895 //=============================================================================
896 //=============================================================================
897 void HOMARD_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
899 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
901 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypothesis];
902 ASSERT(!CORBA::is_nil(myHypo));
903 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
904 ASSERT(!CORBA::is_nil(aHypoSO));
906 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
907 ASSERT(!CORBA::is_nil(myZone));
908 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myZone)));
909 ASSERT(!CORBA::is_nil(aZoneSO));
911 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
913 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(aHypoSO);
914 for (; it->More(); it->Next())
916 SALOMEDS::SObject_var aHypObj = it->Value();
917 SALOMEDS::SObject_var ptrObj;
918 if (aHypObj->ReferencedObject(ptrObj))
920 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
922 aStudyBuilder->NewCommand();
923 aStudyBuilder->RemoveObject(aHypObj);
924 aStudyBuilder->CommitCommand();
930 myZone->SupprHypo(nomHypothesis);
931 myHypo->SupprZone(ZoneName);
933 //=============================================================================
934 //=============================================================================
937 //=============================================================================
938 //=============================================================================
939 // Recuperation des listes
940 //=============================================================================
941 //=============================================================================
942 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
944 MESSAGE("GetAllBoundarysName");
947 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
948 ret->length(myStudyContext._mesBoundarys.size());
949 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
951 for (it = myStudyContext._mesBoundarys.begin();
952 it != myStudyContext._mesBoundarys.end(); it++)
954 ret[i++] = CORBA::string_dup((*it).first.c_str());
959 //=============================================================================
960 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
962 MESSAGE("GetAllCasesName");
965 HOMARD::listeCases_var ret = new HOMARD::listeCases;
966 ret->length(myStudyContext._mesCas.size());
967 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
969 for (it = myStudyContext._mesCas.begin();
970 it != myStudyContext._mesCas.end(); it++)
972 ret[i++] = CORBA::string_dup((*it).first.c_str());
977 //=============================================================================
978 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
980 MESSAGE("GetAllHypothesesName");
983 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
984 ret->length(myStudyContext._mesHypotheses.size());
985 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
987 for (it = myStudyContext._mesHypotheses.begin();
988 it != myStudyContext._mesHypotheses.end(); it++)
990 ret[i++] = CORBA::string_dup((*it).first.c_str());
995 //=============================================================================
996 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
998 MESSAGE("GetAllIterationsName");
1001 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
1002 ret->length(myStudyContext._mesIterations.size());
1003 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
1005 for (it = myStudyContext._mesIterations.begin();
1006 it != myStudyContext._mesIterations.end(); it++)
1008 ret[i++] = CORBA::string_dup((*it).first.c_str());
1013 //=============================================================================
1014 HOMARD::listeYACSs* HOMARD_Gen_i::GetAllYACSsName()
1016 MESSAGE("GetAllYACSsName");
1019 HOMARD::listeYACSs_var ret = new HOMARD::listeYACSs;
1020 ret->length(myStudyContext._mesYACSs.size());
1021 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it;
1023 for (it = myStudyContext._mesYACSs.begin();
1024 it != myStudyContext._mesYACSs.end(); it++)
1026 ret[i++] = CORBA::string_dup((*it).first.c_str());
1031 //=============================================================================
1032 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
1034 MESSAGE("GetAllZonesName");
1037 HOMARD::listeZones_var ret = new HOMARD::listeZones;
1038 ret->length(myStudyContext._mesZones.size());
1039 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
1041 for (it = myStudyContext._mesZones.begin();
1042 it != myStudyContext._mesZones.end(); it++)
1044 ret[i++] = CORBA::string_dup((*it).first.c_str());
1049 //=============================================================================
1050 //=============================================================================
1052 //=============================================================================
1053 //=============================================================================
1054 // Recuperation des structures identifiees par leurs noms
1055 //=============================================================================
1056 //=============================================================================
1057 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
1059 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[nomBoundary];
1060 ASSERT(!CORBA::is_nil(myBoundary));
1061 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1063 //=============================================================================
1064 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
1066 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
1067 ASSERT(!CORBA::is_nil(myCase));
1068 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1070 //=============================================================================
1071 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
1073 HOMARD::HOMARD_Hypothesis_var myHypothesis = myStudyContext._mesHypotheses[nomHypothesis];
1074 ASSERT(!CORBA::is_nil(myHypothesis));
1075 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1077 //=============================================================================
1078 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* NomIterationation)
1080 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIterationation];
1081 ASSERT(!CORBA::is_nil(myIteration));
1082 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1084 //=============================================================================
1085 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::GetYACS(const char* nomYACS)
1087 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
1088 ASSERT(!CORBA::is_nil(myYACS));
1089 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
1091 //=============================================================================
1092 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
1094 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
1095 ASSERT(!CORBA::is_nil(myZone));
1096 return HOMARD::HOMARD_Zone::_duplicate(myZone);
1098 //=============================================================================
1099 //=============================================================================
1101 //=============================================================================
1102 //=============================================================================
1104 //=============================================================================
1105 //=============================================================================
1106 void HOMARD_Gen_i::MeshInfo(const char* nomCas, const char* MeshName, const char* MeshFile, const char* DirName, CORBA::Long Qual, CORBA::Long Diam, CORBA::Long Conn, CORBA::Long Tail, CORBA::Long Inte)
1108 INFOS ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1109 INFOS ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte );
1114 if ( _PublisMeshIN != 0 ) option = 2 ;
1115 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, 0, option) ;
1116 myCase->SetDirName(DirName) ;
1118 myCase->MeshInfo(Qual, Diam, Conn, Tail, Inte) ;
1122 //=============================================================================
1123 //=============================================================================
1125 //=============================================================================
1126 //=============================================================================
1127 // Recuperation des structures par le contexte
1128 //=============================================================================
1129 //=============================================================================
1130 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::LastIteration(const char* nomCas)
1132 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
1133 ASSERT(!CORBA::is_nil(myCase));
1135 HOMARD::HOMARD_Iteration_var myIteration = myCase->LastIteration();
1136 ASSERT(!CORBA::is_nil(myIteration));
1138 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1140 //=============================================================================
1141 //=============================================================================
1143 //=============================================================================
1144 //=============================================================================
1145 // Nouvelles structures
1146 //=============================================================================
1147 //=============================================================================
1148 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1150 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1151 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
1152 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
1153 return aCase._retn();
1155 //=============================================================================
1156 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
1158 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1159 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
1160 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
1161 return aHypo._retn();
1163 //=============================================================================
1164 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
1166 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1167 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
1168 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
1169 return aIter._retn();
1171 //=============================================================================
1172 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1174 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1175 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
1176 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1177 return aBoundary._retn();
1179 //=============================================================================
1180 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
1182 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1183 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
1184 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
1185 return aZone._retn();
1187 //=============================================================================
1188 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::newYACS()
1190 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1191 HOMARD_YACS_i* aServant = new HOMARD_YACS_i(_orb, engine);
1192 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(aServant->_this());
1193 return aYACS._retn();
1195 //=============================================================================
1196 //=============================================================================
1198 //=============================================================================
1199 //=============================================================================
1200 // Creation des structures identifiees par leurs noms
1201 //=============================================================================
1202 //=============================================================================
1203 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
1205 // Creation d'un cas initial
1206 // nomCas : nom du cas a creer
1207 // MeshName, MeshFile : nom et fichier du maillage correspondant
1210 INFOS ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1213 if ( _PublisMeshIN != 0 ) option = 2 ;
1214 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 0, 0, option) ;
1216 // Valeurs par defaut des filtrages
1217 myCase->SetPyram(0);
1219 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1221 //=============================================================================
1222 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromIteration(const char* nomCas, const char* DirNameStart)
1224 // nomCas : nom du cas a creer
1225 // DirNameStart : nom du répertoire contenant l'iteration de reprise
1228 INFOS ( "CreateCaseFromIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1229 std::string nomDirWork = getenv("PWD") ;
1232 // A. Decodage du point de reprise
1233 // A.1. Controle du répertoire de depart de l'iteration
1234 codret = CHDIR(DirNameStart) ;
1237 SALOME::ExceptionStruct es;
1238 es.type = SALOME::BAD_PARAM;
1239 es.text = "The directory of the iteration does not exist.";
1240 throw SALOME::SALOME_Exception(es);
1243 // A.2. Reperage des fichiers du répertoire de reprise
1244 std::string file_configuration = "" ;
1245 std::string file_maillage_homard = "" ;
1249 struct dirent *dirp;
1250 dp = opendir(DirNameStart);
1251 while ( (dirp = readdir(dp)) != NULL )
1253 std::string file_name(dirp->d_name);
1254 // MESSAGE ( file_name );
1255 bilan = file_name.find("HOMARD.Configuration.") ;
1256 if ( bilan != string::npos ) { file_configuration = file_name ; }
1257 bilan = file_name.find("maill.") ;
1258 if ( bilan != string::npos )
1260 bilan = file_name.find(".hom.med") ;
1261 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1266 HANDLE hFind = INVALID_HANDLE_VALUE;
1267 WIN32_FIND_DATA ffd;
1268 hFind = FindFirstFile(DirNameStart, &ffd);
1269 if (INVALID_HANDLE_VALUE != hFind) {
1270 while (FindNextFile(hFind, &ffd) != 0) {
1271 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1272 std::string file_name(ffd.cFileName);
1273 bilan = file_name.find("HOMARD.Configuration.") ;
1274 if ( bilan != string::npos ) { file_configuration = file_name ; }
1275 bilan = file_name.find("maill.") ;
1276 if ( bilan != string::npos )
1278 bilan = file_name.find(".hom.med") ;
1279 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1285 MESSAGE ( "==> file_configuration : " << file_configuration ) ;
1286 MESSAGE ( "==> file_maillage_homard : " << file_maillage_homard ) ;
1288 if ( ( file_configuration == "" ) || ( file_maillage_homard == "" ) )
1290 SALOME::ExceptionStruct es;
1291 es.type = SALOME::BAD_PARAM;
1293 if ( file_configuration == "" ) { text = "The configuration file cannot be found." ; }
1294 else { text = "The HOMARD mesh file cannot be found." ; }
1295 es.text = CORBA::string_dup(text.c_str());
1296 throw SALOME::SALOME_Exception(es);
1299 // B. Lecture du fichier de configuration
1300 // ATTENTION : on doit veiller a la coherence entre HomardDriver et CreateCaseFromIteration
1307 // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1308 std::ifstream fichier( file_configuration.c_str() );
1309 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1311 std::string ligne; // variable contenant chaque ligne lue
1312 std::string mot_cle;
1313 std::string argument;
1315 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1316 while ( std::getline( fichier, ligne ) )
1318 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1319 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1320 ligne_bis >> mot_cle ;
1321 // B.2. Des valeurs entieres : le second bloc de la ligne
1322 if ( mot_cle == "NumeIter" )
1324 ligne_bis >> NumeIter ;
1327 // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1328 else if ( ( mot_cle == "TypeConf" ) || ( mot_cle == "TypeElem" ) )
1330 ligne_bis >> argument ;
1332 if ( mot_cle == "TypeConf" )
1334 if ( argument == "conforme" ) { TypeConf = 1 ; }
1335 else if ( argument == "non_conforme_1_noeud" ) { TypeConf = 2 ; }
1336 else if ( argument == "non_conforme_1_arete" ) { TypeConf = 3 ; }
1337 else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1339 else if ( mot_cle == "TypeElem" )
1341 if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1342 else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1345 // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1346 // il faut les supprimer
1347 else if ( ( mot_cle == "CCNoMNP1" ) || ( mot_cle == "CCMaiNP1" ) )
1349 ligne_bis >> argument ;
1350 if ( argument[0] == '"' ) { decalage = 1 ; }
1351 else { decalage = 0 ; }
1352 size_t size = argument.size() + 1 - 2*decalage ;
1354 if ( mot_cle == "CCNoMNP1" )
1356 MeshName = new char[ size ];
1357 strncpy( MeshName, argument.c_str()+decalage, size );
1358 MeshName[size-1] = '\0' ;
1360 else if ( mot_cle == "CCMaiNP1" )
1362 MeshFile = new char[ size ];
1363 strncpy( MeshFile, argument.c_str()+decalage, size );
1364 MeshFile[size-1] = '\0' ;
1368 MESSAGE ( "==> TypeConf : " << TypeConf ) ;
1369 MESSAGE ( "==> MeshName : " << MeshName ) ;
1370 MESSAGE ( "==> MeshFile : " << MeshFile ) ;
1371 MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1372 MESSAGE ( "==> Pyram : " << Pyram ) ;
1376 SALOME::ExceptionStruct es;
1377 es.type = SALOME::BAD_PARAM;
1378 std::string text = "The configuration file cannot be read." ;
1379 es.text = CORBA::string_dup(text.c_str());
1380 throw SALOME::SALOME_Exception(es);
1383 // C. Creation effective du cas
1386 if ( _PublisMeshIN != 0 ) option = 2 ;
1387 HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, option) ;
1389 // D. Parametrages lus dans le fichier de configuration
1391 myCase->SetConfType (TypeConf) ;
1392 myCase->SetExtType (TypeExt) ;
1393 myCase->SetPyram (Pyram) ;
1395 // E. Copie du fichier de maillage homard
1396 // E.1. Répertoire associe au cas
1397 char* nomDirCase = myCase->GetDirName() ;
1398 // E.2. Répertoire associe a l'iteration de ce cas
1400 IterName = myCase->GetIter0Name() ;
1401 HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1402 char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1403 Iter->SetDirNameLoc(nomDirIter);
1404 std::string nomDirIterTotal ;
1405 nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1407 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1409 if (_mkdir(nomDirIterTotal.c_str()) != 0)
1412 MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1413 SALOME::ExceptionStruct es;
1414 es.type = SALOME::BAD_PARAM;
1415 std::string text = "The directory for the computation cannot be created." ;
1416 es.text = CORBA::string_dup(text.c_str());
1417 throw SALOME::SALOME_Exception(es);
1419 // E.3. Copie du maillage HOMARD au format MED
1420 codret = CHDIR(DirNameStart) ;
1421 std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1422 MESSAGE ( "commande : " << commande ) ;
1423 codret = system(commande.c_str()) ;
1424 MESSAGE ( "codret : " << codret ) ;
1427 SALOME::ExceptionStruct es;
1428 es.type = SALOME::BAD_PARAM;
1429 es.text = "The starting point for the case cannot be copied into the working directory.";
1430 throw SALOME::SALOME_Exception(es);
1439 CHDIR(nomDirWork.c_str());
1440 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1442 //=============================================================================
1443 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1445 // nomCas : nom du cas a creer
1446 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1449 INFOS ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1451 std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1453 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1454 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1456 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1458 //=============================================================================
1459 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1461 // nomCas : nom du cas a creer
1462 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1463 // Number : numero de l'iteration de depart
1466 INFOS ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1469 SALOME::ExceptionStruct es;
1470 es.type = SALOME::BAD_PARAM;
1471 es.text = "The number of iteration must be positive.";
1472 throw SALOME::SALOME_Exception(es);
1476 std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1478 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1479 HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1481 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1483 //=============================================================================
1484 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1486 // Retourne le nom du répertoire ou se trouve l'iteration voulue.
1487 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1488 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1491 MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1492 std::string nomDirWork = getenv("PWD") ;
1493 std::string DirNameStartIter ;
1495 int NumeIterMax = -1 ;
1497 // A.1. Controle du répertoire de depart du cas
1498 codret = CHDIR(DirNameStart) ;
1501 SALOME::ExceptionStruct es;
1502 es.type = SALOME::BAD_PARAM;
1503 es.text = "The directory of the case for the pursuit does not exist.";
1504 throw SALOME::SALOME_Exception(es);
1507 // A.2. Reperage des sous-répertoire du répertoire de reprise
1508 bool existe = false ;
1511 struct dirent *dirp;
1512 dp = opendir(DirNameStart);
1513 while ( (dirp = readdir(dp)) != NULL ) {
1514 std::string DirName_1(dirp->d_name);
1516 HANDLE hFind = INVALID_HANDLE_VALUE;
1517 WIN32_FIND_DATA ffd;
1518 hFind = FindFirstFile(DirNameStart, &ffd);
1519 if (INVALID_HANDLE_VALUE != hFind) {
1520 while (FindNextFile(hFind, &ffd) != 0) {
1521 std::string DirName_1 = "";
1522 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1523 DirName_1 = std::string(ffd.cFileName);
1526 if ( ( DirName_1 != "." ) && ( DirName_1 != ".." ) )
1528 if ( CHDIR(DirName_1.c_str()) == 0 )
1530 // On cherche le fichier de configuration dans ce sous-répertoire
1531 codret = CHDIR(DirNameStart);
1534 struct dirent *dirp_1;
1535 dp_1 = opendir(DirName_1.c_str()) ;
1536 while ( (dirp_1 = readdir(dp_1)) != NULL )
1538 std::string file_name_1(dirp_1->d_name);
1540 HANDLE hFind1 = INVALID_HANDLE_VALUE;
1541 WIN32_FIND_DATA ffd1;
1542 hFind1 = FindFirstFile(DirName_1.c_str(), &ffd1);
1543 while (FindNextFile(hFind1, &ffd1) != 0)
1545 if (ffd1.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1546 std::string file_name_1(ffd1.cFileName);
1548 int bilan = file_name_1.find("HOMARD.Configuration.") ;
1549 if ( bilan != string::npos )
1551 // Decodage du fichier pour trouver le numero d'iteration
1552 CHDIR(DirName_1.c_str()) ;
1554 std::ifstream fichier( file_name_1.c_str() );
1555 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1558 std::string ligne; // variable contenant chaque ligne lue
1559 std::string mot_cle;
1560 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1561 while ( std::getline( fichier, ligne ) )
1563 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1564 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1565 ligne_bis >> mot_cle ;
1566 if ( mot_cle == "NumeIter" )
1568 ligne_bis >> NumeIter ;
1570 // MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1571 if ( Number == - 1 )
1573 if ( NumeIter >= NumeIterMax )
1575 NumeIterMax = NumeIter ;
1576 DirNameStartIter = DirName_1 ;
1581 if ( NumeIter == Number )
1583 DirNameStartIter = DirName_1 ;
1593 SALOME::ExceptionStruct es;
1594 es.type = SALOME::BAD_PARAM;
1595 std::string text = "The configuration file cannot be read." ;
1596 es.text = CORBA::string_dup(text.c_str());
1597 throw SALOME::SALOME_Exception(es);
1599 CHDIR(DirNameStart) ;
1601 if ( existe ) { break ; }
1608 if ( existe ) { break ; }
1617 CHDIR(nomDirWork.c_str());
1619 if ( ( Number >= 0 && ( !existe ) ) || ( Number < 0 && ( NumeIterMax == -1 ) ) )
1621 SALOME::ExceptionStruct es;
1622 es.type = SALOME::BAD_PARAM;
1623 es.text = "The directory of the iteration does not exist.";
1624 throw SALOME::SALOME_Exception(es);
1628 return DirNameStartIter ;
1630 //=============================================================================
1631 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase0(const char* nomCas, const char* MeshName, const char* MeshFile, CORBA::Long MeshOption, CORBA::Long NumeIter, CORBA::Long Option)
1633 // nomCas : nom du cas a creer
1634 // MeshName, MeshFile : nom et fichier du maillage correspondant
1635 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1636 // 1 : le maillage fourni peut ne pas exister ==> on continue si absent
1637 // -1 : le maillage n'est pas fourni
1638 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1639 // Option : multiple de nombres premiers
1640 // 1 : aucune option
1641 // x2 : publication du maillage dans SMESH
1643 MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1644 MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1645 MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1651 // A.2. Controle du nom :
1652 if ((myStudyContext._mesCas).find(nomCas)!=(myStudyContext._mesCas).end())
1654 SALOME::ExceptionStruct es;
1655 es.type = SALOME::BAD_PARAM;
1656 es.text = "This case has already been defined.";
1657 throw SALOME::SALOME_Exception(es);
1661 // A.3. Controle du fichier du maillage
1662 int existeMeshFile ;
1663 if ( MeshOption >= 0 )
1665 existeMeshFile = MEDFileExist ( MeshFile ) ;
1666 MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1667 if ( ( existeMeshFile == 0 ) && ( MeshOption == 0 ) )
1669 SALOME::ExceptionStruct es;
1670 es.type = SALOME::BAD_PARAM;
1671 es.text = "The mesh file does not exist.";
1672 throw SALOME::SALOME_Exception(es);
1676 else { existeMeshFile = 0 ; }
1678 // B. Creation de l'objet cas et publication
1679 // MESSAGE ( "CreateCase0 : Creation de l'objet" );
1680 HOMARD::HOMARD_Cas_var myCase = newCase();
1681 myCase->SetName(nomCas);
1682 SALOMEDS::SObject_var aSO;
1683 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myCase, nomCas);
1684 myStudyContext._mesCas[nomCas] = myCase;
1686 // C. Caracteristiques du maillage
1687 if ( existeMeshFile != 0 )
1689 // Les valeurs extremes des coordonnées
1690 // MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnées" );
1691 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1692 HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1693 if (LesExtremes.size()!=10) { return 0; }
1695 for (int i =0 ; i< LesExtremes.size() ; i++)
1696 aSeq[i]=LesExtremes[i] ;
1697 myCase->SetBoundingBox(aSeq) ;
1699 // MESSAGE ( "CreateCase0 : Les groupes" );
1700 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile) ;
1701 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1702 aSeqGroupe->length(LesGroupes.size());
1703 std::set<std::string>::const_iterator it ;
1705 for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1706 aSeqGroupe[i++]=(*it).c_str() ;
1707 myCase->SetGroups(aSeqGroupe) ;
1710 // D. L'iteration initiale du cas
1711 MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1712 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1713 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1715 std::string NomIteration = std::string(MeshName) ;
1716 while ( (myStudyContext._mesIterations).find(NomIteration) != (myStudyContext._mesIterations.end()) )
1718 std::ostringstream nom;
1719 nom << MeshName << monNum;
1720 NomIteration = nom.str();
1723 MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1725 // D.2. Creation de l'iteration
1726 HOMARD::HOMARD_Iteration_var anIter = newIteration();
1727 myStudyContext._mesIterations[NomIteration] = anIter;
1728 anIter->SetName(NomIteration.c_str());
1729 AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1731 // D.4. Maillage correspondant
1732 if ( existeMeshFile != 0 )
1734 anIter->SetMeshFile(MeshFile);
1735 if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1737 anIter->SetMeshName(MeshName);
1739 // D.5. Numero d'iteration
1740 anIter->SetNumber(NumeIter);
1743 SetEtatIter(NomIteration.c_str(), -NumeIter);
1746 return HOMARD::HOMARD_Cas::_duplicate(myCase);
1748 //=============================================================================
1749 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1751 INFOS ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1754 // A. Controle du nom :
1755 if ((myStudyContext._mesHypotheses).find(nomHypothesis) != (myStudyContext._mesHypotheses).end())
1757 SALOME::ExceptionStruct es;
1758 es.type = SALOME::BAD_PARAM;
1759 es.text = "This hypothesis has already been defined.";
1760 throw SALOME::SALOME_Exception(es);
1764 // B. Creation de l'objet
1765 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1766 if (CORBA::is_nil(myHypothesis))
1768 SALOME::ExceptionStruct es;
1769 es.type = SALOME::BAD_PARAM;
1770 es.text = "Unable to create the hypothesis";
1771 throw SALOME::SALOME_Exception(es);
1774 myHypothesis->SetName(nomHypothesis);
1776 // C. Enregistrement
1777 myStudyContext._mesHypotheses[nomHypothesis] = myHypothesis;
1779 SALOMEDS::SObject_var aSO;
1780 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myHypothesis, nomHypothesis);
1782 // D. Valeurs par defaut des options avancees
1783 myHypothesis->SetNivMax(-1);
1784 myHypothesis->SetDiamMin(-1.0);
1785 myHypothesis->SetAdapInit(0);
1786 myHypothesis->SetExtraOutput(1);
1788 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1791 //=============================================================================
1792 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1793 //=============================================================================
1795 INFOS ("CreateIteration : NomIteration = " << NomIteration << ", nomIterParent = " << nomIterParent);
1798 HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterParent];
1799 if (CORBA::is_nil(myIterationParent))
1801 SALOME::ExceptionStruct es;
1802 es.type = SALOME::BAD_PARAM;
1803 es.text = "The parent iteration is not defined.";
1804 throw SALOME::SALOME_Exception(es);
1808 const char* nomCas = myIterationParent->GetCaseName();
1809 MESSAGE ("CreateIteration : nomCas = " << nomCas);
1810 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
1811 if (CORBA::is_nil(myCase))
1813 SALOME::ExceptionStruct es;
1814 es.type = SALOME::BAD_PARAM;
1815 es.text = "Invalid case context";
1816 throw SALOME::SALOME_Exception(es);
1819 const char* nomDirCase = myCase->GetDirName();
1821 // Controle du nom :
1822 if ((myStudyContext._mesIterations).find(NomIteration)!=(myStudyContext._mesIterations).end())
1824 SALOME::ExceptionStruct es;
1825 es.type = SALOME::BAD_PARAM;
1826 es.text = "This iteration has already been defined.";
1827 throw SALOME::SALOME_Exception(es);
1831 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1832 if (CORBA::is_nil(myIteration))
1834 SALOME::ExceptionStruct es;
1835 es.type = SALOME::BAD_PARAM;
1836 es.text = "Unable to create the iteration";
1837 throw SALOME::SALOME_Exception(es);
1840 myStudyContext._mesIterations[std::string(NomIteration)] = myIteration;
1841 // Nom de l'iteration et du maillage
1842 myIteration->SetName(NomIteration);
1843 myIteration->SetMeshName(NomIteration);
1844 myIteration->SetState(1);
1846 int numero = myIterationParent->GetNumber() + 1;
1847 myIteration->SetNumber(numero);
1849 // Nombre d'iterations deja connues pour le cas, permettant
1850 // la creation d'un sous-répertoire unique
1851 int nbitercase = myCase->GetNumberofIter();
1852 char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1853 myIteration->SetDirNameLoc(nomDirIter);
1855 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1856 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1857 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1858 // situation la plus frequente.
1859 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1860 // le nombre d'iterations du cas permet d'eviter les collisions.
1862 if ( nbitercase < 100 ) { jaux = 2 ; }
1863 else if ( nbitercase < 1000 ) { jaux = 3 ; }
1864 else if ( nbitercase < 10000 ) { jaux = 4 ; }
1865 else if ( nbitercase < 100000 ) { jaux = 5 ; }
1867 std::ostringstream iaux ;
1868 iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1869 std::stringstream MeshFile;
1870 MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1871 myIteration->SetMeshFile(MeshFile.str().c_str());
1873 // Association avec le cas
1874 std::string label = "IterationHomard_" + std::string(nomIterParent);
1875 AssociateCaseIter(nomCas, NomIteration, label.c_str());
1876 // Lien avec l'iteration precedente
1877 myIterationParent->LinkNextIteration(NomIteration);
1878 myIteration->SetIterParentName(nomIterParent);
1879 // Gestion de l'arbre d'etudes
1880 SALOMEDS::SObject_var aIterSOParent = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIterationParent)));
1881 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
1882 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
1883 aStudyBuilder->NewCommand();
1884 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
1885 aStudyBuilder->Addreference(aSubSO, aIterSOParent);
1886 aStudyBuilder->CommitCommand();
1888 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1890 //=============================================================================
1891 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1893 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1896 // Controle du nom :
1897 if ((myStudyContext._mesBoundarys).find(BoundaryName)!=(myStudyContext._mesBoundarys).end())
1899 MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1900 SALOME::ExceptionStruct es;
1901 es.type = SALOME::BAD_PARAM;
1902 es.text = "This boundary has already been defined";
1903 throw SALOME::SALOME_Exception(es);
1907 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1908 myBoundary->SetName(BoundaryName);
1909 myBoundary->SetType(BoundaryType);
1911 myStudyContext._mesBoundarys[BoundaryName] = myBoundary;
1913 SALOMEDS::SObject_var aSO;
1914 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myBoundary, BoundaryName);
1916 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1918 //=============================================================================
1919 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCAO(const char* BoundaryName, const char* CAOFile)
1921 INFOS ("CreateBoundaryCAO : BoundaryName = " << BoundaryName << ", CAOFile = " << CAOFile );
1922 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, -1);
1923 myBoundary->SetDataFile( CAOFile ) ;
1925 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1927 //=============================================================================
1928 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1930 INFOS ("CreateBoundaryDi : BoundaryName = " << BoundaryName << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1931 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1932 myBoundary->SetDataFile( MeshFile ) ;
1933 myBoundary->SetMeshName( MeshName ) ;
1935 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1937 //=============================================================================
1938 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1939 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1940 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1941 CORBA::Double Rayon)
1943 INFOS ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
1945 SALOME::ExceptionStruct es;
1948 { es.text = "The radius must be positive." ;
1950 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1951 if ( daux < 0.0000001 )
1952 { es.text = "The axis must be a non 0 vector." ;
1956 es.type = SALOME::BAD_PARAM;
1957 throw SALOME::SALOME_Exception(es);
1961 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1962 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1964 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1966 //=============================================================================
1967 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1968 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1969 CORBA::Double Rayon)
1971 INFOS ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
1973 SALOME::ExceptionStruct es;
1976 { es.text = "The radius must be positive." ;
1980 es.type = SALOME::BAD_PARAM;
1981 throw SALOME::SALOME_Exception(es);
1985 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1986 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1988 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1990 //=============================================================================
1991 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
1992 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
1993 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
1995 INFOS ("CreateBoundaryConeA : BoundaryName = " << BoundaryName ) ;
1997 SALOME::ExceptionStruct es;
1999 if ( Angle <= 0.0 || Angle >= 90.0 )
2000 { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
2002 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2003 if ( daux < 0.0000001 )
2004 { es.text = "The axis must be a non 0 vector." ;
2008 es.type = SALOME::BAD_PARAM;
2009 throw SALOME::SALOME_Exception(es);
2013 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
2014 myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
2016 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2018 //=============================================================================
2019 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
2020 CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
2021 CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
2023 INFOS ("CreateBoundaryConeR : BoundaryName = " << BoundaryName ) ;
2025 SALOME::ExceptionStruct es;
2027 if ( Rayon1 < 0.0 || Rayon2 < 0.0 )
2028 { es.text = "The radius must be positive." ;
2030 double daux = fabs(Rayon2-Rayon1) ;
2031 if ( daux < 0.0000001 )
2032 { es.text = "The radius must be different." ;
2034 daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
2035 if ( daux < 0.0000001 )
2036 { es.text = "The centers must be different." ;
2040 es.type = SALOME::BAD_PARAM;
2041 throw SALOME::SALOME_Exception(es);
2045 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
2046 myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
2048 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2050 //=============================================================================
2051 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryTorus(const char* BoundaryName,
2052 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2053 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2054 CORBA::Double RayonRev, CORBA::Double RayonPri)
2056 INFOS ("CreateBoundaryTorus : BoundaryName = " << BoundaryName ) ;
2058 SALOME::ExceptionStruct es;
2060 if ( ( RayonRev <= 0.0 ) || ( RayonPri <= 0.0 ) )
2061 { es.text = "The radius must be positive." ;
2063 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2064 if ( daux < 0.0000001 )
2065 { es.text = "The axis must be a non 0 vector." ;
2069 es.type = SALOME::BAD_PARAM;
2070 throw SALOME::SALOME_Exception(es);
2074 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 5) ;
2075 myBoundary->SetTorus( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, RayonRev, RayonPri ) ;
2077 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2079 //=============================================================================
2080 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
2082 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
2085 // Controle du nom :
2086 if ((myStudyContext._mesZones).find(ZoneName)!=(myStudyContext._mesZones).end())
2088 SALOME::ExceptionStruct es;
2089 es.type = SALOME::BAD_PARAM;
2090 es.text = "This zone has already been defined";
2091 throw SALOME::SALOME_Exception(es);
2095 HOMARD::HOMARD_Zone_var myZone = newZone();
2096 myZone->SetName(ZoneName);
2097 myZone->SetType(ZoneType);
2099 myStudyContext._mesZones[ZoneName] = myZone;
2101 SALOMEDS::SObject_var aSO;
2102 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myZone, ZoneName);
2104 return HOMARD::HOMARD_Zone::_duplicate(myZone);
2106 //=============================================================================
2107 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
2108 CORBA::Double Xmini, CORBA::Double Xmaxi,
2109 CORBA::Double Ymini, CORBA::Double Ymaxi,
2110 CORBA::Double Zmini, CORBA::Double Zmaxi)
2112 INFOS ("CreateZoneBox : ZoneName = " << ZoneName ) ;
2114 SALOME::ExceptionStruct es;
2116 if ( Xmini > Xmaxi )
2117 { es.text = "The X coordinates are not coherent." ;
2119 if ( Ymini > Ymaxi )
2120 { es.text = "The Y coordinates are not coherent." ;
2122 if ( Zmini > Zmaxi )
2123 { es.text = "The Z coordinates are not coherent." ;
2127 es.type = SALOME::BAD_PARAM;
2128 throw SALOME::SALOME_Exception(es);
2132 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
2133 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2135 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2137 //=============================================================================
2138 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
2139 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
2141 INFOS ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
2143 SALOME::ExceptionStruct es;
2146 { es.text = "The radius must be positive." ;
2150 es.type = SALOME::BAD_PARAM;
2151 throw SALOME::SALOME_Exception(es);
2155 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
2156 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2158 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2160 //=============================================================================
2161 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
2162 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2163 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2164 CORBA::Double Rayon, CORBA::Double Haut)
2166 INFOS ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
2168 SALOME::ExceptionStruct es;
2171 { es.text = "The radius must be positive." ;
2173 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2174 if ( daux < 0.0000001 )
2175 { es.text = "The axis must be a non 0 vector." ;
2178 { es.text = "The height must be positive." ;
2182 es.type = SALOME::BAD_PARAM;
2183 throw SALOME::SALOME_Exception(es);
2187 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
2188 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
2190 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2192 //=============================================================================
2193 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
2194 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2195 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2196 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
2198 INFOS ("CreateZonePipe : ZoneName = " << ZoneName ) ;
2200 SALOME::ExceptionStruct es;
2202 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2203 { es.text = "The radius must be positive." ;
2205 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2206 if ( daux < 0.0000001 )
2207 { es.text = "The axis must be a non 0 vector." ;
2210 { es.text = "The height must be positive." ;
2212 if ( Rayon <= Rayonint )
2213 { es.text = "The external radius must be higher than the internal radius." ;
2217 es.type = SALOME::BAD_PARAM;
2218 throw SALOME::SALOME_Exception(es);
2222 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
2223 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
2225 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2227 //=============================================================================
2228 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
2229 CORBA::Double Umini, CORBA::Double Umaxi,
2230 CORBA::Double Vmini, CORBA::Double Vmaxi,
2233 INFOS ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
2234 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
2235 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
2236 // MESSAGE ("Orient = " << Orient ) ;
2238 SALOME::ExceptionStruct es;
2240 if ( Umini > Umaxi )
2241 { es.text = "The first coordinates are not coherent." ;
2243 if ( Vmini > Vmaxi )
2244 { es.text = "The second coordinates are not coherent." ;
2246 if ( Orient < 1 || Orient > 3 )
2247 { es.text = "The orientation must be 1, 2 or 3." ;
2251 es.type = SALOME::BAD_PARAM;
2252 throw SALOME::SALOME_Exception(es);
2256 double Xmini, Xmaxi ;
2257 double Ymini, Ymaxi ;
2258 double Zmini, Zmaxi ;
2266 else if ( Orient == 2 )
2273 else if ( Orient == 3 )
2280 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2282 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2283 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2285 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2287 //=============================================================================
2288 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2289 CORBA::Double Ucentre, CORBA::Double Vcentre,
2290 CORBA::Double Rayon,
2293 INFOS ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
2295 SALOME::ExceptionStruct es;
2298 { es.text = "The radius must be positive." ;
2300 if ( Orient < 1 || Orient > 3 )
2301 { es.text = "The orientation must be 1, 2 or 3." ;
2305 es.type = SALOME::BAD_PARAM;
2306 throw SALOME::SALOME_Exception(es);
2314 { Xcentre = Ucentre ;
2317 else if ( Orient == 2 )
2320 Zcentre = Vcentre ; }
2321 else if ( Orient == 3 )
2322 { Xcentre = Vcentre ;
2324 Zcentre = Ucentre ; }
2325 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2327 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2328 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2330 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2332 //=============================================================================
2333 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2334 CORBA::Double Ucentre, CORBA::Double Vcentre,
2335 CORBA::Double Rayon, CORBA::Double Rayonint,
2338 INFOS ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
2340 SALOME::ExceptionStruct es;
2342 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2343 { es.text = "The radius must be positive." ;
2345 if ( Orient < 1 || Orient > 3 )
2346 { es.text = "The orientation must be 1, 2 or 3." ;
2348 if ( Rayon <= Rayonint )
2349 { es.text = "The external radius must be higher than the internal radius." ;
2353 es.type = SALOME::BAD_PARAM;
2354 throw SALOME::SALOME_Exception(es);
2362 { Xcentre = Ucentre ;
2365 else if ( Orient == 2 )
2368 Zcentre = Vcentre ; }
2369 else if ( Orient == 3 )
2370 { Xcentre = Vcentre ;
2372 Zcentre = Ucentre ; }
2373 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2375 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2376 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2378 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2380 //=============================================================================
2381 //=============================================================================
2386 //=============================================================================
2387 //=============================================================================
2388 // Traitement d'une iteration
2389 // etatMenage = 1 : destruction du répertoire d'execution
2390 // modeHOMARD = 1 : adaptation
2391 // != 1 : information avec les options modeHOMARD
2392 // Option1 >0 : appel depuis python
2393 // <0 : appel depuis GUI
2394 // Option2 : multiple de nombres premiers
2395 // 1 : aucune option
2396 // x2 : publication du maillage dans SMESH
2397 //=============================================================================
2398 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2400 INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2405 // A.1. L'objet iteration
2406 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIteration];
2407 ASSERT(!CORBA::is_nil(myIteration));
2409 // A.2. Controle de la possibilite d'agir
2410 // A.2.1. Etat de l'iteration
2411 int etat = myIteration->GetState();
2412 MESSAGE ( "etat = "<<etat );
2413 // A.2.2. On ne calcule pas l'iteration initiale, ni une iteration deja calculee
2414 if ( modeHOMARD == 1 )
2418 SALOME::ExceptionStruct es;
2419 es.type = SALOME::BAD_PARAM;
2420 es.text = "This iteration is the first of the case and cannot be computed.";
2421 throw SALOME::SALOME_Exception(es);
2424 else if ( ( etat == 2 ) & ( modeHOMARD == 1 ) )
2426 SALOME::ExceptionStruct es;
2427 es.type = SALOME::BAD_PARAM;
2428 es.text = "This iteration is already computed.";
2429 throw SALOME::SALOME_Exception(es);
2433 // A.2.3. On n'analyse pas une iteration non calculee
2438 SALOME::ExceptionStruct es;
2439 es.type = SALOME::BAD_PARAM;
2440 es.text = "This iteration is not computed.";
2441 throw SALOME::SALOME_Exception(es);
2446 // A.3. Numero de l'iteration
2447 // siterp1 : numero de l'iteration a traiter
2449 // siter : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2450 // Ou si information :
2452 int NumeIter = myIteration->GetNumber();
2453 std::string siterp1 ;
2454 std::stringstream saux1 ;
2456 siterp1 = saux1.str() ;
2457 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2460 if ( modeHOMARD==1 )
2462 std::stringstream saux0 ;
2463 int iaux = max(0, NumeIter-1) ;
2465 siter = saux0.str() ;
2466 if (NumeIter < 11) { siter = "0" + siter ; }
2469 { siter = siterp1 ; }
2472 const char* nomCas = myIteration->GetCaseName();
2473 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
2474 ASSERT(!CORBA::is_nil(myCase));
2476 // B. Les répertoires
2477 // B.1. Le répertoire courant
2478 std::string nomDirWork = getenv("PWD") ;
2479 // B.2. Le sous-répertoire de l'iteration a traiter
2480 char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2481 MESSAGE( ". DirCompute = " << DirCompute );
2483 // C. Le fichier des messages
2484 // C.1. Le deroulement de l'execution de HOMARD
2485 std::string LogFile = DirCompute ;
2486 LogFile += "/Liste" ;
2487 if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2489 MESSAGE (". LogFile = " << LogFile);
2490 if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2491 // C.2. Le bilan de l'analyse du maillage
2492 std::string FileInfo = DirCompute ;
2494 if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2496 { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2497 else { FileInfo += "info_ap" ; }
2499 FileInfo += "." + siterp1 + ".bilan" ;
2500 myIteration->SetFileInfo(FileInfo.c_str());
2502 // D. On passe dans le répertoire de l'iteration a calculer
2503 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2506 // E. Les données de l'exécution HOMARD
2507 // E.1. L'objet du texte du fichier de configuration
2508 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2509 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2511 // E.2. Le maillage associe a l'iteration
2512 const char* NomMesh = myIteration->GetMeshName();
2513 MESSAGE ( ". NomMesh = " << NomMesh );
2514 const char* MeshFile = myIteration->GetMeshFile();
2515 MESSAGE ( ". MeshFile = " << MeshFile );
2517 // E.3. Les données du traitement HOMARD
2519 if ( modeHOMARD == 1 )
2522 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2523 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2524 codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2528 InvalideIterInfo(NomIteration);
2529 myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2531 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2532 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2533 myDriver->CreeFichierDonn();
2536 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2537 int BoundaryOption = DriverTexteBoundary(myCase, myDriver) ;
2539 // E.5. Ecriture du texte dans le fichier
2540 MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2542 { myDriver->CreeFichier(); }
2546 int codretexec = 1789 ;
2549 codretexec = myDriver->ExecuteHomard(Option1);
2551 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2552 // En mode adaptation, on ajuste l'etat de l'iteration
2553 if ( modeHOMARD == 1 )
2555 if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2556 else { SetEtatIter(NomIteration,1); }
2557 // GERALD -- QMESSAGE BOX
2561 // H. Gestion des resultats
2564 std::string Commentaire ;
2565 // H.1. Le fichier des messages, dans tous les cas
2566 Commentaire = "log" ;
2567 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2568 else { Commentaire += "Info" ; }
2569 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2571 // H.2. Si tout s'est bien passe :
2572 if (codretexec == 0)
2574 // H.2.1. Le fichier de bilan
2575 Commentaire = "Summary" ;
2576 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2577 else { Commentaire += "Info" ; }
2578 PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2579 // H.2.2. Le fichier de maillage obtenu
2580 if ( modeHOMARD == 1 )
2582 std::stringstream saux0 ;
2583 Commentaire = "Mesh" ;
2584 Commentaire += " " + siterp1 ;
2585 PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2586 if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2589 // H.3 Message d'erreur
2590 if (codretexec != 0)
2592 std::string text = "" ;
2593 // Message d'erreur en cas de probleme en adaptation
2594 if ( modeHOMARD == 1 )
2596 text = "Error during the adaptation.\n" ;
2597 bool stopvu = false ;
2598 std::ifstream fichier( LogFile.c_str() );
2599 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
2601 std::string ligne; // variable contenant chaque ligne lue
2602 while ( std::getline( fichier, ligne ) )
2606 { text += ligne+ "\n"; }
2609 int position = ligne.find( "===== HOMARD ===== STOP =====" ) ;
2610 if ( position > 0 ) { stopvu = true ; }
2615 text += "\n\nSee the file " + LogFile + "\n" ;
2617 SALOME::ExceptionStruct es;
2618 es.type = SALOME::BAD_PARAM;
2619 es.text = CORBA::string_dup(text.c_str());
2620 throw SALOME::SALOME_Exception(es);
2622 // En mode information, on force le succes pour pouvoir consulter le fichier log
2623 if ( modeHOMARD != 1 ) { codretexec = 0 ; }
2627 // I. Menage et retour dans le répertoire du cas
2631 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2633 CHDIR(nomDirWork.c_str());
2636 // J. Suivi de la frontière CAO
2637 // std::cout << "- codret : " << codret << std::endl;
2638 // std::cout << "- modeHOMARD : " << modeHOMARD << std::endl;
2639 // std::cout << "- BoundaryOption : " << BoundaryOption << std::endl;
2640 // std::cout << "- codretexec : " << codretexec << std::endl;
2643 if ( ( modeHOMARD == 1 ) && ( BoundaryOption % 5 == 0 ) && (codretexec == 0) )
2645 INFOS ( "Suivi de frontière CAO" );
2646 codret = ComputeCAO(myCase, myIteration, Option1, Option2) ;
2652 //=============================================================================
2653 // Calcul d'une iteration : partie spécifique à l'adaptation
2654 //=============================================================================
2655 CORBA::Long HOMARD_Gen_i::ComputeAdap(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage, HomardDriver* myDriver, CORBA::Long Option1, CORBA::Long Option2)
2657 MESSAGE ( "ComputeAdap avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2662 // Numero de l'iteration
2663 int NumeIter = myIteration->GetNumber();
2664 std::stringstream saux0 ;
2665 saux0 << NumeIter-1 ;
2666 std::string siter = saux0.str() ;
2667 if (NumeIter < 11) { siter = "0" + siter ; }
2669 // A.2. On verifie qu il y a une hypothese (erreur improbable);
2670 const char* nomHypo = myIteration->GetHypoName();
2671 if (std::string(nomHypo) == std::string(""))
2673 SALOME::ExceptionStruct es;
2674 es.type = SALOME::BAD_PARAM;
2675 es.text = "This iteration does not have any associated hypothesis.";
2676 throw SALOME::SALOME_Exception(es);
2679 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
2680 ASSERT(!CORBA::is_nil(myHypo));
2682 // B. L'iteration parent
2683 const char* nomIterationParent = myIteration->GetIterParentName();
2684 HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterationParent];
2685 ASSERT(!CORBA::is_nil(myIterationParent));
2686 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2687 if ( myIterationParent->GetState() == 1 )
2690 int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2693 // GERALD -- QMESSAGE BOX
2694 VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2698 // C. Le sous-répertoire de l'iteration precedente
2699 char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2700 MESSAGE( ". DirComputePa = " << DirComputePa );
2702 // D. Les données de l'adaptation HOMARD
2703 // D.1. Le type de conformite
2704 int ConfType = myCase->GetConfType();
2705 MESSAGE ( ". ConfType = " << ConfType );
2707 // D.1. Le type externe
2708 int ExtType = myCase->GetExtType();
2709 MESSAGE ( ". ExtType = " << ExtType );
2711 // D.3. Le maillage de depart
2712 const char* NomMeshParent = myIterationParent->GetMeshName();
2713 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2714 const char* MeshFileParent = myIterationParent->GetMeshFile();
2715 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2717 // D.4. Le maillage associe a l'iteration
2718 const char* MeshFile = myIteration->GetMeshFile();
2719 MESSAGE ( ". MeshFile = " << MeshFile );
2720 FILE *file = fopen(MeshFile,"r");
2724 if (etatMenage == 0)
2726 SALOME::ExceptionStruct es;
2727 es.type = SALOME::BAD_PARAM;
2728 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2729 es.text = CORBA::string_dup(text.c_str());
2730 throw SALOME::SALOME_Exception(es);
2735 std::string commande = "rm -f " + std::string(MeshFile);
2736 codret = system(commande.c_str());
2739 SALOME::ExceptionStruct es;
2740 es.type = SALOME::BAD_PARAM;
2741 es.text = "The mesh file cannot be deleted.";
2742 throw SALOME::SALOME_Exception(es);
2748 // D.5. Les types de raffinement et de deraffinement
2749 // Les appels corba sont lourds, il vaut mieux les grouper
2750 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2751 ASSERT(ListTypes->length() == 3);
2752 int TypeAdap = (*ListTypes)[0];
2753 int TypeRaff = (*ListTypes)[1];
2754 int TypeDera = (*ListTypes)[2];
2755 // MESSAGE ( ". TypeAdap = " << TypeAdap << ", TypeRaff = " << TypeRaff << ", TypeDera = " << TypeDera );
2757 // E. Texte du fichier de configuration
2758 // E.1. Incontournables du texte
2759 myDriver->TexteAdap(ExtType);
2761 myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2762 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2763 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2765 // E.2. Ajout des informations liees aux zones eventuelles
2766 if ( TypeAdap == 0 )
2767 { DriverTexteZone(myHypo, myDriver) ; }
2769 // E.3. Ajout des informations liees aux champs eventuels
2770 if ( TypeAdap == 1 )
2771 { DriverTexteField(myIteration, myHypo, myDriver) ; }
2773 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2774 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2775 int numberOfGroups = listeGroupes->length();
2776 MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2777 if (numberOfGroups > 0)
2779 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2781 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2782 MESSAGE( "... GroupName = " << GroupName );
2783 myDriver->TexteGroup(GroupName);
2787 // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2788 DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2790 // E.6. Ajout des options avancees
2791 int Pyram = myCase->GetPyram();
2792 MESSAGE ( ". Pyram = " << Pyram );
2793 int NivMax = myHypo->GetNivMax();
2794 MESSAGE ( ". NivMax = " << NivMax );
2795 double DiamMin = myHypo->GetDiamMin() ;
2796 MESSAGE ( ". DiamMin = " << DiamMin );
2797 int AdapInit = myHypo->GetAdapInit();
2798 MESSAGE ( ". AdapInit = " << AdapInit );
2799 int ExtraOutput = myHypo->GetExtraOutput();
2800 MESSAGE ( ". ExtraOutput = " << ExtraOutput );
2801 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, ExtraOutput);
2803 // E.7. Ajout des informations sur le deroulement de l'execution
2804 int MessInfo = myIteration->GetInfoCompute();
2805 MESSAGE ( ". MessInfo = " << MessInfo );
2806 myDriver->TexteInfoCompute(MessInfo);
2810 //=============================================================================
2811 // Calcul d'une iteration : partie spécifique au suivi de frontière CAO
2812 //=============================================================================
2813 CORBA::Long HOMARD_Gen_i::ComputeCAO(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long Option1, CORBA::Long Option2)
2815 MESSAGE ( "ComputeCAO avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2820 // A.2. Le sous-répertoire de l'iteration en cours de traitement
2821 char* DirCompute = myIteration->GetDirName();
2822 // A.3. Le maillage résultat de l'iteration en cours de traitement
2823 char* MeshFile = myIteration->GetMeshFile();
2825 // B. Les données pour FrontTrack
2826 // B.1. Le maillage à modifier
2827 const std::string theInputMedFile = MeshFile;
2828 MESSAGE ( ". theInputMedFile = " << theInputMedFile );
2830 // B.2. Le maillage après modification : fichier identique
2831 const std::string theOutputMedFile = MeshFile ;
2832 MESSAGE ( ". theOutputMedFile = " << theInputMedFile );
2834 // B.3. La liste des fichiers contenant les numéros des noeuds à bouger
2835 std::vector< std::string > theInputNodeFiles ;
2836 MESSAGE ( ". DirCompute = " << DirCompute );
2841 struct dirent *dirp;
2842 dp = opendir(DirCompute);
2843 while ( (dirp = readdir(dp)) != NULL )
2845 std::string file_name(dirp->d_name);
2846 bilan = file_name.find("fr") ;
2847 if ( bilan != string::npos )
2849 std::stringstream filename_total ;
2850 filename_total << DirCompute << "/" << file_name ;
2851 theInputNodeFiles.push_back(filename_total.str()) ;
2856 HANDLE hFind = INVALID_HANDLE_VALUE;
2857 WIN32_FIND_DATA ffd;
2858 hFind = FindFirstFile(DirNameStart, &ffd);
2859 if (INVALID_HANDLE_VALUE != hFind) {
2860 while (FindNextFile(hFind, &ffd) != 0) {
2861 std::string file_name(ffd.cFileName);
2862 bilan = file_name.find("fr") ;
2863 if ( bilan != string::npos )
2865 std::stringstream filename_total ;
2866 filename_total << DirCompute << "/" << file_name ;
2867 theInputNodeFiles.push_back(filename_total.str()) ;
2874 for ( int i = 0; i < icpt; i++ )
2875 { MESSAGE ( ". theInputNodeFiles["<< i << "] = " << theInputNodeFiles[i] ); }
2877 // B.4. Le fichier de la CAO
2878 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2879 std::string BoundaryName = std::string((*ListBoundaryGroupType)[0]);
2880 MESSAGE ( ". BoundaryName = " << BoundaryName );
2881 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
2882 const std::string theXaoFileName = myBoundary->GetDataFile();
2883 MESSAGE ( ". theXaoFileName = " << theXaoFileName );
2885 // B.5. Parallélisme
2886 bool theIsParallel = false;
2888 // C. Lancement des projections
2889 MESSAGE ( ". Lancement des projections" );
2890 FrontTrack* myFrontTrack = new FrontTrack();
2891 myFrontTrack->track(theInputMedFile, theOutputMedFile, theInputNodeFiles, theXaoFileName, theIsParallel);
2893 // D. Transfert des coordonnées modifiées dans le fichier historique de HOMARD
2894 // On lance une exécution spéciale de HOMARD en attendant de savoir le faire avec MEDCoupling
2895 MESSAGE ( ". Transfert des coordonnées" );
2896 codret = ComputeCAObis(myIteration, Option1, Option2) ;
2900 //=============================================================================
2901 //=============================================================================
2902 // Transfert des coordonnées en suivi de frontière CAO
2903 // Option1 >0 : appel depuis python
2904 // <0 : appel depuis GUI
2905 // Option2 : multiple de nombres premiers
2906 // 1 : aucune option
2907 // x2 : publication du maillage dans SMESH
2908 //=============================================================================
2909 CORBA::Long HOMARD_Gen_i::ComputeCAObis(HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long Option1, CORBA::Long Option2)
2911 MESSAGE ( "ComputeCAObis, avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2916 // A.1. Controle de la possibilite d'agir
2917 // A.1.1. Etat de l'iteration
2918 int etat = myIteration->GetState();
2919 MESSAGE ( "etat = "<<etat );
2920 // A.1.2. L'iteration doit être calculee
2923 SALOME::ExceptionStruct es;
2924 es.type = SALOME::BAD_PARAM;
2925 es.text = "This iteration is not computed.";
2926 throw SALOME::SALOME_Exception(es);
2929 // A.2. Numero de l'iteration
2930 // siterp1 : numero de l'iteration a traiter
2931 int NumeIter = myIteration->GetNumber();
2932 std::string siterp1 ;
2933 std::stringstream saux1 ;
2935 siterp1 = saux1.str() ;
2936 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2937 MESSAGE ( "siterp1 = "<<siterp1 );
2940 const char* CaseName = myIteration->GetCaseName();
2941 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[CaseName];
2942 ASSERT(!CORBA::is_nil(myCase));
2944 // A.4. Le sous-répertoire de l'iteration a traiter
2945 char* DirCompute = myIteration->GetDirName();
2946 MESSAGE( ". DirCompute = " << DirCompute );
2948 // C. Le fichier des messages
2949 std::string LogFile = DirCompute ;
2950 LogFile += "/Liste." + siterp1 + ".maj_coords.log" ;
2951 MESSAGE (". LogFile = " << LogFile);
2952 myIteration->SetFileInfo(LogFile.c_str());
2954 // D. On passe dans le répertoire de l'iteration a calculer
2955 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2958 // E. Les données de l'exécution HOMARD
2959 // E.1. L'objet du texte du fichier de configuration
2960 HomardDriver* myDriver = new HomardDriver("", siterp1);
2961 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2963 // E.2. Le maillage associe a l'iteration
2964 const char* NomMesh = myIteration->GetMeshName();
2965 MESSAGE ( ". NomMesh = " << NomMesh );
2966 const char* MeshFile = myIteration->GetMeshFile();
2967 MESSAGE ( ". MeshFile = " << MeshFile );
2969 // E.3. Les données du traitement HOMARD
2971 myDriver->TexteMajCoords( NumeIter ) ;
2973 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2974 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2976 // E.4. Ecriture du texte dans le fichier
2977 MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2979 { myDriver->CreeFichier(); }
2983 int codretexec = 1789 ;
2986 codretexec = myDriver->ExecuteHomard(Option1);
2987 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2990 // G. Gestion des resultats
2993 // G.1. Le fichier des messages, dans tous les cas
2994 const char* NomIteration = myIteration->GetName();
2995 std::string Commentaire = "logmaj_coords" ;
2996 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2997 // G.2 Message d'erreur
2998 if (codretexec != 0)
3000 std::string text = "\n\nSee the file " + LogFile + "\n" ;
3002 SALOME::ExceptionStruct es;
3003 es.type = SALOME::BAD_PARAM;
3004 es.text = CORBA::string_dup(text.c_str());
3005 throw SALOME::SALOME_Exception(es);
3007 // On force le succes pour pouvoir consulter le fichier log
3012 // H. Menage et retour dans le répertoire du cas
3013 if (codret == 0) { delete myDriver; }
3017 //=============================================================================
3018 // Creation d'un nom de sous-répertoire pour l'iteration au sein d'un répertoire parent
3019 // nomrep : nom du répertoire parent
3020 // num : le nom du sous-répertoire est sous la forme 'In', n est >= num
3021 //=============================================================================
3022 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
3024 MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
3025 // On verifie que le répertoire parent existe
3026 int codret = CHDIR(nomrep) ;
3029 SALOME::ExceptionStruct es;
3030 es.type = SALOME::BAD_PARAM;
3031 es.text = "The directory of the case does not exist.";
3032 throw SALOME::SALOME_Exception(es);
3035 std::string nomDirActuel = getenv("PWD") ;
3036 std::string DirName ;
3037 // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un répertoire inconnu
3038 bool a_chercher = true ;
3039 while ( a_chercher )
3041 // On passe dans le répertoire parent
3044 // On recherche un nom sous la forme Iabc, avec abc representant le numero
3046 if ( num < 100 ) { jaux = 2 ; }
3047 else if ( num < 1000 ) { jaux = 3 ; }
3048 else if ( num < 10000 ) { jaux = 4 ; }
3049 else if ( num < 100000 ) { jaux = 5 ; }
3051 std::ostringstream iaux ;
3052 iaux << std::setw(jaux) << std::setfill('0') << num ;
3053 std::ostringstream DirNameA ;
3054 DirNameA << "I" << iaux.str();
3055 // Si on ne pas peut entrer dans le répertoire, on doit verifier
3056 // que c'est bien un probleme d'absence
3057 if ( CHDIR(DirNameA.str().c_str()) != 0 )
3059 bool existe = false ;
3062 struct dirent *dirp;
3063 dp = opendir(nomrep);
3064 while ( (dirp = readdir(dp)) != NULL )
3066 std::string file_name(dirp->d_name);
3068 HANDLE hFind = INVALID_HANDLE_VALUE;
3069 WIN32_FIND_DATA ffd;
3070 hFind = FindFirstFile(nomrep, &ffd);
3071 if (INVALID_HANDLE_VALUE != hFind) {
3072 while (FindNextFile(hFind, &ffd) != 0) {
3073 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
3074 std::string file_name(ffd.cFileName);
3076 if ( file_name == DirNameA.str() ) { existe = true ; }
3085 DirName = DirNameA.str() ;
3086 a_chercher = false ;
3093 MESSAGE ( "==> DirName = " << DirName);
3094 MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
3095 CHDIR(nomDirActuel.c_str());
3096 return CORBA::string_dup( DirName.c_str() );
3098 //=============================================================================
3099 // Calcul d'une iteration : gestion du répertoire de calcul
3100 // Si le sous-répertoire existe :
3101 // etatMenage = 0 : on sort en erreur si le répertoire n'est pas vide
3102 // etatMenage = 1 : on fait le menage du répertoire
3103 // etatMenage = -1 : on ne fait rien
3104 //=============================================================================
3105 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
3107 MESSAGE ( "ComputeDirManagement : répertoires pour le calcul" );
3108 // B.2. Le répertoire du cas
3109 const char* nomDirCase = myCase->GetDirName();
3110 MESSAGE ( ". nomDirCase = " << nomDirCase );
3112 // B.3. Le sous-répertoire de l'iteration a calculer, puis le répertoire complet a creer
3113 // B.3.1. Le nom du sous-répertoire
3114 const char* nomDirIt = myIteration->GetDirNameLoc();
3116 // B.3.2. Le nom complet du sous-répertoire
3117 std::stringstream DirCompute ;
3118 DirCompute << nomDirCase << "/" << nomDirIt;
3119 MESSAGE (". DirCompute = " << DirCompute.str() );
3121 // B.3.3. Si le sous-répertoire n'existe pas, on le cree
3122 if (CHDIR(DirCompute.str().c_str()) != 0)
3125 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
3127 if (_mkdir(DirCompute.str().c_str()) != 0)
3130 // GERALD -- QMESSAGE BOX
3131 std::cerr << "Pb Creation du répertoire DirCompute = " << DirCompute.str() << std::endl;
3132 VERIFICATION("Pb a la creation du répertoire" == 0);
3137 // Le répertoire existe
3138 // On demande de faire le menage de son contenu :
3139 if (etatMenage == 1)
3141 MESSAGE (". Menage du répertoire DirCompute = " << DirCompute.str());
3142 std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
3143 int codret = system(commande.c_str());
3146 // GERALD -- QMESSAGE BOX
3147 std::cerr << ". Menage du répertoire de calcul" << DirCompute.str() << std::endl;
3148 VERIFICATION("Pb au menage du répertoire de calcul" == 0);
3151 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
3154 if (etatMenage == 0)
3158 struct dirent *dirp;
3159 dp = opendir(DirCompute.str().c_str());
3161 while ((dirp = readdir(dp)) != NULL && result )
3163 std::string file_name(dirp->d_name);
3164 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3168 HANDLE hFind = INVALID_HANDLE_VALUE;
3169 WIN32_FIND_DATA ffd;
3170 hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
3172 if (INVALID_HANDLE_VALUE != hFind) {
3173 while (FindNextFile(hFind, &ffd) != 0) {
3174 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
3175 std::string file_name(ffd.cFileName);
3176 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3181 if ( result == false)
3183 SALOME::ExceptionStruct es;
3184 es.type = SALOME::BAD_PARAM;
3185 std::string text = "Directory : " + DirCompute.str() + " is not empty";
3186 es.text = CORBA::string_dup(text.c_str());
3187 throw SALOME::SALOME_Exception(es);
3188 VERIFICATION("Directory is not empty" == 0);
3194 return CORBA::string_dup( DirCompute.str().c_str() );
3196 //=============================================================================
3197 // Calcul d'une iteration : gestion du répertoire de calcul de l'iteration parent
3198 //=============================================================================
3199 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
3201 MESSAGE ( "ComputeDirPaManagement : répertoires pour le calcul" );
3202 // Le répertoire du cas
3203 const char* nomDirCase = myCase->GetDirName();
3204 MESSAGE ( ". nomDirCase = " << nomDirCase );
3206 // Le sous-répertoire de l'iteration precedente
3208 const char* nomIterationParent = myIteration->GetIterParentName();
3209 HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterationParent];
3210 const char* nomDirItPa = myIterationParent->GetDirNameLoc();
3211 std::stringstream DirComputePa ;
3212 DirComputePa << nomDirCase << "/" << nomDirItPa;
3213 MESSAGE( ". nomDirItPa = " << nomDirItPa);
3214 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
3216 return CORBA::string_dup( DirComputePa.str().c_str() );
3218 //=============================================================================
3219 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
3220 //=============================================================================
3221 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3223 MESSAGE ( "... DriverTexteZone" );
3224 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3225 int numberOfZonesx2 = ListZone->length();
3228 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3230 std::string ZoneName = std::string((*ListZone)[iaux]);
3231 MESSAGE ( "... ZoneName = " << ZoneName);
3232 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
3233 ASSERT(!CORBA::is_nil(myZone));
3235 int ZoneType = myZone->GetType();
3236 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
3237 int TypeUse = atoi( TypeUsestr.c_str() );
3238 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
3239 NumZone = iaux/2 + 1 ;
3240 HOMARD::double_array* zone = myZone->GetCoords();
3241 if ( ZoneType == 2 || ( ZoneType>=11 && ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
3242 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
3243 else if ( ZoneType == 4 ) // Cas d une sphere
3244 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
3245 else if ( ZoneType == 5 || ( ZoneType>=31 && ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
3246 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
3247 else if ( ZoneType == 7 || ( ZoneType>=61 && ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
3248 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
3249 else { VERIFICATION("ZoneType est incorrect." == 0) ; }
3254 //=============================================================================
3255 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
3256 //=============================================================================
3257 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3259 MESSAGE ( "... DriverTexteField" );
3260 // Le fichier du champ
3261 char* FieldFile = myIteration->GetFieldFile();
3262 MESSAGE ( ". FieldFile = " << FieldFile );
3263 if (strlen(FieldFile) == 0)
3265 // GERALD -- QMESSAGE BOX
3266 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
3267 VERIFICATION("The file for the field is not given." == 0);
3269 // Les caracteristiques d'instants du champ de pilotage
3270 int TimeStep = myIteration->GetTimeStep();
3271 MESSAGE( ". TimeStep = " << TimeStep );
3272 int Rank = myIteration->GetRank();
3273 MESSAGE( ". Rank = " << Rank );
3274 // Les informations sur les champs
3275 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
3277 const char* FieldName = aInfosHypo->FieldName;
3279 int TypeThR = aInfosHypo->TypeThR;
3280 double ThreshR = aInfosHypo->ThreshR;
3281 int TypeThC = aInfosHypo->TypeThC;
3282 double ThreshC = aInfosHypo->ThreshC;
3283 // Saut entre mailles ou non ?
3284 int UsField = aInfosHypo->UsField;
3285 MESSAGE( ". UsField = " << UsField );
3286 // L'usage des composantes
3287 int UsCmpI = aInfosHypo->UsCmpI;
3288 MESSAGE( ". UsCmpI = " << UsCmpI );
3290 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
3293 HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
3294 int numberOfCompos = mescompo->length();
3295 MESSAGE( ". numberOfCompos = " << numberOfCompos );
3296 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
3298 std::string nomCompo = std::string((*mescompo)[NumeComp]);
3299 MESSAGE( "... nomCompo = " << nomCompo );
3300 myDriver->TexteCompo(NumeComp, nomCompo);
3304 //=============================================================================
3305 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
3306 // On ecrit dans l'ordre :
3307 // 1. la definition des frontieres
3308 // 2. les liens avec les groupes
3309 // 3. un entier resumant le type de comportement pour les frontieres
3310 //=============================================================================
3311 int HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
3313 MESSAGE ( "... DriverTexteBoundary" );
3314 // 1. Recuperation des frontieres
3315 std::list<std::string> ListeBoundaryTraitees ;
3316 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3317 int numberOfitems = ListBoundaryGroupType->length();
3318 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
3319 int BoundaryOption = 1 ;
3320 // 2. Parcours des frontieres pour ecrire leur description
3321 int NumBoundaryAnalytical = 0 ;
3322 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3324 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3325 MESSAGE ( "... BoundaryName = " << BoundaryName);
3326 // 2.1. La frontiere a-t-elle deja ete ecrite ?
3327 // Cela arrive quand elle est liee a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
3329 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3330 while (it != ListeBoundaryTraitees.end())
3332 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3333 if ( BoundaryName == *it ) { A_faire = 0 ; }
3336 // 2.2. Ecriture de la frontiere
3339 // 2.2.1. Caracteristiques de la frontiere
3340 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
3341 ASSERT(!CORBA::is_nil(myBoundary));
3342 int BoundaryType = myBoundary->GetType();
3343 MESSAGE ( "... BoundaryType = " << BoundaryType );
3344 // 2.2.2. Ecriture selon le type
3345 // 2.2.2.1. Cas d une frontiere CAO
3346 if (BoundaryType == -1)
3348 // const char* CAOFile = myBoundary->GetDataFile() ;
3349 // MESSAGE ( ". CAOFile = " << CAOFile );
3350 if ( BoundaryOption % 5 != 0 ) { BoundaryOption = BoundaryOption*5 ; }
3352 // 2.2.2.2. Cas d une frontiere discrete
3353 else if (BoundaryType == 0)
3355 const char* MeshName = myBoundary->GetMeshName() ;
3356 MESSAGE ( ". MeshName = " << MeshName );
3357 const char* MeshFile = myBoundary->GetDataFile() ;
3358 MESSAGE ( ". MeshFile = " << MeshFile );
3359 myDriver->TexteBoundaryDi( MeshName, MeshFile);
3360 if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
3362 // 2.2.2.3. Cas d une frontiere analytique
3365 NumBoundaryAnalytical++ ;
3366 HOMARD::double_array* coor = myBoundary->GetCoords();
3367 if (BoundaryType == 1) // Cas d un cylindre
3369 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3370 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3372 else if (BoundaryType == 2) // Cas d une sphere
3374 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
3375 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3377 else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
3379 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3380 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3382 else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
3384 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3385 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3387 else if (BoundaryType == 5) // Cas d un tore
3389 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3390 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3393 // 2.2.3. Memorisation du traitement
3394 ListeBoundaryTraitees.push_back( BoundaryName );
3397 // 3. Parcours des frontieres pour ecrire les liens avec les groupes
3398 NumBoundaryAnalytical = 0 ;
3399 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3401 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3402 MESSAGE ( "... BoundaryName = " << BoundaryName);
3403 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
3404 ASSERT(!CORBA::is_nil(myBoundary));
3405 int BoundaryType = myBoundary->GetType();
3406 MESSAGE ( "... BoundaryType = " << BoundaryType );
3407 // 3.1. Recuperation du nom du groupe
3408 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
3409 MESSAGE ( "... GroupName = " << GroupName);
3410 // 3.2. Cas d une frontiere CAO
3411 if ( BoundaryType == -1 )
3413 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryCAOGr ( GroupName ) ; }
3415 // 3.3. Cas d une frontiere discrete
3416 else if ( BoundaryType == 0 )
3418 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
3420 // 3.4. Cas d une frontiere analytique
3423 NumBoundaryAnalytical++ ;
3424 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
3427 // 4. Ecriture de l'option finale
3428 myDriver->TexteBoundaryOption(BoundaryOption);
3430 return BoundaryOption ;
3432 //=============================================================================
3433 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3434 //=============================================================================
3435 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3437 MESSAGE ( "... DriverTexteFieldInterp" );
3438 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3439 MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3440 if (TypeFieldInterp != 0)
3442 // Le fichier des champs
3443 char* FieldFile = myIteration->GetFieldFile();
3444 MESSAGE ( ". FieldFile = " << FieldFile );
3445 if (strlen(FieldFile) == 0)
3447 // GERALD -- QMESSAGE BOX
3448 VERIFICATION("The file for the field is not given." == 0);
3451 const char* MeshFile = myIteration->GetMeshFile();
3452 myDriver->TexteFieldInterp(FieldFile, MeshFile);
3455 // Interpolation de tous les champs
3456 if ( TypeFieldInterp == 1 )
3458 myDriver->TexteFieldInterpAll();
3460 // Interpolation de certains champs
3461 else if (TypeFieldInterp == 2)
3463 // Les champs et leurs instants pour l'iteration
3464 HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3465 int numberOfFieldsx3 = ListFieldTSR->length();
3466 MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3467 // Les champs pour l'hypothese
3468 HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3469 int numberOfFieldsx2 = ListField->length();
3470 MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3471 // On parcourt tous les champs de l'hypothese
3473 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3476 std::string FieldName = std::string((*ListField)[iaux]) ;
3477 // Le type d'interpolation
3478 std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3479 MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3480 // On cherche ?? savoir si des instants ont ??t?? pr??cis??s pour cette it??ration
3482 for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3485 std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3486 MESSAGE( "..... FieldName2 = " << FieldName2 );
3487 // Quand c'est le bon champ, on ecrit le pas de temps
3488 if ( FieldName == FieldName2 )
3492 std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3493 // Le numero d'ordre
3494 std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3495 MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3497 int TimeStep = atoi( TimeStepstr.c_str() );
3498 int Rank = atoi( Rankstr.c_str() );
3499 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3503 // Si aucun instant n'a été défini
3507 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3515 //===========================================================================
3516 //===========================================================================
3519 //===========================================================================
3520 //===========================================================================
3522 //===========================================================================
3523 //===========================================================================
3524 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::SObject_ptr theSObject,
3525 CORBA::Object_ptr theObject,
3526 const char* theName)
3528 MESSAGE("PublishInStudy pour " << theName);
3529 SALOMEDS::SObject_var aResultSO;
3530 if (CORBA::is_nil(myStudy))
3532 SALOME::ExceptionStruct es;
3533 es.type = SALOME::BAD_PARAM;
3534 es.text = "Invalid study context";
3535 throw SALOME::SALOME_Exception(es);
3539 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3540 // Rq : Iteration est publiee ailleurs
3541 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3542 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
3543 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3544 HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3545 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3549 // Controle de la non publication d'un objet de meme nom
3550 if ( (!aBoundary->_is_nil()) || (!aHypo->_is_nil()) || (!aYACS->_is_nil()) || (!aZone->_is_nil()) )
3552 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(theName, ComponentDataType());
3553 if (listSO->length() >= 1)
3555 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3556 aResultSO = listSO[0];
3557 return aResultSO._retn();
3561 // Caracteristiques de l'etude
3562 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
3563 aStudyBuilder->NewCommand();
3564 if(!aBoundary->_is_nil())
3565 aResultSO = PublishBoundaryInStudy(aStudyBuilder, aBoundary, theName);
3566 else if(!aCase->_is_nil())
3567 aResultSO = PublishCaseInStudy(aStudyBuilder, aCase, theName);
3568 else if(!aHypo->_is_nil())
3569 aResultSO = PublishHypotheseInStudy(aStudyBuilder, aHypo, theName);
3570 else if(!aYACS->_is_nil())
3571 aResultSO = PublishYACSInStudy(aStudyBuilder, aYACS, theName);
3572 else if(!aZone->_is_nil())
3573 aResultSO = PublishZoneInStudy(aStudyBuilder, aZone, theName);
3575 aStudyBuilder->CommitCommand();
3577 return aResultSO._retn();
3579 //=============================================================================
3580 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy( SALOMEDS::StudyBuilder_var aStudyBuilder,
3581 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3583 MESSAGE("PublishBoundaryStudy pour "<<theName);
3584 SALOMEDS::SObject_var aResultSO;
3586 // Caracteristique de la Boundary
3587 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[theName];
3589 // On recupere le module pere dans l etude
3590 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3591 if (theFatherHomard->_is_nil())
3593 MESSAGE("theFatherHomard->_is_nil()");
3594 return aResultSO._retn();
3597 // On ajoute la categorie des boundarys dans l etude si necessaire
3598 if ( _tag_boun == 0 )
3601 _tag_boun = _tag_gene ;
3603 MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3604 SALOMEDS::SObject_var aSObject;
3605 if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3607 MESSAGE("Ajout de la categorie des boundarys");
3608 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3609 PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3611 else { MESSAGE("La categorie des boundarys existe deja."); }
3613 CORBA::Long BoundaryType = myBoundary->GetType();
3614 // MESSAGE("BoundaryType : "<<BoundaryType);
3617 switch (BoundaryType)
3620 { value = "BoundaryDiHomard" ;
3621 icone = "mesh_tree_mesh.png" ;
3625 { value = "BoundaryAnHomard" ;
3626 icone = "cylinderpointvector_2.png" ;
3630 { value = "BoundaryAnHomard" ;
3631 icone = "spherepoint_2.png" ;
3635 { value = "BoundaryAnHomard" ;
3636 icone = "conepointvector.png" ;
3640 { value = "BoundaryAnHomard" ;
3641 icone = "conedxyz.png" ;
3645 { value = "BoundaryAnHomard" ;
3646 icone = "toruspointvector.png" ;
3650 aResultSO = aStudyBuilder->NewObject(aSObject);
3651 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3652 return aResultSO._retn();
3654 //=============================================================================
3655 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3656 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3658 MESSAGE("PublishCaseInStudy pour "<<theName);
3659 SALOMEDS::SObject_var aResultSO;
3661 if (CORBA::is_nil(theObject)) {
3662 MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3663 return aResultSO._retn();
3665 if (myStudy->_is_nil()) {
3666 MESSAGE("HOMARD_Gen_i::myStudy->_is_nil()");
3667 return aResultSO._retn();
3670 // On recupere le module pere dans l etude
3671 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3672 if (theFatherHomard->_is_nil())
3674 MESSAGE("theFatherHomard->_is_nil()");
3675 return aResultSO._retn();
3679 MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3680 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3681 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3682 _orb->object_to_string(theObject) ) ;
3684 return aResultSO._retn();
3686 //=============================================================================
3687 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3688 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3690 MESSAGE("PublishHypotheseInStudy pour "<<theName);
3691 SALOMEDS::SObject_var aResultSO;
3693 // On recupere le module pere dans l etude
3694 // On ajoute la categorie des hypotheses dans l etude si necessaire
3695 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3696 if (theFatherHomard->_is_nil())
3698 MESSAGE("theFatherHomard->_is_nil()");
3699 return aResultSO._retn();
3702 // On ajoute la categorie des hypotheses dans l etude si necessaire
3703 SALOMEDS::SObject_var aSObject;
3704 if ( _tag_hypo == 0 )
3707 _tag_hypo = _tag_gene ;
3709 MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3710 if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3712 MESSAGE("Ajout de la categorie des hypotheses");
3713 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3714 PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3716 else { MESSAGE("La categorie des hypotheses existe deja."); }
3718 // Creation du resultat dans l'etude
3719 aResultSO = aStudyBuilder->NewObject(aSObject);
3720 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3722 return aResultSO._retn();
3724 //=============================================================================
3725 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3726 HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3728 MESSAGE("PublishYACSInStudy pour "<<theName);
3729 SALOMEDS::SObject_var aResultSO;
3731 // On recupere le module pere dans l etude
3732 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3733 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3734 if (theFatherHomard->_is_nil())
3736 MESSAGE("theFatherHomard->_is_nil()");
3737 return aResultSO._retn();
3739 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3740 if ( _tag_yacs == 0 )
3743 _tag_yacs = _tag_gene ;
3745 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3746 SALOMEDS::SObject_var aSObject;
3747 if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3749 MESSAGE("Ajout de la categorie des schemas YACS");
3750 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3751 PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3753 else { MESSAGE("La categorie des schemas YACS existe deja."); }
3755 // Creation du resultat dans l'etude
3756 aResultSO = aStudyBuilder->NewObject(aSObject);
3757 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3759 return aResultSO._retn();
3762 //=============================================================================
3763 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3764 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3766 MESSAGE("PublishZoneStudy pour "<<theName);
3767 SALOMEDS::SObject_var aResultSO;
3768 if (CORBA::is_nil(theObject))
3770 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3771 return aResultSO._retn();
3773 if (myStudy->_is_nil())
3775 MESSAGE("PublishZoneInStudy : myStudy->_is_nil()");
3776 return aResultSO._retn();
3778 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3779 if (theFatherHomard->_is_nil())
3781 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3782 return aResultSO._retn();
3785 // Caracteristique de la zone
3786 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[theName];
3787 CORBA::Long ZoneType = myZone->GetType();
3789 // On ajoute la categorie des zones dans l etude si necessaire
3790 if ( _tag_zone == 0 )
3793 _tag_zone = _tag_gene ;
3795 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3796 SALOMEDS::SObject_var aSObject;
3797 if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3799 MESSAGE("Ajout de la categorie des zones");
3800 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3801 PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3803 else { MESSAGE("La categorie des zones existe deja."); }
3805 aResultSO = aStudyBuilder->NewObject(aSObject);
3814 { icone = "boxdxy_2.png" ;
3818 { icone = "boxdxyz_2.png" ;
3826 { icone = "disk_2.png" ;
3830 { icone = "spherepoint_2.png" ;
3834 { icone = "cylinderpointvector_2.png" ;
3842 { icone = "diskwithhole_2.png" ;
3846 { icone = "pipe_2.png" ;
3850 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3852 return aResultSO._retn();
3854 //===========================================================================
3855 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3856 SALOMEDS::SObject_var aResultSO,
3857 const char* name, const char* comment, const char* icone, const char* ior)
3859 MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3860 // MESSAGE("icone = "<<icone);
3861 // MESSAGE("ior = "<<ior);
3862 SALOMEDS::GenericAttribute_var anAttr ;
3866 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3867 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3868 aNameAttrib->SetValue(name);
3871 // Ajout du commentaire
3872 if ( comment != NULL )
3874 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3875 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3876 aCommentAttrib->SetValue(comment);
3880 if ( icone != NULL )
3882 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3883 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3884 aPixmap->SetPixMap(icone);
3890 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3891 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3892 anIOR->SetValue(ior);
3896 //=====================================================================================
3897 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3899 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3901 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[CaseName];
3902 ASSERT(!CORBA::is_nil(myCase));
3903 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3904 ASSERT(!CORBA::is_nil(aCaseSO));
3906 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
3907 ASSERT(!CORBA::is_nil(myBoundary));
3908 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3909 ASSERT(!CORBA::is_nil(aBoundarySO));
3911 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
3913 aStudyBuilder->NewCommand();
3915 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3916 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3917 // aStudyBuilder->RemoveReference(aSubSO);
3919 aStudyBuilder->CommitCommand();
3922 //=====================================================================================
3923 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3925 MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3927 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
3928 ASSERT(!CORBA::is_nil(myYACS));
3929 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3930 ASSERT(!CORBA::is_nil(aYACSSO));
3932 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[CaseName];
3933 ASSERT(!CORBA::is_nil(myCase));
3934 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3935 ASSERT(!CORBA::is_nil(aCaseSO));
3937 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
3939 aStudyBuilder->NewCommand();
3941 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3942 aStudyBuilder->Addreference(aSubSO, aCaseSO);
3944 aStudyBuilder->CommitCommand();
3947 //=============================================================================
3948 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3949 // Option = 0 : fichier issu d'une importation
3950 // Option = 1 : fichier issu d'une execution HOMARD
3952 MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3953 if (CORBA::is_nil(myStudy))
3955 SALOME::ExceptionStruct es;
3956 es.type = SALOME::BAD_PARAM;
3957 es.text = "Invalid study context";
3958 throw SALOME::SALOME_Exception(es);
3962 // Le module SMESH est-il actif ?
3963 SALOMEDS::SObject_var aSmeshSO = myStudy->FindComponent("SMESH");
3965 if (!CORBA::is_nil(aSmeshSO))
3967 // On verifie que le fichier n est pas deja publie
3968 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aSmeshSO);
3969 for (; aIter->More(); aIter->Next())
3971 SALOMEDS::SObject_var aSO = aIter->Value();
3972 SALOMEDS::GenericAttribute_var aGAttr;
3973 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3975 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3976 CORBA::String_var value=anAttr->Value();
3977 if (strcmp((const char*)value,NomFich) == 0)
3979 MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3980 // Pour un fichier importe, on ne republie pas
3981 if ( Option == 0 ) { return; }
3982 // Pour un fichier calcule, on commence par faire la depublication
3985 MESSAGE ( "PublishResultInSmesh : depublication" );
3986 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3987 CORBA::String_var value2=anAttr2->Value();
3988 std::string MeshName = string(value2) ;
3989 MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3990 DeleteResultInSmesh(NomFich, MeshName) ;
3997 // On enregistre le fichier
3998 MESSAGE( "Enregistrement du fichier");
3999 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
4000 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
4001 ASSERT(!CORBA::is_nil(aSmeshEngine));
4002 aSmeshEngine->UpdateStudy();
4003 SMESH::DriverMED_ReadStatus theStatus;
4004 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
4006 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
4007 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
4008 for (int i = 0; i < mesMaillages->length(); i++)
4010 MESSAGE( ". Mise a jour des attributs du maillage");
4011 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
4012 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
4013 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4014 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
4015 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
4016 anAttr->SetValue(NomFich);
4017 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
4018 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
4020 if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
4021 else { icone = "mesh_tree_mesh.png" ; }
4022 anAttr2->SetPixMap( icone );
4026 //=============================================================================
4027 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
4029 MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
4030 if (CORBA::is_nil(myStudy))
4032 SALOME::ExceptionStruct es;
4033 es.type = SALOME::BAD_PARAM;
4034 es.text = "Invalid study context";
4035 throw SALOME::SALOME_Exception(es);
4039 // Le module SMESH est-il actif ?
4040 SALOMEDS::SObject_var aSmeshSO = myStudy->FindComponent("SMESH");
4042 if (CORBA::is_nil(aSmeshSO))
4046 // On verifie que le fichier est deja publie
4047 SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
4048 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aSmeshSO);
4049 for (; aIter->More(); aIter->Next())
4051 SALOMEDS::SObject_var aSO = aIter->Value();
4052 SALOMEDS::GenericAttribute_var aGAttr;
4053 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
4055 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
4056 CORBA::String_var value=anAttr->Value();
4057 if (strcmp((const char*)value,NomFich.c_str()) == 0)
4059 if (aSO->FindAttribute(aGAttr,"AttributeName"))
4061 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
4062 CORBA::String_var value2=anAttr2->Value();
4063 if (strcmp((const char*)value2,MeshName.c_str()) == 0)
4065 myBuilder->RemoveObjectWithChildren( aSO ) ;
4073 //=============================================================================
4074 void HOMARD_Gen_i::PublishMeshIterInSmesh(const char* NomIter)
4076 MESSAGE( "PublishMeshIterInSmesh " << NomIter);
4077 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIter];
4079 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
4080 if (CORBA::is_nil(myIteration))
4082 SALOME::ExceptionStruct es;
4083 es.type = SALOME::BAD_PARAM;
4084 es.text = "Invalid iterationStudy Object";
4085 throw SALOME::SALOME_Exception(es);
4088 const char* MeshFile = myIteration->GetMeshFile() ;
4089 const char* MeshName = myIteration->GetMeshName() ;
4090 CORBA::Long Option = -1 ;
4091 int etat = myIteration->GetState();
4092 // Iteration initiale
4093 if ( etat <= 0 ) { Option = 0 ; }
4094 // ou iteration calculee
4095 else if ( etat == 2 ) { Option = 1 ; }
4096 // Publication effective apres menage eventuel
4099 DeleteResultInSmesh(MeshFile, MeshName) ;
4100 PublishResultInSmesh(MeshFile, Option) ;
4104 //=============================================================================
4105 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
4107 // MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
4108 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIter];
4110 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
4111 if (CORBA::is_nil(myIteration))
4113 SALOME::ExceptionStruct es;
4114 es.type = SALOME::BAD_PARAM;
4115 es.text = "Invalid iterationStudy Object";
4116 throw SALOME::SALOME_Exception(es);
4120 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4122 aStudyBuilder->NewCommand();
4124 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
4125 // Pour les fichiers med, on affiche une icone de maillage
4126 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
4127 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
4129 std::string ior = " " ;
4130 if ( Commentaire[0] == 'M' )
4131 { icone = "med.png" ; }
4133 { icone = "texte_2.png" ; }
4134 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
4136 aStudyBuilder->CommitCommand();
4139 //=============================================================================
4140 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
4142 // MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
4143 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
4145 SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
4146 if (CORBA::is_nil(myYACS))
4148 SALOME::ExceptionStruct es;
4149 es.type = SALOME::BAD_PARAM;
4150 es.text = "Invalid YACSStudy Object";
4151 throw SALOME::SALOME_Exception(es);
4155 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4157 aStudyBuilder->NewCommand();
4159 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
4160 std::string icone = "texte_2.png" ;
4161 std::string ior = " " ;
4162 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
4164 aStudyBuilder->CommitCommand();
4167 //=============================================================================
4168 //=============================================================================
4170 //=============================================================================
4171 //=============================================================================
4172 //=============================================================================
4173 // Creation d'un schema YACS
4174 // nomCas : nom du cas a traiter
4175 // FileName : nom du fichier contenant le script de lancement du calcul
4176 // DirName : le répertoire de lancement des calculs du schéma
4177 //=============================================================================
4178 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
4180 INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
4181 INFOS ( ". nomCas : " << nomCas);
4182 INFOS ( ". ScriptFile : " << ScriptFile);
4183 INFOS ( ". DirName : " << DirName);
4184 INFOS ( ". MeshFile : " << MeshFile);
4186 // A. Controle du nom :
4187 if ((myStudyContext._mesYACSs).find(nomYACS) != (myStudyContext._mesYACSs).end())
4189 SALOME::ExceptionStruct es;
4190 es.type = SALOME::BAD_PARAM;
4191 es.text = "This schema YACS has already been defined.";
4192 throw SALOME::SALOME_Exception(es);
4196 // B. Creation de l'objet
4197 HOMARD::HOMARD_YACS_var myYACS = newYACS();
4198 if (CORBA::is_nil(myYACS))
4200 SALOME::ExceptionStruct es;
4201 es.type = SALOME::BAD_PARAM;
4202 es.text = "Unable to create the schema YACS";
4203 throw SALOME::SALOME_Exception(es);
4206 myYACS->SetName( nomYACS ) ;
4208 // C. Enregistrement
4209 myStudyContext._mesYACSs[nomYACS] = myYACS;
4211 SALOMEDS::SObject_var aSO;
4212 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myYACS, nomYACS);
4214 PublishCaseUnderYACS(nomYACS, nomCas);
4216 // D. Caracterisation
4218 myYACS->SetDirName( DirName ) ;
4219 myYACS->SetMeshFile( MeshFile ) ;
4220 myYACS->SetScriptFile( ScriptFile ) ;
4221 myYACS->SetCaseName( nomCas ) ;
4224 // D.2.1. Type constant
4225 myYACS->SetType( 1 ) ;
4226 // D.2.2. Convergence
4227 defaut_i = GetYACSMaxIter() ;
4228 myYACS->SetMaxIter( defaut_i ) ;
4229 defaut_i = GetYACSMaxNode() ;
4230 myYACS->SetMaxNode( defaut_i ) ;
4231 defaut_i = GetYACSMaxElem() ;
4232 myYACS->SetMaxElem( defaut_i ) ;
4233 // D.3. Fichier de sauvegarde dans le répertoire du cas
4234 HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
4235 std::string dirnamecase = caseyacs->GetDirName() ;
4236 std::string XMLFile ;
4237 XMLFile = dirnamecase + "/schema.xml" ;
4238 myYACS->SetXMLFile( XMLFile.c_str() ) ;
4240 return HOMARD::HOMARD_YACS::_duplicate(myYACS);
4242 //=============================================================================
4243 // Ecriture d'un schema YACS
4244 //=============================================================================
4245 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
4247 INFOS ( "YACSWrite : Ecriture de " << nomYACS );
4248 // Le répertoire du cas
4249 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
4250 ASSERT(!CORBA::is_nil(myYACS));
4251 // Le nom du fichier du schema
4252 std::string XMLFile ;
4253 XMLFile = myYACS->GetXMLFile() ;
4255 int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
4259 //=============================================================================
4260 // Ecriture d'un schema YACS sur un fichier donne
4261 //=============================================================================
4262 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
4264 INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
4271 HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
4272 ASSERT(!CORBA::is_nil(myYACS));
4273 // B.2. Les caracteristiques
4274 std::string DirName = myYACS->GetDirName() ;
4275 std::string MeshFile = myYACS->GetMeshFile() ;
4276 std::string ScriptFile = myYACS->GetScriptFile() ;
4277 // B.3. Les caracteristiques de convergence
4278 int MaxIter = myYACS->GetMaxIter() ;
4279 int MaxNode = myYACS->GetMaxNode() ;
4280 int MaxElem = myYACS->GetMaxElem() ;
4284 const char* nomCas = myYACS->GetCaseName();
4285 HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
4286 ASSERT(!CORBA::is_nil(myCase));
4287 // C.2. Les instructions python associees au cas
4288 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4289 std::string pythonCas = dumpCorbaCase.in();
4290 MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
4292 // D. Les iterations
4293 // D.1. L'iteration initiale
4294 HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
4295 std::string Iter0Name = myCase->GetIter0Name() ;
4296 MESSAGE (". Iter0Name = " << Iter0Name);
4297 std::string MeshName = Iter0->GetMeshName();
4298 MESSAGE (". MeshName = " << MeshName);
4299 // D.2. L'iteration numero 1
4300 HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
4301 int numberOfIter = maListe->length();
4302 if ( numberOfIter > 1 )
4304 MESSAGE (". numberOfIter = " << numberOfIter);
4305 SALOME::ExceptionStruct es ;
4306 es.type = SALOME::BAD_PARAM;
4307 std::string text = "Une seule iteration est permise." ;
4308 es.text = CORBA::string_dup(text.c_str());
4309 throw SALOME::SALOME_Exception(es);
4312 std::string Iter1Name = std::string((*maListe)[0]);
4313 MESSAGE ("... Iter1Name = " << Iter1Name);
4314 HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
4315 // D.3. Les instructions python associees a l'iteration
4316 CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
4317 std::string pythonIter = dumpCorbaIter.in();
4318 MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
4320 // E. L'hypothese pour passer de l'iteration initiale a la suivante
4321 // E.1. La structure
4322 std::string nomHypo = Iter1->GetHypoName();
4323 MESSAGE (". nomHypo = " << nomHypo);
4324 HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
4325 ASSERT(!CORBA::is_nil(myHypo));
4326 // E.2. Les caracteristiques de l'adaptation
4327 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
4328 ASSERT(ListTypes->length() == 3);
4329 int TypeAdap = (*ListTypes)[0];
4330 // int TypeRaff = (*ListTypes)[1];
4331 // int TypeDera = (*ListTypes)[2];
4332 // E.3. Les instructions python associees a l'hypothese
4333 CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
4334 std::string pythonHypo = dumpCorbaHypo.in();
4335 MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
4337 // F. Le fichier du schema de reference
4338 // HOMARD_ROOT_DIR : répertoire ou se trouve le module HOMARD
4339 std::string XMLFile_base ;
4340 if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
4343 SALOME::ExceptionStruct es ;
4344 es.type = SALOME::BAD_PARAM;
4345 std::string text = "HOMARD_ROOT_DIR est inconnu." ;
4346 es.text = CORBA::string_dup(text.c_str());
4347 throw SALOME::SALOME_Exception(es);
4350 XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
4352 MESSAGE("XMLFile_base ="<<XMLFile_base);
4354 // G. Lecture du schema de reference et insertion des données propres au fil de la rencontre des mots-cles
4355 YACSDriver* myDriver = new YACSDriver(XMLFile, DirName);
4356 std::ifstream fichier( XMLFile_base.c_str() );
4357 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
4359 // G.1. Lecture du schema de reference et insertion des données propres au fil de la rencontre des mots-cles
4360 std::string ligne; // variable contenant chaque ligne lue
4361 std::string mot_cle;
4362 while ( std::getline( fichier, ligne ) )
4364 // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
4365 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
4366 ligne_bis >> mot_cle ;
4367 // G.1.2. Le maillage initial
4368 if ( mot_cle == "DataInit_MeshFile" )
4369 { myDriver->Texte_DataInit_MeshFile(MeshFile); }
4370 // G.1.3. Le script de lancement
4371 else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
4372 { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
4373 // G.1.4. Les options du cas
4374 else if ( mot_cle == "Iter_1_Case_Options" )
4375 { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
4376 // G.1.5. Execution de HOMARD : le répertoire du cas
4377 else if ( mot_cle == "HOMARD_Exec_DirName" )
4378 { myDriver->Texte_HOMARD_Exec_DirName(); }
4379 // G.1.6. Execution de HOMARD : le nom du maillage
4380 else if ( mot_cle == "HOMARD_Exec_MeshName" )
4382 myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
4383 std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
4384 myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
4386 // G.1.7. Execution de HOMARD : les options de l'hypothese
4387 else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
4388 { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ; }
4389 // G.1.8. Execution de HOMARD : les options de l'iteration
4390 else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
4391 { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ; }
4392 // G.1.9. a. Creation eventuelles des zones et frontieres
4394 else if ( mot_cle == "Iter_1" )
4396 std::string texte_control = "" ;
4397 if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
4398 texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
4399 texte_control += myDriver->Texte_Iter_1_control() ;
4400 myDriver->TexteAdd(texte_control);
4402 // G.1.10. Les tests de convergence
4403 else if ( mot_cle == "Analyse_Test_Convergence" )
4404 { myDriver->TexteAnalyse_Test_Convergence(MaxIter, MaxNode, MaxElem); }
4405 // G.1.11. Les parametres
4406 else if ( mot_cle == "PARAMETRES" )
4407 { myDriver->TexteAddParametres(); }
4408 // G.1.n. La ligne est recopiee telle quelle
4409 else { myDriver->TexteAdd(ligne); }
4411 // G.2. Ecriture du texte dans le fichier
4413 { myDriver->CreeFichier(); }
4417 SALOME::ExceptionStruct es;
4418 es.type = SALOME::BAD_PARAM;
4419 std::string text = "The reference file for the YACS schema cannot be read." ;
4420 es.text = CORBA::string_dup(text.c_str());
4421 throw SALOME::SALOME_Exception(es);
4426 // H. Publication du fichier dans l'arbre
4428 std::string Commentaire = "xml" ;
4429 PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
4433 //=============================================================================
4434 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
4435 //=============================================================================
4436 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
4438 MESSAGE ( "YACSDriverTexteZone" );
4439 // A. Les zones associees a cette hypothese
4440 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
4441 int numberOfZonesx2 = ListZone->length();
4443 // B. Parcours des zones
4444 std::string texte_control ;
4445 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
4447 // 1. Reperage de la zone
4448 std::string ZoneName = std::string((*ListZone)[iaux]);
4449 MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
4450 HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
4451 ASSERT(!CORBA::is_nil(myZone));
4452 // 2. Les instructions python associees a la zone
4453 // La premiere ligne est un commentaire a eliminer
4454 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4455 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4456 std::string pythonStructure_0 = dumpCorbaZone.in();
4457 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4458 std::istringstream tout (pythonStructure_0) ;
4460 std::string pythonStructure ;
4461 while ( std::getline( tout, ligne ) )
4462 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4463 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4464 // 3. Decodage du nom du service
4465 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4466 MESSAGE ( "... methode = " << methode);
4467 // 4. Mise en place des instructions
4468 int ZoneType = myZone->GetType();
4469 MESSAGE ( "... ZoneType = " << ZoneType);
4470 std::string texte_control_0 ;
4471 texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
4472 texte_control += texte_control_0 ;
4477 return texte_control ;
4479 //=============================================================================
4480 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4481 //=============================================================================
4482 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4484 MESSAGE ( "YACSDriverTexteBoundary" );
4485 // A. Les frontieres associees au cas
4486 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4487 int numberOfitems = ListBoundaryGroupType->length();
4489 // B. Parcours des frontieres
4490 std::string texte_control ;
4491 std::list<std::string> ListeBoundaryTraitees ;
4492 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4494 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4495 MESSAGE ( "... BoundaryName = " << BoundaryName);
4496 // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4497 // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4499 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4500 while (it != ListeBoundaryTraitees.end())
4502 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4503 if ( BoundaryName == *it ) { A_faire = 0 ; }
4508 // 1. Caracteristiques de la frontiere
4509 HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
4510 ASSERT(!CORBA::is_nil(myBoundary));
4511 // 2. Les instructions python associees a la frontiere
4512 // La premiere ligne est un commentaire a eliminer
4513 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4514 CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4515 std::string pythonStructure_0 = dumpCorbaBoundary.in();
4516 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4517 std::istringstream tout (pythonStructure_0) ;
4519 std::string pythonStructure ;
4520 while ( std::getline( tout, ligne ) )
4521 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4522 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4523 // 3. Decodage du nom du service
4524 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4525 MESSAGE ( "... methode = " << methode);
4526 // 4. Mise en place des instructions
4527 int BoundaryType = myBoundary->GetType();
4528 MESSAGE ( "... BoundaryType = " << BoundaryType);
4529 const char* MeshName ;
4530 const char* DataFile ;
4531 if (BoundaryType == -1)
4533 DataFile = myBoundary->GetDataFile() ;
4534 MESSAGE ( ". CAOFile = " << DataFile );
4536 else if (BoundaryType == 0)
4538 MeshName = myBoundary->GetMeshName() ;
4539 MESSAGE ( ". MeshName = " << MeshName );
4540 DataFile = myBoundary->GetDataFile() ;
4541 MESSAGE ( ". MeshFile = " << DataFile );
4543 std::string texte_control_0 ;
4544 texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName, MeshName, DataFile );
4545 texte_control += texte_control_0 ;
4546 // 5. Memorisation du traitement
4547 ListeBoundaryTraitees.push_back( BoundaryName );
4551 return texte_control ;
4554 //=============================================================================
4555 //=============================================================================
4556 // Next functions are inherited from SALOMEDS::Driver interface
4557 //=============================================================================
4558 //=============================================================================
4559 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4561 CORBA::Boolean isMultiFile)
4563 MESSAGE ("Save for theURL = "<< theURL);
4564 SALOMEDS::TMPFile_var aStreamFile;
4566 // get temporary directory name
4567 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4569 StudyContext& context = myStudyContext;
4571 // HOMARD data file name
4572 std::string aFileName = "";
4574 aFileName = SALOMEDS_Tool::GetNameFromPath(Kernel_Utils::encode(SMESH_Gen_i::getStudyServant()->URL()));
4575 aFileName += "_HOMARD.dat";
4577 // initialize sequence of file names
4578 SALOMEDS_Tool::ListOfFiles aFileSeq;
4579 aFileSeq.reserve(1);
4580 aFileSeq.push_back(CORBA::string_dup(aFileName.c_str())) ;
4582 // get full path to the data file
4583 aFileName = tmpDir + aFileName;
4587 std::ofstream f(aFileName.c_str());
4589 // clear temporary id map
4590 context._idmap.clear();
4595 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4596 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4597 HOMARD::HOMARD_Cas_var aCas = it_case->second;
4598 PortableServer::ServantBase_var aServant = GetServant(aCas);
4599 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4601 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4602 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4606 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4607 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4608 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4609 PortableServer::ServantBase_var aServant = GetServant(aZone);
4610 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4612 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4613 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4616 // -> save hypotheses
4617 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4618 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4619 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4620 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4621 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4623 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4624 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4627 // -> save iterations
4628 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4629 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4630 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4631 PortableServer::ServantBase_var aServant = GetServant(aIter);
4632 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4634 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4635 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4638 // -> save boundaries
4639 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4640 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4641 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4642 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4643 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4644 if (aBoundaryServant) {
4645 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4646 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4650 MESSAGE ("close file");
4653 // put temporary files to the stream
4654 MESSAGE ("put temporary files to the stream");
4655 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq, isMultiFile);
4657 // remove temporary files
4658 MESSAGE ("remove temporary files");
4659 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq, true);
4661 // return data stream
4662 MESSAGE ("return data stream");
4663 return aStreamFile._retn();
4666 //===========================================================================
4667 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4669 CORBA::Boolean isMultiFile)
4671 // No specific ASCII persistence
4672 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4673 return aStreamFile._retn();
4676 //===========================================================================
4677 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4678 const SALOMEDS::TMPFile& theStream,
4680 CORBA::Boolean isMultiFile)
4682 MESSAGE ("Load pour theURL = "<< theURL);
4684 // set current study
4685 if (myStudy->_is_nil())
4688 // get temporary directory name
4689 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4691 // Convert the stream into sequence of files to process
4692 SALOMEDS_Tool::ListOfFiles aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4695 // HOMARD data file name
4696 std::string aFileName = "";
4698 aFileName = SALOMEDS_Tool::GetNameFromPath(Kernel_Utils::encode(SMESH_Gen_i::getStudyServant()->URL()));
4699 aFileName = tmpDir + aFileName + "_HOMARD.dat";
4701 StudyContext& context = myStudyContext;
4705 std::ifstream f(aFileName.c_str());
4708 context._mesCas.clear();
4709 context._mesHypotheses.clear();
4710 context._mesIterations.clear();
4711 context._mesZones.clear();
4712 context._mesBoundarys.clear();
4713 context._idmap.clear();
4719 std::getline(f, line);
4720 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4721 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4722 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4723 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4724 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4725 std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4726 if (line.substr(0, bounSignature.size()) == bounSignature) {
4727 // re-create boundary
4728 MESSAGE ("Recreation de la frontiere" );
4729 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4730 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4731 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4732 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4733 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4734 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4737 else if (line.substr(0, caseSignature.size()) == caseSignature) {
4739 MESSAGE ("Recreation du cas" );
4740 HOMARD::HOMARD_Cas_var aCase = newCase();
4741 PortableServer::ServantBase_var aServant = GetServant(aCase);
4742 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4743 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4744 context._mesCas[aCase->GetName()] = aCase;
4745 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4748 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4749 // re-create hypothesis
4750 MESSAGE ("Recreation de l hypothese" );
4751 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4752 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4753 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4754 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4755 context._mesHypotheses[aHypo->GetName()] = aHypo;
4756 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4759 else if (line.substr(0, iterSignature.size()) == iterSignature) {
4760 // re-create iteration
4761 MESSAGE ("Recreation de l'iteration" );
4762 HOMARD::HOMARD_Iteration_var aIter = newIteration();
4763 PortableServer::ServantBase_var aServant = GetServant(aIter);
4764 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4765 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4766 context._mesIterations[aIter->GetName()] = aIter;
4767 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4770 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4771 MESSAGE ("Recreation de la zone" );
4773 HOMARD::HOMARD_Zone_var aZone = newZone();
4774 PortableServer::ServantBase_var aServant = GetServant(aZone);
4775 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4776 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4777 context._mesZones[aZone->GetName()] = aZone;
4778 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4781 else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4782 MESSAGE ("Recreation du schema YACS" );
4784 HOMARD::HOMARD_YACS_var aYACS = newYACS();
4785 PortableServer::ServantBase_var aServant = GetServant(aYACS);
4786 HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4787 if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4788 context._mesYACSs[aYACS->GetName()] = aYACS;
4789 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4798 // Remove temporary files created from the stream
4800 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq, true);
4805 //===========================================================================
4806 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4807 const SALOMEDS::TMPFile& theStream,
4809 CORBA::Boolean isMultiFile)
4811 // No specific ASCII persistence
4812 return Load(theComponent, theStream, theURL, isMultiFile);
4815 //===========================================================================
4816 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4820 //===========================================================================
4821 char* HOMARD_Gen_i::ComponentDataType()
4823 return CORBA::string_dup("HOMARD");
4826 //===========================================================================
4827 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4828 const char* IORString,
4829 CORBA::Boolean isMultiFile,
4830 CORBA::Boolean isASCII)
4832 CORBA::String_var aString("");
4833 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4834 StudyContext context = myStudyContext;
4835 CORBA::Object_var anObj = _orb->string_to_object(IORString);
4836 if (!CORBA::is_nil(anObj)) {
4837 PortableServer::ServantBase_var aServant = GetServant(anObj);
4838 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4840 std::map<int, PortableServer::ServantBase*>::const_iterator it;
4841 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4842 if (it->second == aStorable) {
4843 std::stringstream os;
4845 aString = CORBA::string_dup(os.str().c_str());
4851 return aString._retn();
4854 //===========================================================================
4855 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4856 const char* aLocalPersistentID,
4857 CORBA::Boolean isMultiFile,
4858 CORBA::Boolean isASCII)
4860 CORBA::String_var aString("");
4861 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4862 StudyContext context = myStudyContext;
4863 int id = atoi(aLocalPersistentID);
4864 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4865 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4866 if (!CORBA::is_nil(object)) {
4867 aString = _orb->object_to_string(object);
4871 return aString._retn();
4874 //===========================================================================
4875 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4877 if(CORBA::is_nil(myStudy))
4880 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4881 if(!aCas->_is_nil())
4884 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4885 if(!aHypo->_is_nil())
4888 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4889 if(!aZone->_is_nil())
4892 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4893 if(!aBoundary->_is_nil())
4896 /* Iteration is not published directly
4897 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4898 if(!aIter->_is_nil())
4904 //===========================================================================
4905 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4907 // No Copy/Paste support
4911 //===========================================================================
4912 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4913 CORBA::Long& theObjectID)
4915 // No Copy/Paste support
4916 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4917 return aStreamFile._retn();
4920 //===========================================================================
4921 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
4922 CORBA::Long theObjectID)
4924 // No Copy/Paste support
4928 //===========================================================================
4929 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4930 CORBA::Long theObjectID,
4931 SALOMEDS::SObject_ptr theSObject)
4933 // No Copy/Paste support
4934 SALOMEDS::SObject_var aResultSO;
4935 return aResultSO._retn();
4938 //===========================================================================
4939 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4941 PortableServer::Servant aServant = 0;
4942 if (!CORBA::is_nil(theObject)) {
4944 aServant = _poa->reference_to_servant(theObject);
4952 //==========================================================================
4953 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Boolean isPublished,
4954 CORBA::Boolean isMultiFile,
4955 CORBA::Boolean& isValidScript)
4957 MESSAGE ("Entree dans DumpPython");
4960 SALOMEDS::SObject_var aSO = SMESH_Gen_i::getStudyServant()->FindComponent("HOMARD");
4961 if(CORBA::is_nil(aSO))
4962 return new Engines::TMPFile(0);
4964 std::string aScript = "\"\"\"\n";
4965 aScript += "Python script for HOMARD\n";
4966 aScript += "Copyright 1996, 2011, 2015 EDF\n";
4967 aScript += "\"\"\"\n";
4968 aScript += "__revision__ = \"V1.2\"\n";
4969 aScript += "import HOMARD\n";
4971 aScript += "import salome\n";
4972 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4973 aScript += "\thomard.UpdateStudy()\n";
4974 MESSAGE (". Au depart \n"<<aScript);
4977 if (myStudyContext._mesBoundarys.size() > 0)
4979 MESSAGE (". Ecritures des frontieres");
4980 aScript += "#\n# Creation of the boundaries";
4981 aScript += "\n# ==========================";
4983 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4984 for (it_boundary = myStudyContext._mesBoundarys.begin();
4985 it_boundary != myStudyContext._mesBoundarys.end(); ++it_boundary)
4987 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4988 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4989 std::string dumpBoundary = dumpCorbaBoundary.in();
4990 MESSAGE (dumpBoundary<<"\n");
4991 aScript += dumpBoundary;
4995 if (myStudyContext._mesZones.size() > 0)
4997 MESSAGE (". Ecritures des zones");
4998 aScript += "#\n# Creation of the zones";
4999 aScript += "\n# =====================";
5001 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
5002 for ( it_zone = myStudyContext._mesZones.begin();
5003 it_zone != myStudyContext._mesZones.end(); ++it_zone)
5005 HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
5006 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
5007 std::string dumpZone = dumpCorbaZone.in();
5008 MESSAGE (dumpZone<<"\n");
5009 aScript += dumpZone;
5013 if (myStudyContext._mesHypotheses.size() > 0)
5015 MESSAGE (". Ecritures des hypotheses");
5016 aScript += "#\n# Creation of the hypotheses";
5017 aScript += "\n# ==========================";
5019 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
5020 for ( it_hypo = myStudyContext._mesHypotheses.begin();
5021 it_hypo != myStudyContext._mesHypotheses.end(); it_hypo++)
5023 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
5024 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
5025 std::string dumpHypo = dumpCorbaHypo.in();
5026 MESSAGE (dumpHypo<<"\n");
5027 aScript += dumpHypo;
5031 if (myStudyContext._mesCas.size() > 0)
5033 MESSAGE (". Ecritures des cas");
5034 aScript += "#\n# Creation of the cases";
5035 aScript += "\n# =====================";
5037 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
5038 for (it_cas = myStudyContext._mesCas.begin();
5039 it_cas != myStudyContext._mesCas.end(); it_cas++)
5041 std::string nomCas = (*it_cas).first;
5042 std::string dumpCas = std::string("\n# Creation of the case ") ;
5043 dumpCas += nomCas + std::string("\n");
5044 dumpCas += std::string("\t") + nomCas;
5045 dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
5047 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
5048 CORBA::String_var cIter0= myCase->GetIter0Name();
5049 std::string iter0 = cIter0.in();
5051 HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[iter0];
5052 CORBA::String_var cMesh0= myIteration->GetMeshFile();
5053 std::string mesh0 = cMesh0.in();
5054 CORBA::String_var cMeshName0= myIteration->GetMeshName();
5055 std::string meshName0 = cMeshName0.in();
5056 dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
5057 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
5058 std::string dumpCas2= dumpCorbaCase.in();
5060 MESSAGE (dumpCas<<dumpCas2<<"\n");
5061 aScript += dumpCas + dumpCas2;
5065 if (myStudyContext._mesIterations.size() > 0)
5067 MESSAGE (". Ecritures des iterations");
5068 aScript += "#\n# Creation of the iterations" ;
5069 aScript += "\n# ==========================";
5071 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
5072 for (it_iter = myStudyContext._mesIterations.begin();
5073 it_iter != myStudyContext._mesIterations.end(); ++it_iter)
5075 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
5076 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
5077 std::string dumpIter = dumpCorbaIter.in();
5078 MESSAGE (dumpIter<<"\n");
5079 aScript += dumpIter;
5083 if (myStudyContext._mesYACSs.size() > 0)
5085 MESSAGE (". Ecritures des schemas YACS");
5086 aScript += "#\n# Creation of the schemas YACS";
5087 aScript += "\n# ============================";
5089 std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
5090 for ( it_yacs = myStudyContext._mesYACSs.begin();
5091 it_yacs != myStudyContext._mesYACSs.end(); ++it_yacs)
5093 HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
5094 CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
5095 std::string dumpYACS = dumpCorbaYACS.in();
5096 MESSAGE (dumpYACS<<"\n");
5097 aScript += dumpYACS;
5100 MESSAGE (". Ecritures finales");
5102 aScript += "\n\tpass";
5105 if( !isMultiFile ) // remove unnecessary tabulation
5106 aScript = RemoveTabulation( aScript );
5108 // MESSAGE ("A ecrire \n"<<aScript);
5109 const size_t aLen = strlen(aScript.c_str());
5110 char* aBuffer = new char[aLen+1];
5111 strcpy(aBuffer, aScript.c_str());
5113 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
5114 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
5116 MESSAGE ("Sortie de DumpPython");
5117 return aStreamFile._retn();
5121 //=============================================================================
5122 //=============================================================================
5124 //=============================================================================
5125 //=============================================================================
5126 void HOMARD_Gen_i::IsValidStudy( )
5128 // MESSAGE( "IsValidStudy" );
5129 if (CORBA::is_nil(SMESH_Gen_i::getStudyServant()))
5131 SALOME::ExceptionStruct es;
5132 es.type = SALOME::BAD_PARAM;
5133 es.text = "Invalid study context";
5134 throw SALOME::SALOME_Exception(es);
5139 //=============================================================================
5140 char* HOMARD_Gen_i::VerifieDir(const char* nomDir)
5142 std::string casename = std::string("") ;
5143 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
5144 for (it = myStudyContext._mesCas.begin();
5145 it != myStudyContext._mesCas.end(); it++)
5147 if (std::string(nomDir) == std::string(it->second->GetDirName()))
5149 casename = std::string(it->second->GetName()) ;
5153 return CORBA::string_dup( casename.c_str() );
5155 /*//=============================================================================
5156 void SALOMEException( std::string message )
5158 SALOME::ExceptionStruct es;
5159 es.type = SALOME::BAD_PARAM;
5161 throw SALOME::SALOME_Exception(es);
5164 //=============================================================================
5165 char* HOMARD_Gen_i::getVersion()
5167 #if HOMARD_DEVELOPMENT
5168 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
5170 return CORBA::string_dup(HOMARD_VERSION_STR);
5173 //===============================================================================
5174 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un caractere
5175 // ligne : la ligne a manipuler
5176 // caractere : le caractere a reperer
5177 // option : 0 : la chaine avant la premiere apparition du caractere
5178 // 1 : la chaine apres la premiere apparition du caractere
5179 // 2 : la chaine avant la derniere apparition du caractere
5180 // 3 : la chaine apres la derniere apparition du caractere
5181 // Si le caractere est absent, on retourne la chaine totale
5182 //===============================================================================
5183 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string caractere, int option )
5185 // MESSAGE("GetStringInTexte, recherche de '"<<caractere<<"' dans '"<<ligne<<"'"<<", option = "<<option);
5187 std::string chaine = ligne ;
5189 if ( option < 2 ) { position = ligne.find_first_of( caractere ) ; }
5190 else { position = ligne.find_last_of( caractere ) ; }
5191 // MESSAGE("position = "<<position);
5192 // MESSAGE("a = "<<ligne.substr( 0, position ).c_str());
5193 // MESSAGE("b = "<<ligne.substr( position+1 ).c_str());
5195 if ( position != std::string::npos )
5197 if ( ( option == 0 ) || ( option == 2 ) ) { chaine = ligne.substr( 0, position ) ; }
5198 else { chaine = ligne.substr( position+1 ) ; }
5203 //=============================================================================
5204 //=============================================================================
5205 // Gestion des preferences
5206 //=============================================================================
5207 //=============================================================================
5208 // Decodage du fichier d'arcihvage des preferences
5210 void HOMARD_Gen_i::SetPreferences( )
5212 MESSAGE ( "SetPreferences" );
5214 std::string ligne, mot_cle, salome_version ;
5217 // A. Les valeurs par defaut ; elles doivent etre coherentes
5218 std::string LanguageShort = "en" ;
5219 int PublisMeshIN = 0 ;
5220 int PublisMeshOUT = 0 ;
5221 int YACSMaxIter = 0 ;
5222 int YACSMaxNode = 0 ;
5223 int YACSMaxElem = 0 ;
5224 std::string YACSTypeTestchaine = "None" ;
5226 // B. La version de salome
5227 // Cela se presente sous la forme :
5228 // [SALOME KERNEL] : 7.3.0
5230 File = getenv("KERNEL_ROOT_DIR") ;
5231 File += "/bin/salome/VERSION" ;
5232 MESSAGE ( "File = "<<File ) ;
5233 std::ifstream fichier0( File.c_str() ) ;
5234 if ( fichier0 ) // ce test échoue si le fichier n'est pas ouvert
5236 std::string ligne; // variable contenant chaque ligne lue
5237 while ( std::getline( fichier0, ligne ) )
5239 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5240 ligne_bis >> mot_cle ;
5241 if ( mot_cle == "[SALOME" )
5243 salome_version = GetStringInTexte ( ligne, " ", 3 ) ;
5244 // MESSAGE ( "salome_version = "<<salome_version<<"|||");
5249 else { ok = false ; }
5251 // B. Decodage du fichier de preferences
5254 std::string PrefFile ;
5255 PrefFile = getenv("HOME") ;
5256 PrefFile += "/.config/salome/SalomeApprc." + salome_version ;
5257 MESSAGE ( "PrefFile = "<<PrefFile ) ;
5259 std::ifstream fichier( PrefFile.c_str() );
5260 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
5262 bool section_langue = false ;
5263 bool section_homard = false ;
5264 while ( std::getline( fichier, ligne ) )
5266 std::string chaine ;
5267 // 1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
5268 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5269 ligne_bis >> mot_cle ;
5272 // 2.1. Debut d'une section
5273 // MESSAGE(mot_cle);
5274 if ( mot_cle == "<section" )
5275 { /*MESSAGE ( "Debut de la section : "<< ligne);*/
5276 ligne_bis >> mot_cle ;
5277 chaine = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5278 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5279 if ( chaine == "language" ) { section_langue = true ; }
5280 if ( chaine == "HOMARD" ) { section_homard = true ; }
5281 // MESSAGE ( "section_langue = "<<section_langue<<", section_homard = "<<section_homard);
5283 // 2.2. Fin d'une section
5284 else if ( mot_cle == "</section>" )
5285 { /*MESSAGE ( "Fin de la section : "<< ligne<<", section_langue = "<<section_langue<<", section_homard = "<<section_homard);*/
5286 section_langue = false ;
5287 section_homard = false ; }
5291 else if ( section_langue || section_homard )
5292 { MESSAGE ( "a decoder : "<< ligne);
5293 // La valeur : entre les deux premieres quotes
5294 chaine = GetStringInTexte ( ligne, "\"", 1 ) ;
5295 // MESSAGE("chaine 1 = |"<<chaine<<"|");
5296 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5297 // MESSAGE("chaine = |"<<chaine<<"|");
5298 // Le mot_cle : entre les deux dernieres quotes
5299 std::string chaine2 = GetStringInTexte ( ligne, "\"", 2 ) ;
5300 // MESSAGE("chaine2 1 = |"<<chaine2<<"|");
5301 chaine2 = GetStringInTexte ( chaine2, "\"", 3 ) ;
5302 // MESSAGE("chaine2 = |"<<chaine2<<"|");
5304 if ( section_langue )
5305 { if ( chaine2 == "language" ) { LanguageShort = chaine ; } }
5307 if ( section_homard )
5309 std::istringstream chainebis( chaine ) ;
5310 // 3.2.1. Les publications
5311 if ( chaine2 == "publish_mesh_in" ) { chainebis >> PublisMeshIN ; }
5312 if ( chaine2 == "publish_mesh_out" ) { chainebis >> PublisMeshOUT ; }
5313 // 3.2.2. Les maximum pour YACS
5314 if ( chaine2 == "yacs_max_iter" ) { chainebis >> YACSMaxIter ; }
5315 if ( chaine2 == "yacs_max_node" ) { chainebis >> YACSMaxNode ; }
5316 if ( chaine2 == "yacs_max_elem" ) { chainebis >> YACSMaxElem ; }
5317 if ( chaine2 == "yacs_type_test" ) { YACSTypeTestchaine = chaine ; }
5324 // C. Enregistrements
5325 MESSAGE ("Enregistrement de LanguageShort = " << LanguageShort );
5326 SetLanguageShort( LanguageShort.c_str() ) ;
5328 MESSAGE ("Enregistrement de PublisMeshIN = " << PublisMeshIN<<", PublisMeshOUT = "<< PublisMeshOUT);
5329 SetPublisMesh(PublisMeshIN, PublisMeshOUT) ;
5331 MESSAGE ("Enregistrement de YACSMaxIter = " << YACSMaxIter<<", YACSMaxNode = "<< YACSMaxNode<<", YACSMaxElem = "<< YACSMaxElem);
5332 SetYACSMaximum(YACSMaxIter, YACSMaxNode, YACSMaxElem) ;
5334 MESSAGE ("Enregistrement de TypeTest = " << YACSTypeTestchaine.c_str() );
5336 if ( ( YACSTypeTestchaine == "VTest > VRef" ) || ( YACSTypeTestchaine == "VTest > VRef" ) ) { YACSTypeTest = 1 ; }
5337 else if ( ( YACSTypeTestchaine == "VTest < VRef" ) || ( YACSTypeTestchaine == "VTest < VRef" ) ) { YACSTypeTest = 2 ; }
5338 else { YACSTypeTest = 0 ; }
5339 MESSAGE ("==> TypeTest = " << YACSTypeTest );
5340 SetYACSConvergenceType( YACSTypeTest ) ;
5344 //===============================================================================
5346 //===============================================================================
5347 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
5349 // MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
5350 _LangueShort = LanguageShort ;
5351 if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
5352 else { _Langue = "English" ; }
5355 char* HOMARD_Gen_i::GetLanguageShort()
5357 // MESSAGE ("GetLanguageShort");
5358 return CORBA::string_dup( _LangueShort.c_str() );
5360 //===============================================================================
5361 // Options de publications
5362 //===============================================================================
5363 void HOMARD_Gen_i::SetPublisMesh(CORBA::Long PublisMeshIN, CORBA::Long PublisMeshOUT)
5365 _PublisMeshIN = PublisMeshIN ;
5366 _PublisMeshOUT = PublisMeshOUT ;
5369 CORBA::Long HOMARD_Gen_i::GetPublisMeshIN()
5371 return _PublisMeshIN ;
5373 CORBA::Long HOMARD_Gen_i::GetPublisMeshOUT()
5375 return _PublisMeshOUT ;
5377 //===============================================================================
5378 // YACS - test de convergence
5379 //===============================================================================
5380 void HOMARD_Gen_i::SetYACSMaximum(CORBA::Long YACSMaxIter, CORBA::Long YACSMaxNode, CORBA::Long YACSMaxElem)
5382 _YACSMaxIter = YACSMaxIter ;
5383 _YACSMaxNode = YACSMaxNode ;
5384 _YACSMaxElem = YACSMaxElem ;
5387 CORBA::Long HOMARD_Gen_i::GetYACSMaxIter()
5389 return _YACSMaxIter ;
5391 CORBA::Long HOMARD_Gen_i::GetYACSMaxNode()
5393 return _YACSMaxNode ;
5395 CORBA::Long HOMARD_Gen_i::GetYACSMaxElem()
5397 return _YACSMaxElem ;
5399 void HOMARD_Gen_i::SetYACSConvergenceType(CORBA::Long YACSTypeTest)
5401 _YACSTypeTest = YACSTypeTest ;
5404 CORBA::Long HOMARD_Gen_i::GetYACSConvergenceType()
5406 return _YACSTypeTest ;
5409 //=============================================================================
5413 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
5414 PortableServer::POA_ptr poa,
5415 PortableServer::ObjectId* contId,
5416 const char* instanceName,
5417 const char* interfaceName)
5419 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
5420 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
5421 return myHOMARD_Gen->getId();