1 // Copyright (C) 2011-2020 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 "ADAPT_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 "SMESH_version.h"
37 #include "utilities.h"
38 #include "Basics_Utils.hxx"
39 #include "Basics_DirUtils.hxx"
40 #include "Utils_SINGLETON.hxx"
41 #include "Utils_CorbaException.hxx"
42 #include "SALOMEDS_Tool.hxx"
43 #include "SALOME_LifeCycleCORBA.hxx"
44 #include "SALOMEconfig.h"
45 #include <SMESH_Gen_i.hxx>
46 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
47 #include CORBA_CLIENT_HEADER(SMESH_Gen)
70 //=============================================================================
72 //=============================================================================
73 std::string RemoveTabulation( std::string theScript )
75 std::string::size_type aPos = 0;
76 while( aPos < theScript.length() )
78 aPos = theScript.find( "\n\t", aPos );
79 if( aPos == std::string::npos )
81 theScript.replace( aPos, 2, "\n" );
86 //=============================================================================
88 * standard constructor
90 //=============================================================================
91 ADAPT_Gen_i::ADAPT_Gen_i( CORBA::ORB_ptr orb,
92 PortableServer::POA_ptr poa,
93 PortableServer::ObjectId * contId,
94 const char *instanceName,
95 const char *interfaceName) :
96 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
98 MESSAGE("constructor");
100 _id = _poa->activate_object(_thisObj);
102 myHomard = new ::ADAPT_Gen();
103 _NS = SINGLETON_<SALOME_NamingService>::Instance();
104 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
107 myStudy = SALOMEDS::Study::_duplicate( SMESH_Gen_i::getStudyServant() );
117 //=================================
119 * standard destructor
121 //================================
122 ADAPT_Gen_i::~ADAPT_Gen_i()
125 //=============================================================================
126 //=============================================================================
127 // Utilitaires pour l'étude
128 //=============================================================================
129 //=============================================================================
130 void ADAPT_Gen_i::UpdateStudy()
132 ASSERT(!CORBA::is_nil(myStudy));
133 SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
135 // Create SComponent labelled 'homard' if it doesn't already exit
136 SALOMEDS::SComponent_var homardFather = myStudy->FindComponent(ComponentDataType());
137 if (CORBA::is_nil(homardFather))
139 myBuilder->NewCommand();
140 MESSAGE("Add Component HOMARD");
142 bool aLocked = myStudy->GetProperties()->IsLocked();
143 if (aLocked) myStudy->GetProperties()->SetLocked(false);
145 homardFather = myBuilder->NewComponent(ComponentDataType());
146 SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
147 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
148 CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
149 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
150 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
151 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
152 if (!Comp->_is_nil())
154 aName->SetValue(ComponentDataType());
157 anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributePixMap");
158 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
159 aPixmap->SetPixMap("HOMARD_2.png");
160 myBuilder->DefineComponentInstance(homardFather, ADAPT_Gen::_this());
162 if (aLocked) myStudy->GetProperties()->SetLocked(true);
163 myBuilder->CommitCommand();
167 //=============================================================================
168 //=============================================================================
169 // Utilitaires pour l'iteration
170 //=============================================================================
171 //=============================================================================
172 void ADAPT_Gen_i::SetEtatIter(const char* nomIter, const CORBA::Long Etat)
173 //=====================================================================================
175 MESSAGE( "SetEtatIter : affectation de l'etat " << Etat << " a l'iteration " << nomIter );
176 ADAPT::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
177 if (CORBA::is_nil(myIteration))
179 SALOME::ExceptionStruct es;
180 es.type = SALOME::BAD_PARAM;
181 es.text = "Invalid iteration";
182 throw SALOME::SALOME_Exception(es);
186 myIteration->SetState(Etat);
188 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
189 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
193 icone = "iter0.png" ;
194 else if ( Etat == 2 )
195 icone = "iter_calculee.png" ;
197 icone = "iter_non_calculee.png" ;
198 PublishInStudyAttr(aStudyBuilder, aIterSO, NULL , NULL, icone.c_str(), NULL) ;
200 aStudyBuilder->CommitCommand();
203 //=============================================================================
204 //=============================================================================
206 //=============================================================================
207 //=============================================================================
208 // Destruction des structures identifiees par leurs noms
209 //=============================================================================
210 //=============================================================================
211 CORBA::Long ADAPT_Gen_i::DeleteBoundary(const char* BoundaryName)
213 MESSAGE ( "DeleteBoundary : BoundaryName = " << BoundaryName );
214 ADAPT::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
215 if (CORBA::is_nil(myBoundary))
217 SALOME::ExceptionStruct es;
218 es.type = SALOME::BAD_PARAM;
219 es.text = "Invalid boundary";
220 throw SALOME::SALOME_Exception(es);
224 // On verifie que la frontiere n'est plus utilisee
225 ADAPT::listeCases* maListe = GetAllCasesName();
226 int numberOfCases = maListe->length();
227 MESSAGE ( ".. Nombre de cas = " << numberOfCases );
228 std::string CaseName ;
229 ADAPT::ListBoundaryGroupType* ListBoundaryGroupType ;
231 ADAPT::HOMARD_Cas_var myCase ;
232 for (int NumeCas = 0; NumeCas< numberOfCases; NumeCas++)
234 CaseName = std::string((*maListe)[NumeCas]);
235 MESSAGE ( "... Examen du cas = " << CaseName.c_str() );
236 myCase = myStudyContext._mesCas[CaseName];
237 ASSERT(!CORBA::is_nil(myCase));
238 ListBoundaryGroupType = myCase->GetBoundaryGroup();
239 numberOfitems = ListBoundaryGroupType->length();
240 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
241 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
243 if ( std::string((*ListBoundaryGroupType)[NumBoundary]) == BoundaryName )
245 SALOME::ExceptionStruct es;
246 es.type = SALOME::BAD_PARAM;
247 es.text = "This boundary is used in a case and cannot be deleted.";
248 throw SALOME::SALOME_Exception(es);
254 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
255 myStudyContext._mesBoundarys.erase(BoundaryName);
256 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(BoundaryName, ComponentDataType());
257 SALOMEDS::SObject_var aSO =listSO[0];
258 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
259 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
263 //=============================================================================
264 CORBA::Long ADAPT_Gen_i::DeleteCase(const char* nomCas, CORBA::Long Option)
266 // Pour detruire un cas
267 MESSAGE ( "DeleteCase : nomCas = " << nomCas << ", avec option = " << Option );
268 ADAPT::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
269 if (CORBA::is_nil(myCase))
271 SALOME::ExceptionStruct es;
272 es.type = SALOME::BAD_PARAM;
273 es.text = "Invalid case context";
274 throw SALOME::SALOME_Exception(es);
277 // On commence par detruire toutes les iterations en partant de l'initiale et y compris elle
278 CORBA::String_var nomIter = myCase->GetIter0Name();
279 CORBA::Long Option1 = 0 ;
280 if ( DeleteIterationOption(nomIter, Option1, Option) != 0 )
285 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
286 myStudyContext._mesCas.erase(nomCas);
287 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomCas, ComponentDataType());
288 SALOMEDS::SObject_var aSO =listSO[0];
289 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
290 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
294 //=============================================================================
295 CORBA::Long ADAPT_Gen_i::DeleteHypo(const char* nomHypo)
297 MESSAGE ( "DeleteHypo : nomHypo = " << nomHypo );
298 ADAPT::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
299 if (CORBA::is_nil(myHypo))
301 SALOME::ExceptionStruct es;
302 es.type = SALOME::BAD_PARAM;
303 es.text = "Invalid hypothesis";
304 throw SALOME::SALOME_Exception(es);
308 // On verifie que l'hypothese n'est plus utilisee
309 ADAPT::listeIters* maListeIter = myHypo->GetIterations();
310 int numberOfIter = maListeIter->length();
311 if ( numberOfIter > 0 )
313 SALOME::ExceptionStruct es;
314 es.type = SALOME::BAD_PARAM;
315 es.text = "This hypothesis is used in an iteration and cannot be deleted.";
316 throw SALOME::SALOME_Exception(es);
320 // suppression du lien avec les zones eventuelles
321 ADAPT::listeZonesHypo* maListe = myHypo->GetZones();
322 int numberOfZones = maListe->length();
323 MESSAGE ( ".. Nombre de zones = " << numberOfZones );
324 for (int NumeZone = 0; NumeZone< numberOfZones; NumeZone++)
326 std::string ZoneName = std::string((*maListe)[NumeZone]);
327 MESSAGE ( ".. suppression du lien avec la zone = " << ZoneName.c_str() );
328 DissociateHypoZone(nomHypo, ZoneName.c_str()) ;
332 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
333 myStudyContext._mesHypotheses.erase(nomHypo);
334 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomHypo, ComponentDataType());
335 SALOMEDS::SObject_var aSO =listSO[0];
336 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
337 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
341 //=============================================================================
342 CORBA::Long ADAPT_Gen_i::DeleteIteration(const char* nomIter, CORBA::Long Option)
344 // Option = 0 : On ne supprime pas le fichier du maillage associe
345 // Option = 1 : On supprime le fichier du maillage associe
346 // Pour detruire une iteration courante
347 MESSAGE ( "DeleteIteration : nomIter = " << nomIter << ", avec option = " << Option );
348 CORBA::Long Option1 = 1 ;
349 return DeleteIterationOption(nomIter, Option1, Option);
351 //=============================================================================
352 CORBA::Long ADAPT_Gen_i::DeleteIterationOption(const char* nomIter, CORBA::Long Option1, CORBA::Long Option2)
354 // Option1 = 0 : On autorise la destruction de l'iteration 0
355 // Option1 = 1 : On interdit la destruction de l'iteration 0
357 // Option2 = 0 : On ne supprime pas le fichier du maillage associe
358 // Option2 = 1 : On supprime le fichier du maillage associe
359 MESSAGE ( "DeleteIterationOption : nomIter = " << nomIter << ", avec options = " << Option1<< ", " << Option2 );
360 ADAPT::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
361 if (CORBA::is_nil(myIteration))
363 SALOME::ExceptionStruct es;
364 es.type = SALOME::BAD_PARAM;
365 es.text = "Invalid iteration";
366 throw SALOME::SALOME_Exception(es);
370 int numero = myIteration->GetNumber();
371 MESSAGE ( "DeleteIterationOption : numero = " << numero );
372 if ( numero == 0 && Option1 == 1 )
374 SALOME::ExceptionStruct es;
375 es.type = SALOME::BAD_PARAM;
376 es.text = "This iteration cannot be deleted.";
377 throw SALOME::SALOME_Exception(es);
381 // On detruit recursivement toutes les filles
382 ADAPT::listeIterFilles* maListe = myIteration->GetIterations();
383 int numberOfIter = maListe->length();
384 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
386 std::string nomIterFille = std::string((*maListe)[NumeIter]);
387 MESSAGE ( ".. appel recursif de DeleteIterationOption pour nomIter = " << nomIterFille.c_str() );
388 DeleteIterationOption(nomIterFille.c_str(), Option1, Option2);
391 // On arrive ici pour une iteration sans fille
392 MESSAGE ( "Destruction effective de " << nomIter );
393 // On commence par invalider l'iteration pour faire le menage des dependances
394 // et eventuellement du maillage associe
396 if ( numero == 0 ) { option = 0 ; }
397 else { option = Option2 ; }
398 InvalideIterOption(nomIter, option) ;
400 // Retrait dans la descendance de l'iteration parent
403 std::string nomIterationParent = myIteration->GetIterParentName();
404 MESSAGE ( "Retrait dans la descendance de nomIterationParent " << nomIterationParent );
405 ADAPT::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterationParent];
406 if (CORBA::is_nil(myIterationParent))
408 SALOME::ExceptionStruct es;
409 es.type = SALOME::BAD_PARAM;
410 es.text = "Invalid iteration";
411 throw SALOME::SALOME_Exception(es);
414 myIterationParent->UnLinkNextIteration(nomIter);
417 // suppression du lien avec l'hypothese
420 std::string nomHypo = myIteration->GetHypoName();
421 ADAPT::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
422 ASSERT(!CORBA::is_nil(myHypo));
423 myHypo->UnLinkIteration(nomIter);
426 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
427 myStudyContext._mesIterations.erase(nomIter);
428 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomIter, ComponentDataType());
429 SALOMEDS::SObject_var aSO =listSO[0];
430 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
431 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
432 // on peut aussi faire RemoveObject
433 // MESSAGE ( "Au final" );
434 // ADAPT::listeIterations* Liste = GetAllIterationsName() ;
435 // numberOfIter = Liste->length();
436 // for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
438 // std::string nomIterFille = std::string((*Liste)[NumeIter]);
439 // MESSAGE ( ".. nomIter = " << nomIterFille.c_str() );
444 //=============================================================================
445 CORBA::Long ADAPT_Gen_i::DeleteYACS(const char* nomYACS, CORBA::Long Option)
447 // Option = 0 : On ne supprime pas le fichier du schema associe
448 // Option = 1 : On supprime le fichier du schema associe
449 MESSAGE ( "DeleteYACS : nomYACS = " << nomYACS << ", avec option = " << Option );
450 ADAPT::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
451 if (CORBA::is_nil(myYACS))
453 SALOME::ExceptionStruct es;
454 es.type = SALOME::BAD_PARAM;
455 es.text = "Invalid schema YACS";
456 throw SALOME::SALOME_Exception(es);
459 // Suppression eventuelle du fichier XML
462 std::string nomFichier = myYACS->GetXMLFile();
463 std::string commande = "rm -rf " + nomFichier ;
464 MESSAGE ( "commande = " << commande );
465 if ((system(commande.c_str())) != 0)
467 SALOME::ExceptionStruct es;
468 es.type = SALOME::BAD_PARAM;
469 es.text = "The xml file for the schema YACS cannot be removed." ;
470 throw SALOME::SALOME_Exception(es);
474 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
475 myStudyContext._mesYACSs.erase(nomYACS);
476 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomYACS, ComponentDataType());
477 SALOMEDS::SObject_var aSO =listSO[0];
478 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
479 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
483 //=============================================================================
484 CORBA::Long ADAPT_Gen_i::DeleteZone(const char* nomZone)
486 MESSAGE ( "DeleteZone : nomZone = " << nomZone );
487 ADAPT::HOMARD_Zone_var myZone = myStudyContext._mesZones[nomZone];
488 if (CORBA::is_nil(myZone))
490 SALOME::ExceptionStruct es;
491 es.type = SALOME::BAD_PARAM;
492 es.text = "Invalid zone";
493 throw SALOME::SALOME_Exception(es);
497 // On verifie que la zone n'est plus utilisee
498 ADAPT::listeHypo* maListe = myZone->GetHypo();
499 int numberOfHypo = maListe->length();
500 MESSAGE ( ".. Nombre d'hypotheses = " << numberOfHypo );
501 if ( numberOfHypo > 0 )
503 SALOME::ExceptionStruct es;
504 es.type = SALOME::BAD_PARAM;
505 es.text = "This zone is used in a hypothesis and cannot be deleted.";
506 throw SALOME::SALOME_Exception(es);
510 // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
511 myStudyContext._mesZones.erase(nomZone);
512 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomZone, ComponentDataType());
513 SALOMEDS::SObject_var aSO =listSO[0];
514 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
515 myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
519 //=============================================================================
520 //=============================================================================
522 //=============================================================================
523 //=============================================================================
524 // Invalidation des structures identifiees par leurs noms
525 //=============================================================================
526 //=============================================================================
527 void ADAPT_Gen_i::InvalideBoundary(const char* BoundaryName)
529 MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName );
530 ADAPT::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
531 if (CORBA::is_nil(myBoundary))
533 SALOME::ExceptionStruct es;
534 es.type = SALOME::BAD_PARAM;
535 es.text = "Invalid boundary";
536 throw SALOME::SALOME_Exception(es);
541 SALOME::ExceptionStruct es;
542 es.type = SALOME::BAD_PARAM;
543 es.text = "No change is allowed in a boundary. Ask for evolution.";
544 throw SALOME::SALOME_Exception(es);
548 //=============================================================================
549 void ADAPT_Gen_i::InvalideHypo(const char* nomHypo)
551 MESSAGE( "InvalideHypo : nomHypo = " << nomHypo );
552 ADAPT::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
553 if (CORBA::is_nil(myHypo))
555 SALOME::ExceptionStruct es;
556 es.type = SALOME::BAD_PARAM;
557 es.text = "Invalid hypothesis";
558 throw SALOME::SALOME_Exception(es);
562 ADAPT::listeIters* maListe = myHypo->GetIterations();
563 int numberOfIter = maListe->length();
564 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
566 std::string nomIter = std::string((*maListe)[NumeIter]);
567 MESSAGE( ".. nomIter = " << nomIter );
568 InvalideIter(nomIter.c_str());
571 //=============================================================================
572 void ADAPT_Gen_i::InvalideIter(const char* nomIter)
574 MESSAGE("InvalideIter : nomIter = " << nomIter);
575 // Pour invalider totalement une iteration courante
576 CORBA::Long Option = 1 ;
577 return InvalideIterOption(nomIter, Option);
579 //=============================================================================
580 void ADAPT_Gen_i::InvalideIterOption(const char* nomIter, CORBA::Long Option)
582 // Option = 0 : On ne supprime pas le fichier du maillage associe
583 // Option = 1 : On supprime le fichier du maillage associe
584 MESSAGE ( "InvalideIterOption : nomIter = " << nomIter << ", avec option = " << Option );
585 ADAPT::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
586 if (CORBA::is_nil(myIteration))
588 SALOME::ExceptionStruct es;
589 es.type = SALOME::BAD_PARAM;
590 es.text = "Invalid iteration";
591 throw SALOME::SALOME_Exception(es);
595 ADAPT::listeIterFilles* maListe = myIteration->GetIterations();
596 int numberOfIter = maListe->length();
597 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
599 std::string nomIterFille = std::string((*maListe)[NumeIter]);
600 MESSAGE ( ".. appel recursif de InvalideIter pour nomIter = " << nomIterFille.c_str() );
601 InvalideIter(nomIterFille.c_str());
604 // On arrive ici pour une iteration sans fille
605 MESSAGE ( "Invalidation effective de " << nomIter );
606 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
607 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aIterSO);
608 for (; aIter->More(); aIter->Next())
610 SALOMEDS::SObject_var so = aIter->Value();
611 SALOMEDS::GenericAttribute_var anAttr;
612 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
613 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
614 std::string value (aCommentAttr->Value());
615 if(value == std::string("IterationHomard")) continue;
616 if(value == std::string("HypoHomard")) continue;
617 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
618 aStudyBuilder->RemoveObject(so);
621 int etat = myIteration->GetState();
624 SetEtatIter(nomIter,1);
625 const char * nomCas = myIteration->GetCaseName();
626 ADAPT::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
627 if (CORBA::is_nil(myCase))
629 SALOME::ExceptionStruct es;
630 es.type = SALOME::BAD_PARAM;
631 es.text = "Invalid case context";
632 throw SALOME::SALOME_Exception(es);
635 std::string nomDir = myIteration->GetDirName();
636 std::string nomFichier = myIteration->GetMeshFile();
637 std::string commande = "rm -rf " + std::string(nomDir);
638 if ( Option == 1 ) { commande = commande + ";rm -rf " + std::string(nomFichier) ; }
639 MESSAGE ( "commande = " << commande );
640 if ((system(commande.c_str())) != 0)
642 SALOME::ExceptionStruct es;
643 es.type = SALOME::BAD_PARAM;
644 es.text = "The directory for the calculation cannot be cleared." ;
645 throw SALOME::SALOME_Exception(es);
648 // Suppression du maillage publie dans SMESH
649 std::string MeshName = myIteration->GetMeshName() ;
650 DeleteResultInSmesh(nomFichier, MeshName) ;
654 //=============================================================================
655 void ADAPT_Gen_i::InvalideIterInfo(const char* nomIter)
657 MESSAGE("InvalideIterInfo : nomIter = " << nomIter);
658 ADAPT::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
659 if (CORBA::is_nil(myIteration))
661 SALOME::ExceptionStruct es;
662 es.type = SALOME::BAD_PARAM;
663 es.text = "Invalid iteration";
664 throw SALOME::SALOME_Exception(es);
668 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
669 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aIterSO);
670 for (; aIter->More(); aIter->Next())
672 SALOMEDS::SObject_var so = aIter->Value();
673 SALOMEDS::GenericAttribute_var anAttr;
674 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
675 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
676 std::string value (aCommentAttr->Value());
677 /* MESSAGE("... value = " << value);*/
678 if( (value == std::string("logInfo")) || ( value == std::string("SummaryInfo")) )
680 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
681 aStudyBuilder->RemoveObject(so);
685 const char * nomCas = myIteration->GetCaseName();
686 ADAPT::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
687 if (CORBA::is_nil(myCase))
689 SALOME::ExceptionStruct es;
690 es.type = SALOME::BAD_PARAM;
691 es.text = "Invalid case context";
692 throw SALOME::SALOME_Exception(es);
695 const char* nomDir = myIteration->GetDirName();
696 std::string commande = "rm -f " + std::string(nomDir) + "/info* " ;
697 commande += std::string(nomDir) + "/Liste.*info" ;
698 /* MESSAGE ( "commande = " << commande );*/
699 if ((system(commande.c_str())) != 0)
701 SALOME::ExceptionStruct es;
702 es.type = SALOME::BAD_PARAM;
703 es.text = "The directory for the calculation cannot be cleared." ;
704 throw SALOME::SALOME_Exception(es);
708 //=============================================================================
709 void ADAPT_Gen_i::InvalideYACS(const char* YACSName)
711 MESSAGE( "InvalideYACS : YACSName = " << YACSName );
712 ADAPT::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[YACSName];
713 if (CORBA::is_nil(myYACS))
715 SALOME::ExceptionStruct es;
716 es.type = SALOME::BAD_PARAM;
717 es.text = "Invalid schema YACS";
718 throw SALOME::SALOME_Exception(es);
722 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
723 SALOMEDS::ChildIterator_var aYACS = myStudy->NewChildIterator(aYACSSO);
724 for (; aYACS->More(); aYACS->Next())
726 SALOMEDS::SObject_var so = aYACS->Value();
727 SALOMEDS::GenericAttribute_var anAttr;
728 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
729 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
730 std::string value (aCommentAttr->Value());
731 if( value == std::string("xml") )
733 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
734 aStudyBuilder->RemoveObject(so);
737 std::string nomFichier = myYACS->GetXMLFile();
738 std::string commande = "rm -rf " + std::string(nomFichier) ;
739 MESSAGE ( "commande = " << commande );
740 if ((system(commande.c_str())) != 0)
742 SALOME::ExceptionStruct es;
743 es.type = SALOME::BAD_PARAM;
744 es.text = "The XML file for the schema YACS cannot be removed." ;
745 throw SALOME::SALOME_Exception(es);
749 //=============================================================================
750 void ADAPT_Gen_i::InvalideZone(const char* ZoneName)
752 MESSAGE( "InvalideZone : ZoneName = " << ZoneName );
753 ADAPT::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
754 if (CORBA::is_nil(myZone))
756 SALOME::ExceptionStruct es;
757 es.type = SALOME::BAD_PARAM;
758 es.text = "Invalid zone";
759 throw SALOME::SALOME_Exception(es);
762 ADAPT::listeHypo* maListe = myZone->GetHypo();
763 int numberOfHypo = maListe->length();
764 MESSAGE( ".. numberOfHypo = " << numberOfHypo );
765 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
767 std::string nomHypo = std::string((*maListe)[NumeHypo]);
768 MESSAGE( ".. nomHypo = " << nomHypo );
769 InvalideHypo(nomHypo.c_str());
772 //=============================================================================
773 //=============================================================================
775 //=============================================================================
776 //=============================================================================
777 // Association de lien entre des structures identifiees par leurs noms
778 //=============================================================================
779 //=============================================================================
780 void ADAPT_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
782 MESSAGE( "AssociateCaseIter : " << nomCas << ", " << nomIter << ", " << labelIter );
784 ADAPT::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
785 if (CORBA::is_nil(myCase))
787 SALOME::ExceptionStruct es;
788 es.type = SALOME::BAD_PARAM;
789 es.text = "Invalid case";
790 throw SALOME::SALOME_Exception(es);
794 ADAPT::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
795 if (CORBA::is_nil(myIteration))
797 SALOME::ExceptionStruct es;
798 es.type = SALOME::BAD_PARAM;
799 es.text = "Invalid iteration";
800 throw SALOME::SALOME_Exception(es);
804 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
805 SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myCase)));
806 if (CORBA::is_nil(aCasSO))
808 SALOME::ExceptionStruct es;
809 es.type = SALOME::BAD_PARAM;
810 es.text = "Invalid case";
811 throw SALOME::SALOME_Exception(es);
815 aStudyBuilder->NewCommand();
816 SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
817 PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
818 "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
819 aStudyBuilder->CommitCommand();
821 myCase->AddIteration(nomIter);
822 myIteration->SetCaseName(nomCas);
824 //=====================================================================================
825 void ADAPT_Gen_i::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
827 MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
829 ADAPT::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypothesis];
830 ASSERT(!CORBA::is_nil(myHypo));
831 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
832 ASSERT(!CORBA::is_nil(aHypoSO));
834 ADAPT::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
835 ASSERT(!CORBA::is_nil(myZone));
836 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myZone)));
837 ASSERT(!CORBA::is_nil(aZoneSO));
839 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
841 aStudyBuilder->NewCommand();
843 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
844 aStudyBuilder->Addreference(aSubSO, aZoneSO);
846 aStudyBuilder->CommitCommand();
848 myZone->AddHypo(nomHypothesis);
849 myHypo->AddZone0(ZoneName, TypeUse);
851 //=============================================================================
852 void ADAPT_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
854 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
856 // Verification de l'existence de l'hypothese
857 ADAPT::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
858 ASSERT(!CORBA::is_nil(myHypo));
859 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
860 ASSERT(!CORBA::is_nil(aHypoSO));
862 // Verification de l'existence de l'iteration
863 ADAPT::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
864 ASSERT(!CORBA::is_nil(myIteration));
865 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
866 ASSERT(!CORBA::is_nil(aIterSO));
868 // Gestion de l'arbre d'etudes
869 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
870 aStudyBuilder->NewCommand();
871 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
872 aStudyBuilder->Addreference(aSubSO, aHypoSO);
873 aStudyBuilder->CommitCommand();
876 myIteration->SetHypoName(nomHypo);
877 myHypo->LinkIteration(nomIter);
879 // On stocke les noms des champ a interpoler pour le futur controle de la donnée des pas de temps
880 myIteration->SupprFieldInterps() ;
881 ADAPT::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
882 int numberOfFieldsx2 = ListField->length();
883 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
885 std::string FieldName = std::string((*ListField)[iaux]) ;
886 myIteration->SetFieldInterp(FieldName.c_str()) ;
890 //=============================================================================
891 //=============================================================================
893 //=============================================================================
894 //=============================================================================
895 // Dissociation de lien entre des structures identifiees par leurs noms
896 //=============================================================================
897 //=============================================================================
898 void ADAPT_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
900 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
902 ADAPT::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypothesis];
903 ASSERT(!CORBA::is_nil(myHypo));
904 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
905 ASSERT(!CORBA::is_nil(aHypoSO));
907 ADAPT::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
908 ASSERT(!CORBA::is_nil(myZone));
909 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myZone)));
910 ASSERT(!CORBA::is_nil(aZoneSO));
912 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
914 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(aHypoSO);
915 for (; it->More(); it->Next())
917 SALOMEDS::SObject_var aHypObj = it->Value();
918 SALOMEDS::SObject_var ptrObj;
919 if (aHypObj->ReferencedObject(ptrObj))
921 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
923 aStudyBuilder->NewCommand();
924 aStudyBuilder->RemoveObject(aHypObj);
925 aStudyBuilder->CommitCommand();
931 myZone->SupprHypo(nomHypothesis);
932 myHypo->SupprZone(ZoneName);
934 //=============================================================================
935 //=============================================================================
938 //=============================================================================
939 //=============================================================================
940 // Recuperation des listes
941 //=============================================================================
942 //=============================================================================
943 ADAPT::listeBoundarys* ADAPT_Gen_i::GetAllBoundarysName()
945 MESSAGE("GetAllBoundarysName");
948 ADAPT::listeBoundarys_var ret = new ADAPT::listeBoundarys;
949 ret->length(myStudyContext._mesBoundarys.size());
950 std::map<std::string, ADAPT::HOMARD_Boundary_var>::const_iterator it;
952 for (it = myStudyContext._mesBoundarys.begin();
953 it != myStudyContext._mesBoundarys.end(); it++)
955 ret[i++] = CORBA::string_dup((*it).first.c_str());
960 //=============================================================================
961 ADAPT::listeCases* ADAPT_Gen_i::GetAllCasesName()
963 MESSAGE("GetAllCasesName");
966 ADAPT::listeCases_var ret = new ADAPT::listeCases;
967 ret->length(myStudyContext._mesCas.size());
968 std::map<std::string, ADAPT::HOMARD_Cas_var>::const_iterator it;
970 for (it = myStudyContext._mesCas.begin();
971 it != myStudyContext._mesCas.end(); it++)
973 ret[i++] = CORBA::string_dup((*it).first.c_str());
978 //=============================================================================
979 ADAPT::listeHypotheses* ADAPT_Gen_i::GetAllHypothesesName()
981 MESSAGE("GetAllHypothesesName");
984 ADAPT::listeHypotheses_var ret = new ADAPT::listeHypotheses;
985 ret->length(myStudyContext._mesHypotheses.size());
986 std::map<std::string, ADAPT::HOMARD_Hypothesis_var>::const_iterator it;
988 for (it = myStudyContext._mesHypotheses.begin();
989 it != myStudyContext._mesHypotheses.end(); it++)
991 ret[i++] = CORBA::string_dup((*it).first.c_str());
996 //=============================================================================
997 ADAPT::listeIterations* ADAPT_Gen_i::GetAllIterationsName()
999 MESSAGE("GetAllIterationsName");
1002 ADAPT::listeIterations_var ret = new ADAPT::listeIterations;
1003 ret->length(myStudyContext._mesIterations.size());
1004 std::map<std::string, ADAPT::HOMARD_Iteration_var>::const_iterator it;
1006 for (it = myStudyContext._mesIterations.begin();
1007 it != myStudyContext._mesIterations.end(); it++)
1009 ret[i++] = CORBA::string_dup((*it).first.c_str());
1014 //=============================================================================
1015 ADAPT::listeYACSs* ADAPT_Gen_i::GetAllYACSsName()
1017 MESSAGE("GetAllYACSsName");
1020 ADAPT::listeYACSs_var ret = new ADAPT::listeYACSs;
1021 ret->length(myStudyContext._mesYACSs.size());
1022 std::map<std::string, ADAPT::HOMARD_YACS_var>::const_iterator it;
1024 for (it = myStudyContext._mesYACSs.begin();
1025 it != myStudyContext._mesYACSs.end(); it++)
1027 ret[i++] = CORBA::string_dup((*it).first.c_str());
1032 //=============================================================================
1033 ADAPT::listeZones* ADAPT_Gen_i::GetAllZonesName()
1035 MESSAGE("GetAllZonesName");
1038 ADAPT::listeZones_var ret = new ADAPT::listeZones;
1039 ret->length(myStudyContext._mesZones.size());
1040 std::map<std::string, ADAPT::HOMARD_Zone_var>::const_iterator it;
1042 for (it = myStudyContext._mesZones.begin();
1043 it != myStudyContext._mesZones.end(); it++)
1045 ret[i++] = CORBA::string_dup((*it).first.c_str());
1050 //=============================================================================
1051 //=============================================================================
1053 //=============================================================================
1054 //=============================================================================
1055 // Recuperation des structures identifiees par leurs noms
1056 //=============================================================================
1057 //=============================================================================
1058 ADAPT::HOMARD_Boundary_ptr ADAPT_Gen_i::GetBoundary(const char* nomBoundary)
1060 ADAPT::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[nomBoundary];
1061 ASSERT(!CORBA::is_nil(myBoundary));
1062 return ADAPT::HOMARD_Boundary::_duplicate(myBoundary);
1064 //=============================================================================
1065 ADAPT::HOMARD_Cas_ptr ADAPT_Gen_i::GetCase(const char* nomCas)
1067 ADAPT::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
1068 ASSERT(!CORBA::is_nil(myCase));
1069 return ADAPT::HOMARD_Cas::_duplicate(myCase);
1071 //=============================================================================
1072 ADAPT::HOMARD_Hypothesis_ptr ADAPT_Gen_i::GetHypothesis(const char* nomHypothesis)
1074 ADAPT::HOMARD_Hypothesis_var myHypothesis = myStudyContext._mesHypotheses[nomHypothesis];
1075 ASSERT(!CORBA::is_nil(myHypothesis));
1076 return ADAPT::HOMARD_Hypothesis::_duplicate(myHypothesis);
1078 //=============================================================================
1079 ADAPT::HOMARD_Iteration_ptr ADAPT_Gen_i::GetIteration(const char* NomIterationation)
1081 ADAPT::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIterationation];
1082 ASSERT(!CORBA::is_nil(myIteration));
1083 return ADAPT::HOMARD_Iteration::_duplicate(myIteration);
1085 //=============================================================================
1086 ADAPT::HOMARD_YACS_ptr ADAPT_Gen_i::GetYACS(const char* nomYACS)
1088 ADAPT::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
1089 ASSERT(!CORBA::is_nil(myYACS));
1090 return ADAPT::HOMARD_YACS::_duplicate(myYACS);
1092 //=============================================================================
1093 ADAPT::HOMARD_Zone_ptr ADAPT_Gen_i::GetZone(const char* ZoneName)
1095 ADAPT::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
1096 ASSERT(!CORBA::is_nil(myZone));
1097 return ADAPT::HOMARD_Zone::_duplicate(myZone);
1099 //=============================================================================
1100 //=============================================================================
1102 //=============================================================================
1103 //=============================================================================
1105 //=============================================================================
1106 //=============================================================================
1107 void ADAPT_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)
1109 INFOS ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1110 INFOS ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte );
1115 if ( _PublisMeshIN != 0 ) option = 2 ;
1116 ADAPT::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, 0, option) ;
1117 myCase->SetDirName(DirName) ;
1119 myCase->MeshInfo(Qual, Diam, Conn, Tail, Inte) ;
1123 //=============================================================================
1124 //=============================================================================
1126 //=============================================================================
1127 //=============================================================================
1128 // Recuperation des structures par le contexte
1129 //=============================================================================
1130 //=============================================================================
1131 ADAPT::HOMARD_Iteration_ptr ADAPT_Gen_i::LastIteration(const char* nomCas)
1133 ADAPT::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
1134 ASSERT(!CORBA::is_nil(myCase));
1136 ADAPT::HOMARD_Iteration_var myIteration = myCase->LastIteration();
1137 ASSERT(!CORBA::is_nil(myIteration));
1139 return ADAPT::HOMARD_Iteration::_duplicate(myIteration);
1141 //=============================================================================
1142 //=============================================================================
1144 //=============================================================================
1145 //=============================================================================
1146 // Nouvelles structures
1147 //=============================================================================
1148 //=============================================================================
1149 ADAPT::HOMARD_Cas_ptr ADAPT_Gen_i::newCase()
1151 ADAPT::ADAPT_Gen_var engine = POA_ADAPT::ADAPT_Gen::_this();
1152 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
1153 ADAPT::HOMARD_Cas_var aCase = ADAPT::HOMARD_Cas::_narrow(aServant->_this());
1154 return aCase._retn();
1156 //=============================================================================
1157 ADAPT::HOMARD_Hypothesis_ptr ADAPT_Gen_i::newHypothesis()
1159 ADAPT::ADAPT_Gen_var engine = POA_ADAPT::ADAPT_Gen::_this();
1160 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
1161 ADAPT::HOMARD_Hypothesis_var aHypo = ADAPT::HOMARD_Hypothesis::_narrow(aServant->_this());
1162 return aHypo._retn();
1164 //=============================================================================
1165 ADAPT::HOMARD_Iteration_ptr ADAPT_Gen_i::newIteration()
1167 ADAPT::ADAPT_Gen_var engine = POA_ADAPT::ADAPT_Gen::_this();
1168 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
1169 ADAPT::HOMARD_Iteration_var aIter = ADAPT::HOMARD_Iteration::_narrow(aServant->_this());
1170 return aIter._retn();
1172 //=============================================================================
1173 ADAPT::HOMARD_Boundary_ptr ADAPT_Gen_i::newBoundary()
1175 ADAPT::ADAPT_Gen_var engine = POA_ADAPT::ADAPT_Gen::_this();
1176 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
1177 ADAPT::HOMARD_Boundary_var aBoundary = ADAPT::HOMARD_Boundary::_narrow(aServant->_this());
1178 return aBoundary._retn();
1180 //=============================================================================
1181 ADAPT::HOMARD_Zone_ptr ADAPT_Gen_i::newZone()
1183 ADAPT::ADAPT_Gen_var engine = POA_ADAPT::ADAPT_Gen::_this();
1184 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
1185 ADAPT::HOMARD_Zone_var aZone = ADAPT::HOMARD_Zone::_narrow(aServant->_this());
1186 return aZone._retn();
1188 //=============================================================================
1189 ADAPT::HOMARD_YACS_ptr ADAPT_Gen_i::newYACS()
1191 ADAPT::ADAPT_Gen_var engine = POA_ADAPT::ADAPT_Gen::_this();
1192 HOMARD_YACS_i* aServant = new HOMARD_YACS_i(_orb, engine);
1193 ADAPT::HOMARD_YACS_var aYACS = ADAPT::HOMARD_YACS::_narrow(aServant->_this());
1194 return aYACS._retn();
1196 //=============================================================================
1197 //=============================================================================
1199 //=============================================================================
1200 //=============================================================================
1201 // Creation des structures identifiees par leurs noms
1202 //=============================================================================
1203 //=============================================================================
1204 ADAPT::HOMARD_Cas_ptr ADAPT_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
1206 // Creation d'un cas initial
1207 // nomCas : nom du cas a creer
1208 // MeshName, MeshFile : nom et fichier du maillage correspondant
1211 INFOS ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1214 if ( _PublisMeshIN != 0 ) option = 2 ;
1215 ADAPT::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 0, 0, option) ;
1217 // Valeurs par defaut des filtrages
1218 myCase->SetPyram(0);
1220 return ADAPT::HOMARD_Cas::_duplicate(myCase);
1222 //=============================================================================
1223 ADAPT::HOMARD_Cas_ptr ADAPT_Gen_i::CreateCaseFromIteration(const char* nomCas, const char* DirNameStart)
1225 // nomCas : nom du cas a creer
1226 // DirNameStart : nom du répertoire contenant l'iteration de reprise
1229 INFOS ( "CreateCaseFromIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1230 std::string nomDirWork = getenv("PWD") ;
1233 // A. Decodage du point de reprise
1234 // A.1. Controle du répertoire de depart de l'iteration
1235 codret = CHDIR(DirNameStart) ;
1238 SALOME::ExceptionStruct es;
1239 es.type = SALOME::BAD_PARAM;
1240 es.text = "The directory of the iteration does not exist.";
1241 throw SALOME::SALOME_Exception(es);
1244 // A.2. Reperage des fichiers du répertoire de reprise
1245 std::string file_configuration = "" ;
1246 std::string file_maillage_homard = "" ;
1250 struct dirent *dirp;
1251 dp = opendir(DirNameStart);
1252 while ( (dirp = readdir(dp)) != NULL )
1254 std::string file_name(dirp->d_name);
1255 // MESSAGE ( file_name );
1256 bilan = file_name.find("HOMARD.Configuration.") ;
1257 if ( bilan != string::npos ) { file_configuration = file_name ; }
1258 bilan = file_name.find("maill.") ;
1259 if ( bilan != string::npos )
1261 bilan = file_name.find(".hom.med") ;
1262 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1267 HANDLE hFind = INVALID_HANDLE_VALUE;
1268 WIN32_FIND_DATA ffd;
1269 hFind = FindFirstFile(DirNameStart, &ffd);
1270 if (INVALID_HANDLE_VALUE != hFind) {
1271 while (FindNextFile(hFind, &ffd) != 0) {
1272 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1273 std::string file_name(ffd.cFileName);
1274 bilan = file_name.find("HOMARD.Configuration.") ;
1275 if ( bilan != string::npos ) { file_configuration = file_name ; }
1276 bilan = file_name.find("maill.") ;
1277 if ( bilan != string::npos )
1279 bilan = file_name.find(".hom.med") ;
1280 if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1286 MESSAGE ( "==> file_configuration : " << file_configuration ) ;
1287 MESSAGE ( "==> file_maillage_homard : " << file_maillage_homard ) ;
1289 if ( ( file_configuration == "" ) || ( file_maillage_homard == "" ) )
1291 SALOME::ExceptionStruct es;
1292 es.type = SALOME::BAD_PARAM;
1294 if ( file_configuration == "" ) { text = "The configuration file cannot be found." ; }
1295 else { text = "The HOMARD mesh file cannot be found." ; }
1296 es.text = CORBA::string_dup(text.c_str());
1297 throw SALOME::SALOME_Exception(es);
1300 // B. Lecture du fichier de configuration
1301 // ATTENTION : on doit veiller a la coherence entre HomardDriver et CreateCaseFromIteration
1308 // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1309 std::ifstream fichier( file_configuration.c_str() );
1310 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1312 std::string ligne; // variable contenant chaque ligne lue
1313 std::string mot_cle;
1314 std::string argument;
1316 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1317 while ( std::getline( fichier, ligne ) )
1319 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1320 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1321 ligne_bis >> mot_cle ;
1322 // B.2. Des valeurs entieres : le second bloc de la ligne
1323 if ( mot_cle == "NumeIter" )
1325 ligne_bis >> NumeIter ;
1328 // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1329 else if ( ( mot_cle == "TypeConf" ) || ( mot_cle == "TypeElem" ) )
1331 ligne_bis >> argument ;
1333 if ( mot_cle == "TypeConf" )
1335 if ( argument == "conforme" ) { TypeConf = 1 ; }
1336 else if ( argument == "non_conforme_1_noeud" ) { TypeConf = 2 ; }
1337 else if ( argument == "non_conforme_1_arete" ) { TypeConf = 3 ; }
1338 else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1340 else if ( mot_cle == "TypeElem" )
1342 if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1343 else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1346 // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1347 // il faut les supprimer
1348 else if ( ( mot_cle == "CCNoMNP1" ) || ( mot_cle == "CCMaiNP1" ) )
1350 ligne_bis >> argument ;
1351 if ( argument[0] == '"' ) { decalage = 1 ; }
1352 else { decalage = 0 ; }
1353 size_t size = argument.size() + 1 - 2*decalage ;
1355 if ( mot_cle == "CCNoMNP1" )
1357 MeshName = new char[ size ];
1358 strncpy( MeshName, argument.c_str()+decalage, size );
1359 MeshName[size-1] = '\0' ;
1361 else if ( mot_cle == "CCMaiNP1" )
1363 MeshFile = new char[ size ];
1364 strncpy( MeshFile, argument.c_str()+decalage, size );
1365 MeshFile[size-1] = '\0' ;
1369 MESSAGE ( "==> TypeConf : " << TypeConf ) ;
1370 MESSAGE ( "==> MeshName : " << MeshName ) ;
1371 MESSAGE ( "==> MeshFile : " << MeshFile ) ;
1372 MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1373 MESSAGE ( "==> Pyram : " << Pyram ) ;
1377 SALOME::ExceptionStruct es;
1378 es.type = SALOME::BAD_PARAM;
1379 std::string text = "The configuration file cannot be read." ;
1380 es.text = CORBA::string_dup(text.c_str());
1381 throw SALOME::SALOME_Exception(es);
1384 // C. Creation effective du cas
1387 if ( _PublisMeshIN != 0 ) option = 2 ;
1388 ADAPT::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, option) ;
1390 // D. Parametrages lus dans le fichier de configuration
1392 myCase->SetConfType (TypeConf) ;
1393 myCase->SetExtType (TypeExt) ;
1394 myCase->SetPyram (Pyram) ;
1396 // E. Copie du fichier de maillage homard
1397 // E.1. Répertoire associe au cas
1398 char* nomDirCase = myCase->GetDirName() ;
1399 // E.2. Répertoire associe a l'iteration de ce cas
1401 IterName = myCase->GetIter0Name() ;
1402 ADAPT::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1403 char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1404 Iter->SetDirNameLoc(nomDirIter);
1405 std::string nomDirIterTotal ;
1406 nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1408 if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1410 if (_mkdir(nomDirIterTotal.c_str()) != 0)
1413 MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1414 SALOME::ExceptionStruct es;
1415 es.type = SALOME::BAD_PARAM;
1416 std::string text = "The directory for the computation cannot be created." ;
1417 es.text = CORBA::string_dup(text.c_str());
1418 throw SALOME::SALOME_Exception(es);
1420 // E.3. Copie du maillage HOMARD au format MED
1421 codret = CHDIR(DirNameStart) ;
1422 std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1423 MESSAGE ( "commande : " << commande ) ;
1424 codret = system(commande.c_str()) ;
1425 MESSAGE ( "codret : " << codret ) ;
1428 SALOME::ExceptionStruct es;
1429 es.type = SALOME::BAD_PARAM;
1430 es.text = "The starting point for the case cannot be copied into the working directory.";
1431 throw SALOME::SALOME_Exception(es);
1440 CHDIR(nomDirWork.c_str());
1441 return ADAPT::HOMARD_Cas::_duplicate(myCase);
1443 //=============================================================================
1444 ADAPT::HOMARD_Cas_ptr ADAPT_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1446 // nomCas : nom du cas a creer
1447 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1450 INFOS ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1452 std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1454 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1455 ADAPT::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1457 return ADAPT::HOMARD_Cas::_duplicate(myCase);
1459 //=============================================================================
1460 ADAPT::HOMARD_Cas_ptr ADAPT_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1462 // nomCas : nom du cas a creer
1463 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1464 // Number : numero de l'iteration de depart
1467 INFOS ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1470 SALOME::ExceptionStruct es;
1471 es.type = SALOME::BAD_PARAM;
1472 es.text = "The number of iteration must be positive.";
1473 throw SALOME::SALOME_Exception(es);
1477 std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1479 DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1480 ADAPT::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1482 return ADAPT::HOMARD_Cas::_duplicate(myCase);
1484 //=============================================================================
1485 std::string ADAPT_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1487 // Retourne le nom du répertoire ou se trouve l'iteration voulue.
1488 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1489 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1492 MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1493 std::string nomDirWork = getenv("PWD") ;
1494 std::string DirNameStartIter ;
1496 int NumeIterMax = -1 ;
1498 // A.1. Controle du répertoire de depart du cas
1499 codret = CHDIR(DirNameStart) ;
1502 SALOME::ExceptionStruct es;
1503 es.type = SALOME::BAD_PARAM;
1504 es.text = "The directory of the case for the pursuit does not exist.";
1505 throw SALOME::SALOME_Exception(es);
1508 // A.2. Reperage des sous-répertoire du répertoire de reprise
1509 bool existe = false ;
1512 struct dirent *dirp;
1513 dp = opendir(DirNameStart);
1514 while ( (dirp = readdir(dp)) != NULL ) {
1515 std::string DirName_1(dirp->d_name);
1517 HANDLE hFind = INVALID_HANDLE_VALUE;
1518 WIN32_FIND_DATA ffd;
1519 hFind = FindFirstFile(DirNameStart, &ffd);
1520 if (INVALID_HANDLE_VALUE != hFind) {
1521 while (FindNextFile(hFind, &ffd) != 0) {
1522 std::string DirName_1 = "";
1523 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1524 DirName_1 = std::string(ffd.cFileName);
1527 if ( ( DirName_1 != "." ) && ( DirName_1 != ".." ) )
1529 if ( CHDIR(DirName_1.c_str()) == 0 )
1531 // On cherche le fichier de configuration dans ce sous-répertoire
1532 codret = CHDIR(DirNameStart);
1535 struct dirent *dirp_1;
1536 dp_1 = opendir(DirName_1.c_str()) ;
1537 while ( (dirp_1 = readdir(dp_1)) != NULL )
1539 std::string file_name_1(dirp_1->d_name);
1541 HANDLE hFind1 = INVALID_HANDLE_VALUE;
1542 WIN32_FIND_DATA ffd1;
1543 hFind1 = FindFirstFile(DirName_1.c_str(), &ffd1);
1544 while (FindNextFile(hFind1, &ffd1) != 0)
1546 if (ffd1.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1547 std::string file_name_1(ffd1.cFileName);
1549 int bilan = file_name_1.find("HOMARD.Configuration.") ;
1550 if ( bilan != string::npos )
1552 // Decodage du fichier pour trouver le numero d'iteration
1553 CHDIR(DirName_1.c_str()) ;
1555 std::ifstream fichier( file_name_1.c_str() );
1556 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1559 std::string ligne; // variable contenant chaque ligne lue
1560 std::string mot_cle;
1561 // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1562 while ( std::getline( fichier, ligne ) )
1564 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1565 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1566 ligne_bis >> mot_cle ;
1567 if ( mot_cle == "NumeIter" )
1569 ligne_bis >> NumeIter ;
1571 // MESSAGE ( "==> NumeIter : " << NumeIter ) ;
1572 if ( Number == - 1 )
1574 if ( NumeIter >= NumeIterMax )
1576 NumeIterMax = NumeIter ;
1577 DirNameStartIter = DirName_1 ;
1582 if ( NumeIter == Number )
1584 DirNameStartIter = DirName_1 ;
1594 SALOME::ExceptionStruct es;
1595 es.type = SALOME::BAD_PARAM;
1596 std::string text = "The configuration file cannot be read." ;
1597 es.text = CORBA::string_dup(text.c_str());
1598 throw SALOME::SALOME_Exception(es);
1600 CHDIR(DirNameStart) ;
1602 if ( existe ) { break ; }
1609 if ( existe ) { break ; }
1618 CHDIR(nomDirWork.c_str());
1620 if ( ( Number >= 0 && ( !existe ) ) || ( Number < 0 && ( NumeIterMax == -1 ) ) )
1622 SALOME::ExceptionStruct es;
1623 es.type = SALOME::BAD_PARAM;
1624 es.text = "The directory of the iteration does not exist.";
1625 throw SALOME::SALOME_Exception(es);
1629 return DirNameStartIter ;
1631 //=============================================================================
1632 ADAPT::HOMARD_Cas_ptr ADAPT_Gen_i::CreateCase0(const char* nomCas, const char* MeshName, const char* MeshFile, CORBA::Long MeshOption, CORBA::Long NumeIter, CORBA::Long Option)
1634 // nomCas : nom du cas a creer
1635 // MeshName, MeshFile : nom et fichier du maillage correspondant
1636 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1637 // 1 : le maillage fourni peut ne pas exister ==> on continue si absent
1638 // -1 : le maillage n'est pas fourni
1639 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1640 // Option : multiple de nombres premiers
1641 // 1 : aucune option
1642 // x2 : publication du maillage dans SMESH
1644 MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1645 MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1646 MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1652 // A.2. Controle du nom :
1653 if ((myStudyContext._mesCas).find(nomCas)!=(myStudyContext._mesCas).end())
1655 SALOME::ExceptionStruct es;
1656 es.type = SALOME::BAD_PARAM;
1657 es.text = "This case has already been defined.";
1658 throw SALOME::SALOME_Exception(es);
1662 // A.3. Controle du fichier du maillage
1663 int existeMeshFile ;
1664 if ( MeshOption >= 0 )
1666 existeMeshFile = MEDFileExist ( MeshFile ) ;
1667 MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1668 if ( ( existeMeshFile == 0 ) && ( MeshOption == 0 ) )
1670 SALOME::ExceptionStruct es;
1671 es.type = SALOME::BAD_PARAM;
1672 es.text = "The mesh file does not exist.";
1673 throw SALOME::SALOME_Exception(es);
1677 else { existeMeshFile = 0 ; }
1679 // B. Creation de l'objet cas et publication
1680 // MESSAGE ( "CreateCase0 : Creation de l'objet" );
1681 ADAPT::HOMARD_Cas_var myCase = newCase();
1682 myCase->SetName(nomCas);
1683 SALOMEDS::SObject_var aSO;
1684 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myCase, nomCas);
1685 myStudyContext._mesCas[nomCas] = myCase;
1687 // C. Caracteristiques du maillage
1688 if ( existeMeshFile != 0 )
1690 // Les valeurs extremes des coordonnées
1691 // MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnées" );
1692 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1693 ADAPT::extrema_var aSeq = new ADAPT::extrema() ;
1694 if (LesExtremes.size()!=10) { return 0; }
1696 for (int i =0 ; i< LesExtremes.size() ; i++)
1697 aSeq[i]=LesExtremes[i] ;
1698 myCase->SetBoundingBox(aSeq) ;
1700 // MESSAGE ( "CreateCase0 : Les groupes" );
1701 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile) ;
1702 ADAPT::ListGroupType_var aSeqGroupe = new ADAPT::ListGroupType ;
1703 aSeqGroupe->length(LesGroupes.size());
1704 std::set<std::string>::const_iterator it ;
1706 for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1707 aSeqGroupe[i++]=(*it).c_str() ;
1708 myCase->SetGroups(aSeqGroupe) ;
1711 // D. L'iteration initiale du cas
1712 MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1713 // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1714 // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1716 std::string NomIteration = std::string(MeshName) ;
1717 while ( (myStudyContext._mesIterations).find(NomIteration) != (myStudyContext._mesIterations.end()) )
1719 std::ostringstream nom;
1720 nom << MeshName << monNum;
1721 NomIteration = nom.str();
1724 MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1726 // D.2. Creation de l'iteration
1727 ADAPT::HOMARD_Iteration_var anIter = newIteration();
1728 myStudyContext._mesIterations[NomIteration] = anIter;
1729 anIter->SetName(NomIteration.c_str());
1730 AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1732 // D.4. Maillage correspondant
1733 if ( existeMeshFile != 0 )
1735 anIter->SetMeshFile(MeshFile);
1736 if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1738 anIter->SetMeshName(MeshName);
1740 // D.5. Numero d'iteration
1741 anIter->SetNumber(NumeIter);
1744 SetEtatIter(NomIteration.c_str(), -NumeIter);
1747 return ADAPT::HOMARD_Cas::_duplicate(myCase);
1749 //=============================================================================
1750 ADAPT::HOMARD_Hypothesis_ptr ADAPT_Gen_i::CreateHypothesis(const char* nomHypothesis)
1752 INFOS ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1755 // A. Controle du nom :
1756 if ((myStudyContext._mesHypotheses).find(nomHypothesis) != (myStudyContext._mesHypotheses).end())
1758 SALOME::ExceptionStruct es;
1759 es.type = SALOME::BAD_PARAM;
1760 es.text = "This hypothesis has already been defined.";
1761 throw SALOME::SALOME_Exception(es);
1765 // B. Creation de l'objet
1766 ADAPT::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1767 if (CORBA::is_nil(myHypothesis))
1769 SALOME::ExceptionStruct es;
1770 es.type = SALOME::BAD_PARAM;
1771 es.text = "Unable to create the hypothesis";
1772 throw SALOME::SALOME_Exception(es);
1775 myHypothesis->SetName(nomHypothesis);
1777 // C. Enregistrement
1778 myStudyContext._mesHypotheses[nomHypothesis] = myHypothesis;
1780 SALOMEDS::SObject_var aSO;
1781 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myHypothesis, nomHypothesis);
1783 // D. Valeurs par defaut des options avancees
1784 myHypothesis->SetNivMax(-1);
1785 myHypothesis->SetDiamMin(-1.0);
1786 myHypothesis->SetAdapInit(0);
1787 myHypothesis->SetExtraOutput(1);
1789 return ADAPT::HOMARD_Hypothesis::_duplicate(myHypothesis);
1792 //=============================================================================
1793 ADAPT::HOMARD_Iteration_ptr ADAPT_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1794 //=============================================================================
1796 INFOS ("CreateIteration : NomIteration = " << NomIteration << ", nomIterParent = " << nomIterParent);
1799 ADAPT::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterParent];
1800 if (CORBA::is_nil(myIterationParent))
1802 SALOME::ExceptionStruct es;
1803 es.type = SALOME::BAD_PARAM;
1804 es.text = "The parent iteration is not defined.";
1805 throw SALOME::SALOME_Exception(es);
1809 const char* nomCas = myIterationParent->GetCaseName();
1810 MESSAGE ("CreateIteration : nomCas = " << nomCas);
1811 ADAPT::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
1812 if (CORBA::is_nil(myCase))
1814 SALOME::ExceptionStruct es;
1815 es.type = SALOME::BAD_PARAM;
1816 es.text = "Invalid case context";
1817 throw SALOME::SALOME_Exception(es);
1820 const char* nomDirCase = myCase->GetDirName();
1822 // Controle du nom :
1823 if ((myStudyContext._mesIterations).find(NomIteration)!=(myStudyContext._mesIterations).end())
1825 SALOME::ExceptionStruct es;
1826 es.type = SALOME::BAD_PARAM;
1827 es.text = "This iteration has already been defined.";
1828 throw SALOME::SALOME_Exception(es);
1832 ADAPT::HOMARD_Iteration_var myIteration = newIteration();
1833 if (CORBA::is_nil(myIteration))
1835 SALOME::ExceptionStruct es;
1836 es.type = SALOME::BAD_PARAM;
1837 es.text = "Unable to create the iteration";
1838 throw SALOME::SALOME_Exception(es);
1841 myStudyContext._mesIterations[std::string(NomIteration)] = myIteration;
1842 // Nom de l'iteration et du maillage
1843 myIteration->SetName(NomIteration);
1844 myIteration->SetMeshName(NomIteration);
1845 myIteration->SetState(1);
1847 int numero = myIterationParent->GetNumber() + 1;
1848 myIteration->SetNumber(numero);
1850 // Nombre d'iterations deja connues pour le cas, permettant
1851 // la creation d'un sous-répertoire unique
1852 int nbitercase = myCase->GetNumberofIter();
1853 char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1854 myIteration->SetDirNameLoc(nomDirIter);
1856 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1857 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1858 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1859 // situation la plus frequente.
1860 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1861 // le nombre d'iterations du cas permet d'eviter les collisions.
1863 if ( nbitercase < 100 ) { jaux = 2 ; }
1864 else if ( nbitercase < 1000 ) { jaux = 3 ; }
1865 else if ( nbitercase < 10000 ) { jaux = 4 ; }
1866 else if ( nbitercase < 100000 ) { jaux = 5 ; }
1868 std::ostringstream iaux ;
1869 iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1870 std::stringstream MeshFile;
1871 MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1872 myIteration->SetMeshFile(MeshFile.str().c_str());
1874 // Association avec le cas
1875 std::string label = "IterationHomard_" + std::string(nomIterParent);
1876 AssociateCaseIter(nomCas, NomIteration, label.c_str());
1877 // Lien avec l'iteration precedente
1878 myIterationParent->LinkNextIteration(NomIteration);
1879 myIteration->SetIterParentName(nomIterParent);
1880 // Gestion de l'arbre d'etudes
1881 SALOMEDS::SObject_var aIterSOParent = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIterationParent)));
1882 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
1883 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
1884 aStudyBuilder->NewCommand();
1885 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
1886 aStudyBuilder->Addreference(aSubSO, aIterSOParent);
1887 aStudyBuilder->CommitCommand();
1889 return ADAPT::HOMARD_Iteration::_duplicate(myIteration);
1891 //=============================================================================
1892 ADAPT::HOMARD_Boundary_ptr ADAPT_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1894 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1897 // Controle du nom :
1898 if ((myStudyContext._mesBoundarys).find(BoundaryName)!=(myStudyContext._mesBoundarys).end())
1900 MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1901 SALOME::ExceptionStruct es;
1902 es.type = SALOME::BAD_PARAM;
1903 es.text = "This boundary has already been defined";
1904 throw SALOME::SALOME_Exception(es);
1908 ADAPT::HOMARD_Boundary_var myBoundary = newBoundary();
1909 myBoundary->SetName(BoundaryName);
1910 myBoundary->SetType(BoundaryType);
1912 myStudyContext._mesBoundarys[BoundaryName] = myBoundary;
1914 SALOMEDS::SObject_var aSO;
1915 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myBoundary, BoundaryName);
1917 return ADAPT::HOMARD_Boundary::_duplicate(myBoundary);
1919 //=============================================================================
1920 ADAPT::HOMARD_Boundary_ptr ADAPT_Gen_i::CreateBoundaryCAO(const char* BoundaryName, const char* CAOFile)
1922 INFOS ("CreateBoundaryCAO : BoundaryName = " << BoundaryName << ", CAOFile = " << CAOFile );
1923 ADAPT::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, -1);
1924 myBoundary->SetDataFile( CAOFile ) ;
1926 return ADAPT::HOMARD_Boundary::_duplicate(myBoundary);
1928 //=============================================================================
1929 ADAPT::HOMARD_Boundary_ptr ADAPT_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1931 INFOS ("CreateBoundaryDi : BoundaryName = " << BoundaryName << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1932 ADAPT::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1933 myBoundary->SetDataFile( MeshFile ) ;
1934 myBoundary->SetMeshName( MeshName ) ;
1936 return ADAPT::HOMARD_Boundary::_duplicate(myBoundary);
1938 //=============================================================================
1939 ADAPT::HOMARD_Boundary_ptr ADAPT_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1940 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1941 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1942 CORBA::Double Rayon)
1944 INFOS ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
1946 SALOME::ExceptionStruct es;
1949 { es.text = "The radius must be positive." ;
1951 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1952 if ( daux < 0.0000001 )
1953 { es.text = "The axis must be a non 0 vector." ;
1957 es.type = SALOME::BAD_PARAM;
1958 throw SALOME::SALOME_Exception(es);
1962 ADAPT::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1963 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1965 return ADAPT::HOMARD_Boundary::_duplicate(myBoundary) ;
1967 //=============================================================================
1968 ADAPT::HOMARD_Boundary_ptr ADAPT_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1969 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1970 CORBA::Double Rayon)
1972 INFOS ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
1974 SALOME::ExceptionStruct es;
1977 { es.text = "The radius must be positive." ;
1981 es.type = SALOME::BAD_PARAM;
1982 throw SALOME::SALOME_Exception(es);
1986 ADAPT::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1987 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1989 return ADAPT::HOMARD_Boundary::_duplicate(myBoundary) ;
1991 //=============================================================================
1992 ADAPT::HOMARD_Boundary_ptr ADAPT_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
1993 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
1994 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
1996 INFOS ("CreateBoundaryConeA : BoundaryName = " << BoundaryName ) ;
1998 SALOME::ExceptionStruct es;
2000 if ( Angle <= 0.0 || Angle >= 90.0 )
2001 { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
2003 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2004 if ( daux < 0.0000001 )
2005 { es.text = "The axis must be a non 0 vector." ;
2009 es.type = SALOME::BAD_PARAM;
2010 throw SALOME::SALOME_Exception(es);
2014 ADAPT::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
2015 myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
2017 return ADAPT::HOMARD_Boundary::_duplicate(myBoundary) ;
2019 //=============================================================================
2020 ADAPT::HOMARD_Boundary_ptr ADAPT_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
2021 CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
2022 CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
2024 INFOS ("CreateBoundaryConeR : BoundaryName = " << BoundaryName ) ;
2026 SALOME::ExceptionStruct es;
2028 if ( Rayon1 < 0.0 || Rayon2 < 0.0 )
2029 { es.text = "The radius must be positive." ;
2031 double daux = fabs(Rayon2-Rayon1) ;
2032 if ( daux < 0.0000001 )
2033 { es.text = "The radius must be different." ;
2035 daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
2036 if ( daux < 0.0000001 )
2037 { es.text = "The centers must be different." ;
2041 es.type = SALOME::BAD_PARAM;
2042 throw SALOME::SALOME_Exception(es);
2046 ADAPT::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
2047 myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
2049 return ADAPT::HOMARD_Boundary::_duplicate(myBoundary) ;
2051 //=============================================================================
2052 ADAPT::HOMARD_Boundary_ptr ADAPT_Gen_i::CreateBoundaryTorus(const char* BoundaryName,
2053 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2054 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2055 CORBA::Double RayonRev, CORBA::Double RayonPri)
2057 INFOS ("CreateBoundaryTorus : BoundaryName = " << BoundaryName ) ;
2059 SALOME::ExceptionStruct es;
2061 if ( ( RayonRev <= 0.0 ) || ( RayonPri <= 0.0 ) )
2062 { es.text = "The radius must be positive." ;
2064 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2065 if ( daux < 0.0000001 )
2066 { es.text = "The axis must be a non 0 vector." ;
2070 es.type = SALOME::BAD_PARAM;
2071 throw SALOME::SALOME_Exception(es);
2075 ADAPT::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 5) ;
2076 myBoundary->SetTorus( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, RayonRev, RayonPri ) ;
2078 return ADAPT::HOMARD_Boundary::_duplicate(myBoundary) ;
2080 //=============================================================================
2081 ADAPT::HOMARD_Zone_ptr ADAPT_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
2083 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
2086 // Controle du nom :
2087 if ((myStudyContext._mesZones).find(ZoneName)!=(myStudyContext._mesZones).end())
2089 SALOME::ExceptionStruct es;
2090 es.type = SALOME::BAD_PARAM;
2091 es.text = "This zone has already been defined";
2092 throw SALOME::SALOME_Exception(es);
2096 ADAPT::HOMARD_Zone_var myZone = newZone();
2097 myZone->SetName(ZoneName);
2098 myZone->SetType(ZoneType);
2100 myStudyContext._mesZones[ZoneName] = myZone;
2102 SALOMEDS::SObject_var aSO;
2103 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myZone, ZoneName);
2105 return ADAPT::HOMARD_Zone::_duplicate(myZone);
2107 //=============================================================================
2108 ADAPT::HOMARD_Zone_ptr ADAPT_Gen_i::CreateZoneBox(const char* ZoneName,
2109 CORBA::Double Xmini, CORBA::Double Xmaxi,
2110 CORBA::Double Ymini, CORBA::Double Ymaxi,
2111 CORBA::Double Zmini, CORBA::Double Zmaxi)
2113 INFOS ("CreateZoneBox : ZoneName = " << ZoneName ) ;
2115 SALOME::ExceptionStruct es;
2117 if ( Xmini > Xmaxi )
2118 { es.text = "The X coordinates are not coherent." ;
2120 if ( Ymini > Ymaxi )
2121 { es.text = "The Y coordinates are not coherent." ;
2123 if ( Zmini > Zmaxi )
2124 { es.text = "The Z coordinates are not coherent." ;
2128 es.type = SALOME::BAD_PARAM;
2129 throw SALOME::SALOME_Exception(es);
2133 ADAPT::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
2134 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2136 return ADAPT::HOMARD_Zone::_duplicate(myZone) ;
2138 //=============================================================================
2139 ADAPT::HOMARD_Zone_ptr ADAPT_Gen_i::CreateZoneSphere(const char* ZoneName,
2140 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
2142 INFOS ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
2144 SALOME::ExceptionStruct es;
2147 { es.text = "The radius must be positive." ;
2151 es.type = SALOME::BAD_PARAM;
2152 throw SALOME::SALOME_Exception(es);
2156 ADAPT::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
2157 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2159 return ADAPT::HOMARD_Zone::_duplicate(myZone) ;
2161 //=============================================================================
2162 ADAPT::HOMARD_Zone_ptr ADAPT_Gen_i::CreateZoneCylinder(const char* ZoneName,
2163 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2164 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2165 CORBA::Double Rayon, CORBA::Double Haut)
2167 INFOS ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
2169 SALOME::ExceptionStruct es;
2172 { es.text = "The radius must be positive." ;
2174 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2175 if ( daux < 0.0000001 )
2176 { es.text = "The axis must be a non 0 vector." ;
2179 { es.text = "The height must be positive." ;
2183 es.type = SALOME::BAD_PARAM;
2184 throw SALOME::SALOME_Exception(es);
2188 ADAPT::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
2189 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
2191 return ADAPT::HOMARD_Zone::_duplicate(myZone) ;
2193 //=============================================================================
2194 ADAPT::HOMARD_Zone_ptr ADAPT_Gen_i::CreateZonePipe(const char* ZoneName,
2195 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2196 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2197 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
2199 INFOS ("CreateZonePipe : ZoneName = " << ZoneName ) ;
2201 SALOME::ExceptionStruct es;
2203 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2204 { es.text = "The radius must be positive." ;
2206 double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2207 if ( daux < 0.0000001 )
2208 { es.text = "The axis must be a non 0 vector." ;
2211 { es.text = "The height must be positive." ;
2213 if ( Rayon <= Rayonint )
2214 { es.text = "The external radius must be higher than the internal radius." ;
2218 es.type = SALOME::BAD_PARAM;
2219 throw SALOME::SALOME_Exception(es);
2223 ADAPT::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
2224 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
2226 return ADAPT::HOMARD_Zone::_duplicate(myZone) ;
2228 //=============================================================================
2229 ADAPT::HOMARD_Zone_ptr ADAPT_Gen_i::CreateZoneBox2D(const char* ZoneName,
2230 CORBA::Double Umini, CORBA::Double Umaxi,
2231 CORBA::Double Vmini, CORBA::Double Vmaxi,
2234 INFOS ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
2235 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
2236 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
2237 // MESSAGE ("Orient = " << Orient ) ;
2239 SALOME::ExceptionStruct es;
2241 if ( Umini > Umaxi )
2242 { es.text = "The first coordinates are not coherent." ;
2244 if ( Vmini > Vmaxi )
2245 { es.text = "The second coordinates are not coherent." ;
2247 if ( Orient < 1 || Orient > 3 )
2248 { es.text = "The orientation must be 1, 2 or 3." ;
2252 es.type = SALOME::BAD_PARAM;
2253 throw SALOME::SALOME_Exception(es);
2257 double Xmini, Xmaxi ;
2258 double Ymini, Ymaxi ;
2259 double Zmini, Zmaxi ;
2267 else if ( Orient == 2 )
2274 else if ( Orient == 3 )
2281 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2283 ADAPT::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2284 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2286 return ADAPT::HOMARD_Zone::_duplicate(myZone) ;
2288 //=============================================================================
2289 ADAPT::HOMARD_Zone_ptr ADAPT_Gen_i::CreateZoneDisk(const char* ZoneName,
2290 CORBA::Double Ucentre, CORBA::Double Vcentre,
2291 CORBA::Double Rayon,
2294 INFOS ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
2296 SALOME::ExceptionStruct es;
2299 { es.text = "The radius must be positive." ;
2301 if ( Orient < 1 || Orient > 3 )
2302 { es.text = "The orientation must be 1, 2 or 3." ;
2306 es.type = SALOME::BAD_PARAM;
2307 throw SALOME::SALOME_Exception(es);
2315 { Xcentre = Ucentre ;
2318 else if ( Orient == 2 )
2321 Zcentre = Vcentre ; }
2322 else if ( Orient == 3 )
2323 { Xcentre = Vcentre ;
2325 Zcentre = Ucentre ; }
2326 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2328 ADAPT::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2329 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2331 return ADAPT::HOMARD_Zone::_duplicate(myZone) ;
2333 //=============================================================================
2334 ADAPT::HOMARD_Zone_ptr ADAPT_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2335 CORBA::Double Ucentre, CORBA::Double Vcentre,
2336 CORBA::Double Rayon, CORBA::Double Rayonint,
2339 INFOS ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
2341 SALOME::ExceptionStruct es;
2343 if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2344 { es.text = "The radius must be positive." ;
2346 if ( Orient < 1 || Orient > 3 )
2347 { es.text = "The orientation must be 1, 2 or 3." ;
2349 if ( Rayon <= Rayonint )
2350 { es.text = "The external radius must be higher than the internal radius." ;
2354 es.type = SALOME::BAD_PARAM;
2355 throw SALOME::SALOME_Exception(es);
2363 { Xcentre = Ucentre ;
2366 else if ( Orient == 2 )
2369 Zcentre = Vcentre ; }
2370 else if ( Orient == 3 )
2371 { Xcentre = Vcentre ;
2373 Zcentre = Ucentre ; }
2374 else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2376 ADAPT::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2377 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2379 return ADAPT::HOMARD_Zone::_duplicate(myZone) ;
2381 //=============================================================================
2382 //=============================================================================
2387 //=============================================================================
2388 //=============================================================================
2389 // Traitement d'une iteration
2390 // etatMenage = 1 : destruction du répertoire d'execution
2391 // modeHOMARD = 1 : adaptation
2392 // != 1 : information avec les options modeHOMARD
2393 // Option1 >0 : appel depuis python
2394 // <0 : appel depuis GUI
2395 // Option2 : multiple de nombres premiers
2396 // 1 : aucune option
2397 // x2 : publication du maillage dans SMESH
2398 //=============================================================================
2399 CORBA::Long ADAPT_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2401 INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2406 // A.1. L'objet iteration
2407 ADAPT::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIteration];
2408 ASSERT(!CORBA::is_nil(myIteration));
2410 // A.2. Controle de la possibilite d'agir
2411 // A.2.1. Etat de l'iteration
2412 int etat = myIteration->GetState();
2413 MESSAGE ( "etat = "<<etat );
2414 // A.2.2. On ne calcule pas l'iteration initiale, ni une iteration deja calculee
2415 if ( modeHOMARD == 1 )
2419 SALOME::ExceptionStruct es;
2420 es.type = SALOME::BAD_PARAM;
2421 es.text = "This iteration is the first of the case and cannot be computed.";
2422 throw SALOME::SALOME_Exception(es);
2425 else if ( ( etat == 2 ) & ( modeHOMARD == 1 ) )
2427 SALOME::ExceptionStruct es;
2428 es.type = SALOME::BAD_PARAM;
2429 es.text = "This iteration is already computed.";
2430 throw SALOME::SALOME_Exception(es);
2434 // A.2.3. On n'analyse pas une iteration non calculee
2439 SALOME::ExceptionStruct es;
2440 es.type = SALOME::BAD_PARAM;
2441 es.text = "This iteration is not computed.";
2442 throw SALOME::SALOME_Exception(es);
2447 // A.3. Numero de l'iteration
2448 // siterp1 : numero de l'iteration a traiter
2450 // siter : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2451 // Ou si information :
2453 int NumeIter = myIteration->GetNumber();
2454 std::string siterp1 ;
2455 std::stringstream saux1 ;
2457 siterp1 = saux1.str() ;
2458 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2461 if ( modeHOMARD==1 )
2463 std::stringstream saux0 ;
2464 int iaux = max(0, NumeIter-1) ;
2466 siter = saux0.str() ;
2467 if (NumeIter < 11) { siter = "0" + siter ; }
2470 { siter = siterp1 ; }
2473 const char* nomCas = myIteration->GetCaseName();
2474 ADAPT::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
2475 ASSERT(!CORBA::is_nil(myCase));
2477 // B. Les répertoires
2478 // B.1. Le répertoire courant
2479 std::string nomDirWork = getenv("PWD") ;
2480 // B.2. Le sous-répertoire de l'iteration a traiter
2481 char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2482 MESSAGE( ". DirCompute = " << DirCompute );
2484 // C. Le fichier des messages
2485 // C.1. Le deroulement de l'execution de HOMARD
2486 std::string LogFile = DirCompute ;
2487 LogFile += "/Liste" ;
2488 if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2490 MESSAGE (". LogFile = " << LogFile);
2491 if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2492 // C.2. Le bilan de l'analyse du maillage
2493 std::string FileInfo = DirCompute ;
2495 if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2497 { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2498 else { FileInfo += "info_ap" ; }
2500 FileInfo += "." + siterp1 + ".bilan" ;
2501 myIteration->SetFileInfo(FileInfo.c_str());
2503 // D. On passe dans le répertoire de l'iteration a calculer
2504 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2507 // E. Les données de l'exécution HOMARD
2508 // E.1. L'objet du texte du fichier de configuration
2509 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2510 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2512 // E.2. Le maillage associe a l'iteration
2513 const char* NomMesh = myIteration->GetMeshName();
2514 MESSAGE ( ". NomMesh = " << NomMesh );
2515 const char* MeshFile = myIteration->GetMeshFile();
2516 MESSAGE ( ". MeshFile = " << MeshFile );
2518 // E.3. Les données du traitement HOMARD
2520 if ( modeHOMARD == 1 )
2523 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2524 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2525 codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2529 InvalideIterInfo(NomIteration);
2530 myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2532 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2533 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2534 myDriver->CreeFichierDonn();
2537 // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2538 int BoundaryOption = DriverTexteBoundary(myCase, myDriver) ;
2540 // E.5. Ecriture du texte dans le fichier
2541 MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2543 { myDriver->CreeFichier(); }
2547 int codretexec = 1789 ;
2550 codretexec = myDriver->ExecuteHomard(Option1);
2552 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2553 // En mode adaptation, on ajuste l'etat de l'iteration
2554 if ( modeHOMARD == 1 )
2556 if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2557 else { SetEtatIter(NomIteration,1); }
2558 // GERALD -- QMESSAGE BOX
2562 // H. Gestion des resultats
2565 std::string Commentaire ;
2566 // H.1. Le fichier des messages, dans tous les cas
2567 Commentaire = "log" ;
2568 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2569 else { Commentaire += "Info" ; }
2570 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2572 // H.2. Si tout s'est bien passe :
2573 if (codretexec == 0)
2575 // H.2.1. Le fichier de bilan
2576 Commentaire = "Summary" ;
2577 if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2578 else { Commentaire += "Info" ; }
2579 PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2580 // H.2.2. Le fichier de maillage obtenu
2581 if ( modeHOMARD == 1 )
2583 std::stringstream saux0 ;
2584 Commentaire = "Mesh" ;
2585 Commentaire += " " + siterp1 ;
2586 PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2587 if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2590 // H.3 Message d'erreur
2591 if (codretexec != 0)
2593 std::string text = "" ;
2594 // Message d'erreur en cas de probleme en adaptation
2595 if ( modeHOMARD == 1 )
2597 text = "Error during the adaptation.\n" ;
2598 bool stopvu = false ;
2599 std::ifstream fichier( LogFile.c_str() );
2600 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
2602 std::string ligne; // variable contenant chaque ligne lue
2603 while ( std::getline( fichier, ligne ) )
2607 { text += ligne+ "\n"; }
2610 int position = ligne.find( "===== HOMARD ===== STOP =====" ) ;
2611 if ( position > 0 ) { stopvu = true ; }
2616 text += "\n\nSee the file " + LogFile + "\n" ;
2618 SALOME::ExceptionStruct es;
2619 es.type = SALOME::BAD_PARAM;
2620 es.text = CORBA::string_dup(text.c_str());
2621 throw SALOME::SALOME_Exception(es);
2623 // En mode information, on force le succes pour pouvoir consulter le fichier log
2624 if ( modeHOMARD != 1 ) { codretexec = 0 ; }
2628 // I. Menage et retour dans le répertoire du cas
2632 MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2634 CHDIR(nomDirWork.c_str());
2637 // J. Suivi de la frontière CAO
2638 // std::cout << "- codret : " << codret << std::endl;
2639 // std::cout << "- modeHOMARD : " << modeHOMARD << std::endl;
2640 // std::cout << "- BoundaryOption : " << BoundaryOption << std::endl;
2641 // std::cout << "- codretexec : " << codretexec << std::endl;
2644 if ( ( modeHOMARD == 1 ) && ( BoundaryOption % 5 == 0 ) && (codretexec == 0) )
2646 INFOS ( "Suivi de frontière CAO" );
2647 codret = ComputeCAO(myCase, myIteration, Option1, Option2) ;
2653 //=============================================================================
2654 // Calcul d'une iteration : partie spécifique à l'adaptation
2655 //=============================================================================
2656 CORBA::Long ADAPT_Gen_i::ComputeAdap(ADAPT::HOMARD_Cas_var myCase, ADAPT::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage, HomardDriver* myDriver, CORBA::Long Option1, CORBA::Long Option2)
2658 MESSAGE ( "ComputeAdap avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2663 // Numero de l'iteration
2664 int NumeIter = myIteration->GetNumber();
2665 std::stringstream saux0 ;
2666 saux0 << NumeIter-1 ;
2667 std::string siter = saux0.str() ;
2668 if (NumeIter < 11) { siter = "0" + siter ; }
2670 // A.2. On verifie qu il y a une hypothese (erreur improbable);
2671 const char* nomHypo = myIteration->GetHypoName();
2672 if (std::string(nomHypo) == std::string(""))
2674 SALOME::ExceptionStruct es;
2675 es.type = SALOME::BAD_PARAM;
2676 es.text = "This iteration does not have any associated hypothesis.";
2677 throw SALOME::SALOME_Exception(es);
2680 ADAPT::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
2681 ASSERT(!CORBA::is_nil(myHypo));
2683 // B. L'iteration parent
2684 const char* nomIterationParent = myIteration->GetIterParentName();
2685 ADAPT::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterationParent];
2686 ASSERT(!CORBA::is_nil(myIterationParent));
2687 // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2688 if ( myIterationParent->GetState() == 1 )
2691 int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2694 // GERALD -- QMESSAGE BOX
2695 VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2699 // C. Le sous-répertoire de l'iteration precedente
2700 char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2701 MESSAGE( ". DirComputePa = " << DirComputePa );
2703 // D. Les données de l'adaptation HOMARD
2704 // D.1. Le type de conformite
2705 int ConfType = myCase->GetConfType();
2706 MESSAGE ( ". ConfType = " << ConfType );
2708 // D.1. Le type externe
2709 int ExtType = myCase->GetExtType();
2710 MESSAGE ( ". ExtType = " << ExtType );
2712 // D.3. Le maillage de depart
2713 const char* NomMeshParent = myIterationParent->GetMeshName();
2714 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2715 const char* MeshFileParent = myIterationParent->GetMeshFile();
2716 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2718 // D.4. Le maillage associe a l'iteration
2719 const char* MeshFile = myIteration->GetMeshFile();
2720 MESSAGE ( ". MeshFile = " << MeshFile );
2721 FILE *file = fopen(MeshFile,"r");
2725 if (etatMenage == 0)
2727 SALOME::ExceptionStruct es;
2728 es.type = SALOME::BAD_PARAM;
2729 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2730 es.text = CORBA::string_dup(text.c_str());
2731 throw SALOME::SALOME_Exception(es);
2736 std::string commande = "rm -f " + std::string(MeshFile);
2737 codret = system(commande.c_str());
2740 SALOME::ExceptionStruct es;
2741 es.type = SALOME::BAD_PARAM;
2742 es.text = "The mesh file cannot be deleted.";
2743 throw SALOME::SALOME_Exception(es);
2749 // D.5. Les types de raffinement et de deraffinement
2750 // Les appels corba sont lourds, il vaut mieux les grouper
2751 ADAPT::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2752 ASSERT(ListTypes->length() == 3);
2753 int TypeAdap = (*ListTypes)[0];
2754 int TypeRaff = (*ListTypes)[1];
2755 int TypeDera = (*ListTypes)[2];
2756 // MESSAGE ( ". TypeAdap = " << TypeAdap << ", TypeRaff = " << TypeRaff << ", TypeDera = " << TypeDera );
2758 // E. Texte du fichier de configuration
2759 // E.1. Incontournables du texte
2760 myDriver->TexteAdap(ExtType);
2762 myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2763 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2764 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2766 // E.2. Ajout des informations liees aux zones eventuelles
2767 if ( TypeAdap == 0 )
2768 { DriverTexteZone(myHypo, myDriver) ; }
2770 // E.3. Ajout des informations liees aux champs eventuels
2771 if ( TypeAdap == 1 )
2772 { DriverTexteField(myIteration, myHypo, myDriver) ; }
2774 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2775 ADAPT::ListGroupType* listeGroupes = myHypo->GetGroups();
2776 int numberOfGroups = listeGroupes->length();
2777 MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2778 if (numberOfGroups > 0)
2780 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2782 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2783 MESSAGE( "... GroupName = " << GroupName );
2784 myDriver->TexteGroup(GroupName);
2788 // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2789 DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2791 // E.6. Ajout des options avancees
2792 int Pyram = myCase->GetPyram();
2793 MESSAGE ( ". Pyram = " << Pyram );
2794 int NivMax = myHypo->GetNivMax();
2795 MESSAGE ( ". NivMax = " << NivMax );
2796 double DiamMin = myHypo->GetDiamMin() ;
2797 MESSAGE ( ". DiamMin = " << DiamMin );
2798 int AdapInit = myHypo->GetAdapInit();
2799 MESSAGE ( ". AdapInit = " << AdapInit );
2800 int ExtraOutput = myHypo->GetExtraOutput();
2801 MESSAGE ( ". ExtraOutput = " << ExtraOutput );
2802 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, ExtraOutput);
2804 // E.7. Ajout des informations sur le deroulement de l'execution
2805 int MessInfo = myIteration->GetInfoCompute();
2806 MESSAGE ( ". MessInfo = " << MessInfo );
2807 myDriver->TexteInfoCompute(MessInfo);
2811 //=============================================================================
2812 // Calcul d'une iteration : partie spécifique au suivi de frontière CAO
2813 //=============================================================================
2814 CORBA::Long ADAPT_Gen_i::ComputeCAO(ADAPT::HOMARD_Cas_var myCase, ADAPT::HOMARD_Iteration_var myIteration, CORBA::Long Option1, CORBA::Long Option2)
2816 MESSAGE ( "ComputeCAO avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2821 // A.2. Le sous-répertoire de l'iteration en cours de traitement
2822 char* DirCompute = myIteration->GetDirName();
2823 // A.3. Le maillage résultat de l'iteration en cours de traitement
2824 char* MeshFile = myIteration->GetMeshFile();
2826 // B. Les données pour FrontTrack
2827 // B.1. Le maillage à modifier
2828 const std::string theInputMedFile = MeshFile;
2829 MESSAGE ( ". theInputMedFile = " << theInputMedFile );
2831 // B.2. Le maillage après modification : fichier identique
2832 const std::string theOutputMedFile = MeshFile ;
2833 MESSAGE ( ". theOutputMedFile = " << theInputMedFile );
2835 // B.3. La liste des fichiers contenant les numéros des noeuds à bouger
2836 std::vector< std::string > theInputNodeFiles ;
2837 MESSAGE ( ". DirCompute = " << DirCompute );
2842 struct dirent *dirp;
2843 dp = opendir(DirCompute);
2844 while ( (dirp = readdir(dp)) != NULL )
2846 std::string file_name(dirp->d_name);
2847 bilan = file_name.find("fr") ;
2848 if ( bilan != string::npos )
2850 std::stringstream filename_total ;
2851 filename_total << DirCompute << "/" << file_name ;
2852 theInputNodeFiles.push_back(filename_total.str()) ;
2857 HANDLE hFind = INVALID_HANDLE_VALUE;
2858 WIN32_FIND_DATA ffd;
2859 hFind = FindFirstFile(DirNameStart, &ffd);
2860 if (INVALID_HANDLE_VALUE != hFind) {
2861 while (FindNextFile(hFind, &ffd) != 0) {
2862 std::string file_name(ffd.cFileName);
2863 bilan = file_name.find("fr") ;
2864 if ( bilan != string::npos )
2866 std::stringstream filename_total ;
2867 filename_total << DirCompute << "/" << file_name ;
2868 theInputNodeFiles.push_back(filename_total.str()) ;
2875 for ( int i = 0; i < icpt; i++ )
2876 { MESSAGE ( ". theInputNodeFiles["<< i << "] = " << theInputNodeFiles[i] ); }
2878 // B.4. Le fichier de la CAO
2879 ADAPT::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2880 std::string BoundaryName = std::string((*ListBoundaryGroupType)[0]);
2881 MESSAGE ( ". BoundaryName = " << BoundaryName );
2882 ADAPT::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
2883 const std::string theXaoFileName = myBoundary->GetDataFile();
2884 MESSAGE ( ". theXaoFileName = " << theXaoFileName );
2886 // B.5. Parallélisme
2887 bool theIsParallel = false;
2889 // C. Lancement des projections
2890 MESSAGE ( ". Lancement des projections" );
2891 FrontTrack* myFrontTrack = new FrontTrack();
2892 myFrontTrack->track(theInputMedFile, theOutputMedFile, theInputNodeFiles, theXaoFileName, theIsParallel);
2894 // D. Transfert des coordonnées modifiées dans le fichier historique de HOMARD
2895 // On lance une exécution spéciale de HOMARD en attendant de savoir le faire avec MEDCoupling
2896 MESSAGE ( ". Transfert des coordonnées" );
2897 codret = ComputeCAObis(myIteration, Option1, Option2) ;
2901 //=============================================================================
2902 //=============================================================================
2903 // Transfert des coordonnées en suivi de frontière CAO
2904 // Option1 >0 : appel depuis python
2905 // <0 : appel depuis GUI
2906 // Option2 : multiple de nombres premiers
2907 // 1 : aucune option
2908 // x2 : publication du maillage dans SMESH
2909 //=============================================================================
2910 CORBA::Long ADAPT_Gen_i::ComputeCAObis(ADAPT::HOMARD_Iteration_var myIteration, CORBA::Long Option1, CORBA::Long Option2)
2912 MESSAGE ( "ComputeCAObis, avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2917 // A.1. Controle de la possibilite d'agir
2918 // A.1.1. Etat de l'iteration
2919 int etat = myIteration->GetState();
2920 MESSAGE ( "etat = "<<etat );
2921 // A.1.2. L'iteration doit être calculee
2924 SALOME::ExceptionStruct es;
2925 es.type = SALOME::BAD_PARAM;
2926 es.text = "This iteration is not computed.";
2927 throw SALOME::SALOME_Exception(es);
2930 // A.2. Numero de l'iteration
2931 // siterp1 : numero de l'iteration a traiter
2932 int NumeIter = myIteration->GetNumber();
2933 std::string siterp1 ;
2934 std::stringstream saux1 ;
2936 siterp1 = saux1.str() ;
2937 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2938 MESSAGE ( "siterp1 = "<<siterp1 );
2941 const char* CaseName = myIteration->GetCaseName();
2942 ADAPT::HOMARD_Cas_var myCase = myStudyContext._mesCas[CaseName];
2943 ASSERT(!CORBA::is_nil(myCase));
2945 // A.4. Le sous-répertoire de l'iteration a traiter
2946 char* DirCompute = myIteration->GetDirName();
2947 MESSAGE( ". DirCompute = " << DirCompute );
2949 // C. Le fichier des messages
2950 std::string LogFile = DirCompute ;
2951 LogFile += "/Liste." + siterp1 + ".maj_coords.log" ;
2952 MESSAGE (". LogFile = " << LogFile);
2953 myIteration->SetFileInfo(LogFile.c_str());
2955 // D. On passe dans le répertoire de l'iteration a calculer
2956 MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2959 // E. Les données de l'exécution HOMARD
2960 // E.1. L'objet du texte du fichier de configuration
2961 HomardDriver* myDriver = new HomardDriver("", siterp1);
2962 myDriver->TexteInit(DirCompute, LogFile, _Langue);
2964 // E.2. Le maillage associe a l'iteration
2965 const char* NomMesh = myIteration->GetMeshName();
2966 MESSAGE ( ". NomMesh = " << NomMesh );
2967 const char* MeshFile = myIteration->GetMeshFile();
2968 MESSAGE ( ". MeshFile = " << MeshFile );
2970 // E.3. Les données du traitement HOMARD
2972 myDriver->TexteMajCoords( NumeIter ) ;
2974 myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2975 myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2977 // E.4. Ecriture du texte dans le fichier
2978 MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2980 { myDriver->CreeFichier(); }
2984 int codretexec = 1789 ;
2987 codretexec = myDriver->ExecuteHomard(Option1);
2988 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2991 // G. Gestion des resultats
2994 // G.1. Le fichier des messages, dans tous les cas
2995 const char* NomIteration = myIteration->GetName();
2996 std::string Commentaire = "logmaj_coords" ;
2997 PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2998 // G.2 Message d'erreur
2999 if (codretexec != 0)
3001 std::string text = "\n\nSee the file " + LogFile + "\n" ;
3003 SALOME::ExceptionStruct es;
3004 es.type = SALOME::BAD_PARAM;
3005 es.text = CORBA::string_dup(text.c_str());
3006 throw SALOME::SALOME_Exception(es);
3008 // On force le succes pour pouvoir consulter le fichier log
3013 // H. Menage et retour dans le répertoire du cas
3014 if (codret == 0) { delete myDriver; }
3018 //=============================================================================
3019 // Creation d'un nom de sous-répertoire pour l'iteration au sein d'un répertoire parent
3020 // nomrep : nom du répertoire parent
3021 // num : le nom du sous-répertoire est sous la forme 'In', n est >= num
3022 //=============================================================================
3023 char* ADAPT_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
3025 MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
3026 // On verifie que le répertoire parent existe
3027 int codret = CHDIR(nomrep) ;
3030 SALOME::ExceptionStruct es;
3031 es.type = SALOME::BAD_PARAM;
3032 es.text = "The directory of the case does not exist.";
3033 throw SALOME::SALOME_Exception(es);
3036 std::string nomDirActuel = getenv("PWD") ;
3037 std::string DirName ;
3038 // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un répertoire inconnu
3039 bool a_chercher = true ;
3040 while ( a_chercher )
3042 // On passe dans le répertoire parent
3045 // On recherche un nom sous la forme Iabc, avec abc representant le numero
3047 if ( num < 100 ) { jaux = 2 ; }
3048 else if ( num < 1000 ) { jaux = 3 ; }
3049 else if ( num < 10000 ) { jaux = 4 ; }
3050 else if ( num < 100000 ) { jaux = 5 ; }
3052 std::ostringstream iaux ;
3053 iaux << std::setw(jaux) << std::setfill('0') << num ;
3054 std::ostringstream DirNameA ;
3055 DirNameA << "I" << iaux.str();
3056 // Si on ne pas peut entrer dans le répertoire, on doit verifier
3057 // que c'est bien un probleme d'absence
3058 if ( CHDIR(DirNameA.str().c_str()) != 0 )
3060 bool existe = false ;
3063 struct dirent *dirp;
3064 dp = opendir(nomrep);
3065 while ( (dirp = readdir(dp)) != NULL )
3067 std::string file_name(dirp->d_name);
3069 HANDLE hFind = INVALID_HANDLE_VALUE;
3070 WIN32_FIND_DATA ffd;
3071 hFind = FindFirstFile(nomrep, &ffd);
3072 if (INVALID_HANDLE_VALUE != hFind) {
3073 while (FindNextFile(hFind, &ffd) != 0) {
3074 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
3075 std::string file_name(ffd.cFileName);
3077 if ( file_name == DirNameA.str() ) { existe = true ; }
3086 DirName = DirNameA.str() ;
3087 a_chercher = false ;
3094 MESSAGE ( "==> DirName = " << DirName);
3095 MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
3096 CHDIR(nomDirActuel.c_str());
3097 return CORBA::string_dup( DirName.c_str() );
3099 //=============================================================================
3100 // Calcul d'une iteration : gestion du répertoire de calcul
3101 // Si le sous-répertoire existe :
3102 // etatMenage = 0 : on sort en erreur si le répertoire n'est pas vide
3103 // etatMenage = 1 : on fait le menage du répertoire
3104 // etatMenage = -1 : on ne fait rien
3105 //=============================================================================
3106 char* ADAPT_Gen_i::ComputeDirManagement(ADAPT::HOMARD_Cas_var myCase, ADAPT::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
3108 MESSAGE ( "ComputeDirManagement : répertoires pour le calcul" );
3109 // B.2. Le répertoire du cas
3110 const char* nomDirCase = myCase->GetDirName();
3111 MESSAGE ( ". nomDirCase = " << nomDirCase );
3113 // B.3. Le sous-répertoire de l'iteration a calculer, puis le répertoire complet a creer
3114 // B.3.1. Le nom du sous-répertoire
3115 const char* nomDirIt = myIteration->GetDirNameLoc();
3117 // B.3.2. Le nom complet du sous-répertoire
3118 std::stringstream DirCompute ;
3119 DirCompute << nomDirCase << "/" << nomDirIt;
3120 MESSAGE (". DirCompute = " << DirCompute.str() );
3122 // B.3.3. Si le sous-répertoire n'existe pas, on le cree
3123 if (CHDIR(DirCompute.str().c_str()) != 0)
3126 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
3128 if (_mkdir(DirCompute.str().c_str()) != 0)
3131 // GERALD -- QMESSAGE BOX
3132 std::cerr << "Pb Creation du répertoire DirCompute = " << DirCompute.str() << std::endl;
3133 VERIFICATION("Pb a la creation du répertoire" == 0);
3138 // Le répertoire existe
3139 // On demande de faire le menage de son contenu :
3140 if (etatMenage == 1)
3142 MESSAGE (". Menage du répertoire DirCompute = " << DirCompute.str());
3143 std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
3144 int codret = system(commande.c_str());
3147 // GERALD -- QMESSAGE BOX
3148 std::cerr << ". Menage du répertoire de calcul" << DirCompute.str() << std::endl;
3149 VERIFICATION("Pb au menage du répertoire de calcul" == 0);
3152 // On n'a pas demande de faire le menage de son contenu : on sort en erreur :
3155 if (etatMenage == 0)
3159 struct dirent *dirp;
3160 dp = opendir(DirCompute.str().c_str());
3162 while ((dirp = readdir(dp)) != NULL && result )
3164 std::string file_name(dirp->d_name);
3165 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3169 HANDLE hFind = INVALID_HANDLE_VALUE;
3170 WIN32_FIND_DATA ffd;
3171 hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
3173 if (INVALID_HANDLE_VALUE != hFind) {
3174 while (FindNextFile(hFind, &ffd) != 0) {
3175 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
3176 std::string file_name(ffd.cFileName);
3177 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3182 if ( result == false)
3184 SALOME::ExceptionStruct es;
3185 es.type = SALOME::BAD_PARAM;
3186 std::string text = "Directory : " + DirCompute.str() + " is not empty";
3187 es.text = CORBA::string_dup(text.c_str());
3188 throw SALOME::SALOME_Exception(es);
3189 VERIFICATION("Directory is not empty" == 0);
3195 return CORBA::string_dup( DirCompute.str().c_str() );
3197 //=============================================================================
3198 // Calcul d'une iteration : gestion du répertoire de calcul de l'iteration parent
3199 //=============================================================================
3200 char* ADAPT_Gen_i::ComputeDirPaManagement(ADAPT::HOMARD_Cas_var myCase, ADAPT::HOMARD_Iteration_var myIteration)
3202 MESSAGE ( "ComputeDirPaManagement : répertoires pour le calcul" );
3203 // Le répertoire du cas
3204 const char* nomDirCase = myCase->GetDirName();
3205 MESSAGE ( ". nomDirCase = " << nomDirCase );
3207 // Le sous-répertoire de l'iteration precedente
3209 const char* nomIterationParent = myIteration->GetIterParentName();
3210 ADAPT::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterationParent];
3211 const char* nomDirItPa = myIterationParent->GetDirNameLoc();
3212 std::stringstream DirComputePa ;
3213 DirComputePa << nomDirCase << "/" << nomDirItPa;
3214 MESSAGE( ". nomDirItPa = " << nomDirItPa);
3215 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
3217 return CORBA::string_dup( DirComputePa.str().c_str() );
3219 //=============================================================================
3220 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
3221 //=============================================================================
3222 void ADAPT_Gen_i::DriverTexteZone(ADAPT::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3224 MESSAGE ( "... DriverTexteZone" );
3225 ADAPT::listeZonesHypo* ListZone = myHypo->GetZones();
3226 int numberOfZonesx2 = ListZone->length();
3229 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3231 std::string ZoneName = std::string((*ListZone)[iaux]);
3232 MESSAGE ( "... ZoneName = " << ZoneName);
3233 ADAPT::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
3234 ASSERT(!CORBA::is_nil(myZone));
3236 int ZoneType = myZone->GetType();
3237 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
3238 int TypeUse = atoi( TypeUsestr.c_str() );
3239 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
3240 NumZone = iaux/2 + 1 ;
3241 ADAPT::double_array* zone = myZone->GetCoords();
3242 if ( ZoneType == 2 || ( ZoneType>=11 && ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
3243 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
3244 else if ( ZoneType == 4 ) // Cas d une sphere
3245 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
3246 else if ( ZoneType == 5 || ( ZoneType>=31 && ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
3247 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
3248 else if ( ZoneType == 7 || ( ZoneType>=61 && ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
3249 { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
3250 else { VERIFICATION("ZoneType est incorrect." == 0) ; }
3255 //=============================================================================
3256 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
3257 //=============================================================================
3258 void ADAPT_Gen_i::DriverTexteField(ADAPT::HOMARD_Iteration_var myIteration, ADAPT::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3260 MESSAGE ( "... DriverTexteField" );
3261 // Le fichier du champ
3262 char* FieldFile = myIteration->GetFieldFile();
3263 MESSAGE ( ". FieldFile = " << FieldFile );
3264 if (strlen(FieldFile) == 0)
3266 // GERALD -- QMESSAGE BOX
3267 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
3268 VERIFICATION("The file for the field is not given." == 0);
3270 // Les caracteristiques d'instants du champ de pilotage
3271 int TimeStep = myIteration->GetTimeStep();
3272 MESSAGE( ". TimeStep = " << TimeStep );
3273 int Rank = myIteration->GetRank();
3274 MESSAGE( ". Rank = " << Rank );
3275 // Les informations sur les champs
3276 ADAPT::InfosHypo* aInfosHypo = myHypo->GetField();
3278 const char* FieldName = aInfosHypo->FieldName;
3280 int TypeThR = aInfosHypo->TypeThR;
3281 double ThreshR = aInfosHypo->ThreshR;
3282 int TypeThC = aInfosHypo->TypeThC;
3283 double ThreshC = aInfosHypo->ThreshC;
3284 // Saut entre mailles ou non ?
3285 int UsField = aInfosHypo->UsField;
3286 MESSAGE( ". UsField = " << UsField );
3287 // L'usage des composantes
3288 int UsCmpI = aInfosHypo->UsCmpI;
3289 MESSAGE( ". UsCmpI = " << UsCmpI );
3291 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
3294 ADAPT::listeComposantsHypo* mescompo = myHypo->GetComps();
3295 int numberOfCompos = mescompo->length();
3296 MESSAGE( ". numberOfCompos = " << numberOfCompos );
3297 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
3299 std::string nomCompo = std::string((*mescompo)[NumeComp]);
3300 MESSAGE( "... nomCompo = " << nomCompo );
3301 myDriver->TexteCompo(NumeComp, nomCompo);
3305 //=============================================================================
3306 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
3307 // On ecrit dans l'ordre :
3308 // 1. la definition des frontieres
3309 // 2. les liens avec les groupes
3310 // 3. un entier resumant le type de comportement pour les frontieres
3311 //=============================================================================
3312 int ADAPT_Gen_i::DriverTexteBoundary(ADAPT::HOMARD_Cas_var myCase, HomardDriver* myDriver)
3314 MESSAGE ( "... DriverTexteBoundary" );
3315 // 1. Recuperation des frontieres
3316 std::list<std::string> ListeBoundaryTraitees ;
3317 ADAPT::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3318 int numberOfitems = ListBoundaryGroupType->length();
3319 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
3320 int BoundaryOption = 1 ;
3321 // 2. Parcours des frontieres pour ecrire leur description
3322 int NumBoundaryAnalytical = 0 ;
3323 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3325 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3326 MESSAGE ( "... BoundaryName = " << BoundaryName);
3327 // 2.1. La frontiere a-t-elle deja ete ecrite ?
3328 // Cela arrive quand elle est liee a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
3330 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3331 while (it != ListeBoundaryTraitees.end())
3333 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3334 if ( BoundaryName == *it ) { A_faire = 0 ; }
3337 // 2.2. Ecriture de la frontiere
3340 // 2.2.1. Caracteristiques de la frontiere
3341 ADAPT::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
3342 ASSERT(!CORBA::is_nil(myBoundary));
3343 int BoundaryType = myBoundary->GetType();
3344 MESSAGE ( "... BoundaryType = " << BoundaryType );
3345 // 2.2.2. Ecriture selon le type
3346 // 2.2.2.1. Cas d une frontiere CAO
3347 if (BoundaryType == -1)
3349 // const char* CAOFile = myBoundary->GetDataFile() ;
3350 // MESSAGE ( ". CAOFile = " << CAOFile );
3351 if ( BoundaryOption % 5 != 0 ) { BoundaryOption = BoundaryOption*5 ; }
3353 // 2.2.2.2. Cas d une frontiere discrete
3354 else if (BoundaryType == 0)
3356 const char* MeshName = myBoundary->GetMeshName() ;
3357 MESSAGE ( ". MeshName = " << MeshName );
3358 const char* MeshFile = myBoundary->GetDataFile() ;
3359 MESSAGE ( ". MeshFile = " << MeshFile );
3360 myDriver->TexteBoundaryDi( MeshName, MeshFile);
3361 if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
3363 // 2.2.2.3. Cas d une frontiere analytique
3366 NumBoundaryAnalytical++ ;
3367 ADAPT::double_array* coor = myBoundary->GetCoords();
3368 if (BoundaryType == 1) // Cas d un cylindre
3370 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3371 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3373 else if (BoundaryType == 2) // Cas d une sphere
3375 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
3376 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3378 else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
3380 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3381 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3383 else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
3385 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3386 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3388 else if (BoundaryType == 5) // Cas d un tore
3390 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3391 if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3394 // 2.2.3. Memorisation du traitement
3395 ListeBoundaryTraitees.push_back( BoundaryName );
3398 // 3. Parcours des frontieres pour ecrire les liens avec les groupes
3399 NumBoundaryAnalytical = 0 ;
3400 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3402 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3403 MESSAGE ( "... BoundaryName = " << BoundaryName);
3404 ADAPT::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
3405 ASSERT(!CORBA::is_nil(myBoundary));
3406 int BoundaryType = myBoundary->GetType();
3407 MESSAGE ( "... BoundaryType = " << BoundaryType );
3408 // 3.1. Recuperation du nom du groupe
3409 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
3410 MESSAGE ( "... GroupName = " << GroupName);
3411 // 3.2. Cas d une frontiere CAO
3412 if ( BoundaryType == -1 )
3414 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryCAOGr ( GroupName ) ; }
3416 // 3.3. Cas d une frontiere discrete
3417 else if ( BoundaryType == 0 )
3419 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
3421 // 3.4. Cas d une frontiere analytique
3424 NumBoundaryAnalytical++ ;
3425 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
3428 // 4. Ecriture de l'option finale
3429 myDriver->TexteBoundaryOption(BoundaryOption);
3431 return BoundaryOption ;
3433 //=============================================================================
3434 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3435 //=============================================================================
3436 void ADAPT_Gen_i::DriverTexteFieldInterp(ADAPT::HOMARD_Iteration_var myIteration, ADAPT::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3438 MESSAGE ( "... DriverTexteFieldInterp" );
3439 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3440 MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3441 if (TypeFieldInterp != 0)
3443 // Le fichier des champs
3444 char* FieldFile = myIteration->GetFieldFile();
3445 MESSAGE ( ". FieldFile = " << FieldFile );
3446 if (strlen(FieldFile) == 0)
3448 // GERALD -- QMESSAGE BOX
3449 VERIFICATION("The file for the field is not given." == 0);
3452 const char* MeshFile = myIteration->GetMeshFile();
3453 myDriver->TexteFieldInterp(FieldFile, MeshFile);
3456 // Interpolation de tous les champs
3457 if ( TypeFieldInterp == 1 )
3459 myDriver->TexteFieldInterpAll();
3461 // Interpolation de certains champs
3462 else if (TypeFieldInterp == 2)
3464 // Les champs et leurs instants pour l'iteration
3465 ADAPT::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3466 int numberOfFieldsx3 = ListFieldTSR->length();
3467 MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3468 // Les champs pour l'hypothese
3469 ADAPT::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3470 int numberOfFieldsx2 = ListField->length();
3471 MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3472 // On parcourt tous les champs de l'hypothese
3474 for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3477 std::string FieldName = std::string((*ListField)[iaux]) ;
3478 // Le type d'interpolation
3479 std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3480 MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3481 // On cherche ?? savoir si des instants ont ??t?? pr??cis??s pour cette it??ration
3483 for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3486 std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3487 MESSAGE( "..... FieldName2 = " << FieldName2 );
3488 // Quand c'est le bon champ, on ecrit le pas de temps
3489 if ( FieldName == FieldName2 )
3493 std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3494 // Le numero d'ordre
3495 std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3496 MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3498 int TimeStep = atoi( TimeStepstr.c_str() );
3499 int Rank = atoi( Rankstr.c_str() );
3500 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3504 // Si aucun instant n'a été défini
3508 myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3516 //===========================================================================
3517 //===========================================================================
3520 //===========================================================================
3521 //===========================================================================
3523 //===========================================================================
3524 //===========================================================================
3525 SALOMEDS::SObject_ptr ADAPT_Gen_i::PublishInStudy(SALOMEDS::SObject_ptr theSObject,
3526 CORBA::Object_ptr theObject,
3527 const char* theName)
3529 MESSAGE("PublishInStudy pour " << theName);
3530 SALOMEDS::SObject_var aResultSO;
3531 if (CORBA::is_nil(myStudy))
3533 SALOME::ExceptionStruct es;
3534 es.type = SALOME::BAD_PARAM;
3535 es.text = "Invalid study context";
3536 throw SALOME::SALOME_Exception(es);
3540 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3541 // Rq : Iteration est publiee ailleurs
3542 ADAPT::HOMARD_Boundary_var aBoundary = ADAPT::HOMARD_Boundary::_narrow(theObject);
3543 ADAPT::HOMARD_Cas_var aCase = ADAPT::HOMARD_Cas::_narrow(theObject);
3544 ADAPT::HOMARD_Hypothesis_var aHypo = ADAPT::HOMARD_Hypothesis::_narrow(theObject);
3545 ADAPT::HOMARD_YACS_var aYACS = ADAPT::HOMARD_YACS::_narrow(theObject);
3546 ADAPT::HOMARD_Zone_var aZone = ADAPT::HOMARD_Zone::_narrow(theObject);
3550 // Controle de la non publication d'un objet de meme nom
3551 if ( (!aBoundary->_is_nil()) || (!aHypo->_is_nil()) || (!aYACS->_is_nil()) || (!aZone->_is_nil()) )
3553 SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(theName, ComponentDataType());
3554 if (listSO->length() >= 1)
3556 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3557 aResultSO = listSO[0];
3558 return aResultSO._retn();
3562 // Caracteristiques de l'etude
3563 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
3564 aStudyBuilder->NewCommand();
3565 if(!aBoundary->_is_nil())
3566 aResultSO = PublishBoundaryInStudy(aStudyBuilder, aBoundary, theName);
3567 else if(!aCase->_is_nil())
3568 aResultSO = PublishCaseInStudy(aStudyBuilder, aCase, theName);
3569 else if(!aHypo->_is_nil())
3570 aResultSO = PublishHypotheseInStudy(aStudyBuilder, aHypo, theName);
3571 else if(!aYACS->_is_nil())
3572 aResultSO = PublishYACSInStudy(aStudyBuilder, aYACS, theName);
3573 else if(!aZone->_is_nil())
3574 aResultSO = PublishZoneInStudy(aStudyBuilder, aZone, theName);
3576 aStudyBuilder->CommitCommand();
3578 return aResultSO._retn();
3580 //=============================================================================
3581 SALOMEDS::SObject_ptr ADAPT_Gen_i::PublishBoundaryInStudy( SALOMEDS::StudyBuilder_var aStudyBuilder,
3582 ADAPT::HOMARD_Boundary_ptr theObject, const char* theName)
3584 MESSAGE("PublishBoundaryStudy pour "<<theName);
3585 SALOMEDS::SObject_var aResultSO;
3587 // Caracteristique de la Boundary
3588 ADAPT::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[theName];
3590 // On recupere le module pere dans l etude
3591 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3592 if (theFatherHomard->_is_nil())
3594 MESSAGE("theFatherHomard->_is_nil()");
3595 return aResultSO._retn();
3598 // On ajoute la categorie des boundarys dans l etude si necessaire
3599 if ( _tag_boun == 0 )
3602 _tag_boun = _tag_gene ;
3604 MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3605 SALOMEDS::SObject_var aSObject;
3606 if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3608 MESSAGE("Ajout de la categorie des boundarys");
3609 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3610 PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3612 else { MESSAGE("La categorie des boundarys existe deja."); }
3614 CORBA::Long BoundaryType = myBoundary->GetType();
3615 // MESSAGE("BoundaryType : "<<BoundaryType);
3618 switch (BoundaryType)
3621 { value = "BoundaryCAOHomard" ;
3622 icone = "geometry.png" ;
3626 { value = "BoundaryDiHomard" ;
3627 icone = "mesh_tree_mesh.png" ;
3631 { value = "BoundaryAnHomard" ;
3632 icone = "cylinderpointvector_2.png" ;
3636 { value = "BoundaryAnHomard" ;
3637 icone = "spherepoint_2.png" ;
3641 { value = "BoundaryAnHomard" ;
3642 icone = "conepointvector.png" ;
3646 { value = "BoundaryAnHomard" ;
3647 icone = "conedxyz.png" ;
3651 { value = "BoundaryAnHomard" ;
3652 icone = "toruspointvector.png" ;
3656 aResultSO = aStudyBuilder->NewObject(aSObject);
3657 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3658 return aResultSO._retn();
3660 //=============================================================================
3661 SALOMEDS::SObject_ptr ADAPT_Gen_i::PublishCaseInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3662 ADAPT::HOMARD_Cas_ptr theObject, const char* theName)
3664 MESSAGE("PublishCaseInStudy pour "<<theName);
3665 SALOMEDS::SObject_var aResultSO;
3667 if (CORBA::is_nil(theObject)) {
3668 MESSAGE("ADAPT_Gen_i::theObject->_is_nil()");
3669 return aResultSO._retn();
3671 if (myStudy->_is_nil()) {
3672 MESSAGE("ADAPT_Gen_i::myStudy->_is_nil()");
3673 return aResultSO._retn();
3676 // On recupere le module pere dans l etude
3677 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3678 if (theFatherHomard->_is_nil())
3680 MESSAGE("theFatherHomard->_is_nil()");
3681 return aResultSO._retn();
3685 MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3686 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3687 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3688 _orb->object_to_string(theObject) ) ;
3690 return aResultSO._retn();
3692 //=============================================================================
3693 SALOMEDS::SObject_ptr ADAPT_Gen_i::PublishHypotheseInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3694 ADAPT::HOMARD_Hypothesis_ptr theObject, const char* theName)
3696 MESSAGE("PublishHypotheseInStudy pour "<<theName);
3697 SALOMEDS::SObject_var aResultSO;
3699 // On recupere le module pere dans l etude
3700 // On ajoute la categorie des hypotheses dans l etude si necessaire
3701 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3702 if (theFatherHomard->_is_nil())
3704 MESSAGE("theFatherHomard->_is_nil()");
3705 return aResultSO._retn();
3708 // On ajoute la categorie des hypotheses dans l etude si necessaire
3709 SALOMEDS::SObject_var aSObject;
3710 if ( _tag_hypo == 0 )
3713 _tag_hypo = _tag_gene ;
3715 MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3716 if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3718 MESSAGE("Ajout de la categorie des hypotheses");
3719 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3720 PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3722 else { MESSAGE("La categorie des hypotheses existe deja."); }
3724 // Creation du resultat dans l'etude
3725 aResultSO = aStudyBuilder->NewObject(aSObject);
3726 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3728 return aResultSO._retn();
3730 //=============================================================================
3731 SALOMEDS::SObject_ptr ADAPT_Gen_i::PublishYACSInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3732 ADAPT::HOMARD_YACS_ptr theObject, const char* theName)
3734 MESSAGE("PublishYACSInStudy pour "<<theName);
3735 SALOMEDS::SObject_var aResultSO;
3737 // On recupere le module pere dans l etude
3738 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3739 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3740 if (theFatherHomard->_is_nil())
3742 MESSAGE("theFatherHomard->_is_nil()");
3743 return aResultSO._retn();
3745 // On ajoute la categorie des schemas YACS dans l etude si necessaire
3746 if ( _tag_yacs == 0 )
3749 _tag_yacs = _tag_gene ;
3751 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3752 SALOMEDS::SObject_var aSObject;
3753 if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3755 MESSAGE("Ajout de la categorie des schemas YACS");
3756 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3757 PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3759 else { MESSAGE("La categorie des schemas YACS existe deja."); }
3761 // Creation du resultat dans l'etude
3762 aResultSO = aStudyBuilder->NewObject(aSObject);
3763 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3765 return aResultSO._retn();
3768 //=============================================================================
3769 SALOMEDS::SObject_ptr ADAPT_Gen_i::PublishZoneInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3770 ADAPT::HOMARD_Zone_ptr theObject, const char* theName)
3772 MESSAGE("PublishZoneStudy pour "<<theName);
3773 SALOMEDS::SObject_var aResultSO;
3774 if (CORBA::is_nil(theObject))
3776 MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3777 return aResultSO._retn();
3779 if (myStudy->_is_nil())
3781 MESSAGE("PublishZoneInStudy : myStudy->_is_nil()");
3782 return aResultSO._retn();
3784 SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3785 if (theFatherHomard->_is_nil())
3787 MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3788 return aResultSO._retn();
3791 // Caracteristique de la zone
3792 ADAPT::HOMARD_Zone_var myZone = myStudyContext._mesZones[theName];
3793 CORBA::Long ZoneType = myZone->GetType();
3795 // On ajoute la categorie des zones dans l etude si necessaire
3796 if ( _tag_zone == 0 )
3799 _tag_zone = _tag_gene ;
3801 MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3802 SALOMEDS::SObject_var aSObject;
3803 if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3805 MESSAGE("Ajout de la categorie des zones");
3806 aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3807 PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3809 else { MESSAGE("La categorie des zones existe deja."); }
3811 aResultSO = aStudyBuilder->NewObject(aSObject);
3820 { icone = "boxdxy_2.png" ;
3824 { icone = "boxdxyz_2.png" ;
3832 { icone = "disk_2.png" ;
3836 { icone = "spherepoint_2.png" ;
3840 { icone = "cylinderpointvector_2.png" ;
3848 { icone = "diskwithhole_2.png" ;
3852 { icone = "pipe_2.png" ;
3856 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3858 return aResultSO._retn();
3860 //===========================================================================
3861 void ADAPT_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3862 SALOMEDS::SObject_var aResultSO,
3863 const char* name, const char* comment, const char* icone, const char* ior)
3865 MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3866 // MESSAGE("icone = "<<icone);
3867 // MESSAGE("ior = "<<ior);
3868 SALOMEDS::GenericAttribute_var anAttr ;
3872 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3873 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3874 aNameAttrib->SetValue(name);
3877 // Ajout du commentaire
3878 if ( comment != NULL )
3880 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3881 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3882 aCommentAttrib->SetValue(comment);
3886 if ( icone != NULL )
3888 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3889 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3890 aPixmap->SetPixMap(icone);
3896 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3897 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3898 anIOR->SetValue(ior);
3902 //=====================================================================================
3903 void ADAPT_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3905 MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3907 ADAPT::HOMARD_Cas_var myCase = myStudyContext._mesCas[CaseName];
3908 ASSERT(!CORBA::is_nil(myCase));
3909 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3910 ASSERT(!CORBA::is_nil(aCaseSO));
3912 ADAPT::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
3913 ASSERT(!CORBA::is_nil(myBoundary));
3914 SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3915 ASSERT(!CORBA::is_nil(aBoundarySO));
3917 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
3919 aStudyBuilder->NewCommand();
3921 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3922 aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3923 // aStudyBuilder->RemoveReference(aSubSO);
3925 aStudyBuilder->CommitCommand();
3928 //=====================================================================================
3929 void ADAPT_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3931 MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3933 ADAPT::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
3934 ASSERT(!CORBA::is_nil(myYACS));
3935 SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3936 ASSERT(!CORBA::is_nil(aYACSSO));
3938 ADAPT::HOMARD_Cas_var myCase = myStudyContext._mesCas[CaseName];
3939 ASSERT(!CORBA::is_nil(myCase));
3940 SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3941 ASSERT(!CORBA::is_nil(aCaseSO));
3943 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
3945 aStudyBuilder->NewCommand();
3947 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3948 aStudyBuilder->Addreference(aSubSO, aCaseSO);
3950 aStudyBuilder->CommitCommand();
3953 //=============================================================================
3954 void ADAPT_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3955 // Option = 0 : fichier issu d'une importation
3956 // Option = 1 : fichier issu d'une execution HOMARD
3958 MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3959 if (CORBA::is_nil(myStudy))
3961 SALOME::ExceptionStruct es;
3962 es.type = SALOME::BAD_PARAM;
3963 es.text = "Invalid study context";
3964 throw SALOME::SALOME_Exception(es);
3968 // Le module SMESH est-il actif ?
3969 SALOMEDS::SObject_var aSmeshSO = myStudy->FindComponent("SMESH");
3971 if (!CORBA::is_nil(aSmeshSO))
3973 // On verifie que le fichier n est pas deja publie
3974 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aSmeshSO);
3975 for (; aIter->More(); aIter->Next())
3977 SALOMEDS::SObject_var aSO = aIter->Value();
3978 SALOMEDS::GenericAttribute_var aGAttr;
3979 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3981 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3982 CORBA::String_var value=anAttr->Value();
3983 if (strcmp((const char*)value,NomFich) == 0)
3985 MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3986 // Pour un fichier importe, on ne republie pas
3987 if ( Option == 0 ) { return; }
3988 // Pour un fichier calcule, on commence par faire la depublication
3991 MESSAGE ( "PublishResultInSmesh : depublication" );
3992 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3993 CORBA::String_var value2=anAttr2->Value();
3994 std::string MeshName = string(value2) ;
3995 MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3996 DeleteResultInSmesh(NomFich, MeshName) ;
4003 // On enregistre le fichier
4004 MESSAGE( "Enregistrement du fichier");
4005 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
4006 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
4007 ASSERT(!CORBA::is_nil(aSmeshEngine));
4008 aSmeshEngine->UpdateStudy();
4009 SMESH::DriverMED_ReadStatus theStatus;
4010 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
4012 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
4013 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
4014 for (int i = 0; i < mesMaillages->length(); i++)
4016 MESSAGE( ". Mise a jour des attributs du maillage");
4017 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
4018 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
4019 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4020 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
4021 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
4022 anAttr->SetValue(NomFich);
4023 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
4024 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
4026 if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
4027 else { icone = "mesh_tree_mesh.png" ; }
4028 anAttr2->SetPixMap( icone );
4032 //=============================================================================
4033 void ADAPT_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
4035 MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
4036 if (CORBA::is_nil(myStudy))
4038 SALOME::ExceptionStruct es;
4039 es.type = SALOME::BAD_PARAM;
4040 es.text = "Invalid study context";
4041 throw SALOME::SALOME_Exception(es);
4045 // Le module SMESH est-il actif ?
4046 SALOMEDS::SObject_var aSmeshSO = myStudy->FindComponent("SMESH");
4048 if (CORBA::is_nil(aSmeshSO))
4052 // On verifie que le fichier est deja publie
4053 SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
4054 SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aSmeshSO);
4055 for (; aIter->More(); aIter->Next())
4057 SALOMEDS::SObject_var aSO = aIter->Value();
4058 SALOMEDS::GenericAttribute_var aGAttr;
4059 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
4061 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
4062 CORBA::String_var value=anAttr->Value();
4063 if (strcmp((const char*)value,NomFich.c_str()) == 0)
4065 if (aSO->FindAttribute(aGAttr,"AttributeName"))
4067 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
4068 CORBA::String_var value2=anAttr2->Value();
4069 if (strcmp((const char*)value2,MeshName.c_str()) == 0)
4071 myBuilder->RemoveObjectWithChildren( aSO ) ;
4079 //=============================================================================
4080 void ADAPT_Gen_i::PublishMeshIterInSmesh(const char* NomIter)
4082 MESSAGE( "PublishMeshIterInSmesh " << NomIter);
4083 ADAPT::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIter];
4085 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
4086 if (CORBA::is_nil(myIteration))
4088 SALOME::ExceptionStruct es;
4089 es.type = SALOME::BAD_PARAM;
4090 es.text = "Invalid iterationStudy Object";
4091 throw SALOME::SALOME_Exception(es);
4094 const char* MeshFile = myIteration->GetMeshFile() ;
4095 const char* MeshName = myIteration->GetMeshName() ;
4096 CORBA::Long Option = -1 ;
4097 int etat = myIteration->GetState();
4098 // Iteration initiale
4099 if ( etat <= 0 ) { Option = 0 ; }
4100 // ou iteration calculee
4101 else if ( etat == 2 ) { Option = 1 ; }
4102 // Publication effective apres menage eventuel
4105 DeleteResultInSmesh(MeshFile, MeshName) ;
4106 PublishResultInSmesh(MeshFile, Option) ;
4110 //=============================================================================
4111 void ADAPT_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
4113 // MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
4114 ADAPT::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIter];
4116 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
4117 if (CORBA::is_nil(myIteration))
4119 SALOME::ExceptionStruct es;
4120 es.type = SALOME::BAD_PARAM;
4121 es.text = "Invalid iterationStudy Object";
4122 throw SALOME::SALOME_Exception(es);
4126 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4128 aStudyBuilder->NewCommand();
4130 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
4131 // Pour les fichiers med, on affiche une icone de maillage
4132 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
4133 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
4135 std::string ior = " " ;
4136 if ( Commentaire[0] == 'M' )
4137 { icone = "med.png" ; }
4139 { icone = "texte_2.png" ; }
4140 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
4142 aStudyBuilder->CommitCommand();
4145 //=============================================================================
4146 void ADAPT_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
4148 // MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
4149 ADAPT::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
4151 SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
4152 if (CORBA::is_nil(myYACS))
4154 SALOME::ExceptionStruct es;
4155 es.type = SALOME::BAD_PARAM;
4156 es.text = "Invalid YACSStudy Object";
4157 throw SALOME::SALOME_Exception(es);
4161 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4163 aStudyBuilder->NewCommand();
4165 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
4166 std::string icone = "texte_2.png" ;
4167 std::string ior = " " ;
4168 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
4170 aStudyBuilder->CommitCommand();
4173 //=============================================================================
4174 //=============================================================================
4176 //=============================================================================
4177 //=============================================================================
4178 //=============================================================================
4179 // Creation d'un schema YACS
4180 // nomCas : nom du cas a traiter
4181 // FileName : nom du fichier contenant le script de lancement du calcul
4182 // DirName : le répertoire de lancement des calculs du schéma
4183 //=============================================================================
4184 ADAPT::HOMARD_YACS_ptr ADAPT_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
4186 INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
4187 INFOS ( ". nomCas : " << nomCas);
4188 INFOS ( ". ScriptFile : " << ScriptFile);
4189 INFOS ( ". DirName : " << DirName);
4190 INFOS ( ". MeshFile : " << MeshFile);
4192 // A. Controle du nom :
4193 if ((myStudyContext._mesYACSs).find(nomYACS) != (myStudyContext._mesYACSs).end())
4195 SALOME::ExceptionStruct es;
4196 es.type = SALOME::BAD_PARAM;
4197 es.text = "This schema YACS has already been defined.";
4198 throw SALOME::SALOME_Exception(es);
4202 // B. Creation de l'objet
4203 ADAPT::HOMARD_YACS_var myYACS = newYACS();
4204 if (CORBA::is_nil(myYACS))
4206 SALOME::ExceptionStruct es;
4207 es.type = SALOME::BAD_PARAM;
4208 es.text = "Unable to create the schema YACS";
4209 throw SALOME::SALOME_Exception(es);
4212 myYACS->SetName( nomYACS ) ;
4214 // C. Enregistrement
4215 myStudyContext._mesYACSs[nomYACS] = myYACS;
4217 SALOMEDS::SObject_var aSO;
4218 SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myYACS, nomYACS);
4220 PublishCaseUnderYACS(nomYACS, nomCas);
4222 // D. Caracterisation
4224 myYACS->SetDirName( DirName ) ;
4225 myYACS->SetMeshFile( MeshFile ) ;
4226 myYACS->SetScriptFile( ScriptFile ) ;
4227 myYACS->SetCaseName( nomCas ) ;
4230 // D.2.1. Type constant
4231 myYACS->SetType( 1 ) ;
4232 // D.2.2. Convergence
4233 defaut_i = GetYACSMaxIter() ;
4234 myYACS->SetMaxIter( defaut_i ) ;
4235 defaut_i = GetYACSMaxNode() ;
4236 myYACS->SetMaxNode( defaut_i ) ;
4237 defaut_i = GetYACSMaxElem() ;
4238 myYACS->SetMaxElem( defaut_i ) ;
4239 // D.3. Fichier de sauvegarde dans le répertoire du cas
4240 ADAPT::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
4241 std::string dirnamecase = caseyacs->GetDirName() ;
4242 std::string XMLFile ;
4243 XMLFile = dirnamecase + "/schema.xml" ;
4244 myYACS->SetXMLFile( XMLFile.c_str() ) ;
4246 return ADAPT::HOMARD_YACS::_duplicate(myYACS);
4248 //=============================================================================
4249 // Ecriture d'un schema YACS
4250 //=============================================================================
4251 CORBA::Long ADAPT_Gen_i::YACSWrite(const char* nomYACS)
4253 INFOS ( "YACSWrite : Ecriture de " << nomYACS );
4254 // Le répertoire du cas
4255 ADAPT::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
4256 ASSERT(!CORBA::is_nil(myYACS));
4257 // Le nom du fichier du schema
4258 std::string XMLFile ;
4259 XMLFile = myYACS->GetXMLFile() ;
4261 int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
4265 //=============================================================================
4266 // Ecriture d'un schema YACS sur un fichier donne
4267 //=============================================================================
4268 CORBA::Long ADAPT_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
4270 INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
4277 ADAPT::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
4278 ASSERT(!CORBA::is_nil(myYACS));
4279 // B.2. Les caracteristiques
4280 std::string DirName = myYACS->GetDirName() ;
4281 std::string MeshFile = myYACS->GetMeshFile() ;
4282 std::string ScriptFile = myYACS->GetScriptFile() ;
4283 // B.3. Les caracteristiques de convergence
4284 int MaxIter = myYACS->GetMaxIter() ;
4285 int MaxNode = myYACS->GetMaxNode() ;
4286 int MaxElem = myYACS->GetMaxElem() ;
4290 const char* nomCas = myYACS->GetCaseName();
4291 ADAPT::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
4292 ASSERT(!CORBA::is_nil(myCase));
4293 // C.2. Les instructions python associees au cas
4294 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4295 std::string pythonCas = dumpCorbaCase.in();
4296 MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
4298 // D. Les iterations
4299 // D.1. L'iteration initiale
4300 ADAPT::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
4301 std::string Iter0Name = myCase->GetIter0Name() ;
4302 MESSAGE (". Iter0Name = " << Iter0Name);
4303 std::string MeshName = Iter0->GetMeshName();
4304 MESSAGE (". MeshName = " << MeshName);
4305 // D.2. L'iteration numero 1
4306 ADAPT::listeIterFilles* maListe = Iter0->GetIterations();
4307 int numberOfIter = maListe->length();
4308 if ( numberOfIter > 1 )
4310 MESSAGE (". numberOfIter = " << numberOfIter);
4311 SALOME::ExceptionStruct es ;
4312 es.type = SALOME::BAD_PARAM;
4313 std::string text = "Une seule iteration est permise." ;
4314 es.text = CORBA::string_dup(text.c_str());
4315 throw SALOME::SALOME_Exception(es);
4318 std::string Iter1Name = std::string((*maListe)[0]);
4319 MESSAGE ("... Iter1Name = " << Iter1Name);
4320 ADAPT::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
4321 // D.3. Les instructions python associees a l'iteration
4322 CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
4323 std::string pythonIter = dumpCorbaIter.in();
4324 MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
4326 // E. L'hypothese pour passer de l'iteration initiale a la suivante
4327 // E.1. La structure
4328 std::string nomHypo = Iter1->GetHypoName();
4329 MESSAGE (". nomHypo = " << nomHypo);
4330 ADAPT::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
4331 ASSERT(!CORBA::is_nil(myHypo));
4332 // E.2. Les caracteristiques de l'adaptation
4333 ADAPT::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
4334 ASSERT(ListTypes->length() == 3);
4335 int TypeAdap = (*ListTypes)[0];
4336 // int TypeRaff = (*ListTypes)[1];
4337 // int TypeDera = (*ListTypes)[2];
4338 // E.3. Les instructions python associees a l'hypothese
4339 CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
4340 std::string pythonHypo = dumpCorbaHypo.in();
4341 MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
4343 // F. Le fichier du schema de reference
4344 // HOMARD_ROOT_DIR : répertoire ou se trouve le module HOMARD
4345 std::string XMLFile_base ;
4346 if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
4349 SALOME::ExceptionStruct es ;
4350 es.type = SALOME::BAD_PARAM;
4351 std::string text = "HOMARD_ROOT_DIR est inconnu." ;
4352 es.text = CORBA::string_dup(text.c_str());
4353 throw SALOME::SALOME_Exception(es);
4356 XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
4358 MESSAGE("XMLFile_base ="<<XMLFile_base);
4360 // G. Lecture du schema de reference et insertion des données propres au fil de la rencontre des mots-cles
4361 YACSDriver* myDriver = new YACSDriver(XMLFile, DirName, _LangueShort);
4362 std::ifstream fichier( XMLFile_base.c_str() );
4363 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
4365 // G.1. Lecture du schema de reference et insertion des données propres au fil de la rencontre des mots-cles
4366 std::string ligne; // variable contenant chaque ligne lue
4367 std::string mot_cle;
4368 while ( std::getline( fichier, ligne ) )
4370 // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
4371 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
4372 ligne_bis >> mot_cle ;
4373 // G.1.2. Le maillage initial
4374 if ( mot_cle == "DataInit_MeshFile" )
4375 { myDriver->Texte_DataInit_MeshFile(MeshFile); }
4376 // G.1.3. Le script de lancement
4377 else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
4378 { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
4379 // G.1.4. Les options du cas
4380 else if ( mot_cle == "Iter_1_Case_Options" )
4381 { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
4382 // G.1.5. Execution de HOMARD : le répertoire du cas
4383 else if ( mot_cle == "HOMARD_Exec_DirName" )
4384 { myDriver->Texte_HOMARD_Exec_DirName(); }
4385 // G.1.6. Execution de HOMARD : le nom du maillage
4386 else if ( mot_cle == "HOMARD_Exec_MeshName" )
4388 myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
4390 if ( _LangueShort == "fr" ) { node = "Boucle_de_convergence.Alternance_Calcul_HOMARD" ; }
4391 else { node = "Convergence_Loop.Alternation_Computation_HOMARD" ; }
4392 node += ".Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
4393 myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
4395 // G.1.7. Execution de HOMARD : les options de l'hypothese
4396 else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
4397 { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ; }
4398 // G.1.8. Execution de HOMARD : les options de l'iteration
4399 else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
4400 { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ; }
4401 // G.1.9. a. Creation eventuelles des zones et frontieres
4403 else if ( mot_cle == "Iter_1" )
4405 std::string texte_control = "" ;
4406 if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
4407 texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
4408 texte_control += myDriver->Texte_Iter_1_control() ;
4409 myDriver->TexteAdd(texte_control);
4411 // G.1.10. Les tests de convergence
4412 else if ( mot_cle == "Analyse_Test_Convergence" )
4413 { myDriver->TexteAnalyse_Test_Convergence(MaxIter, MaxNode, MaxElem); }
4414 // G.1.11. Les parametres
4415 else if ( mot_cle == "PARAMETRES" )
4416 { myDriver->TexteAddParametres(); }
4417 // G.1.n. La ligne est recopiee telle quelle
4418 else { myDriver->TexteAdd(ligne); }
4420 // G.2. Ecriture du texte dans le fichier
4422 { myDriver->CreeFichier(); }
4426 SALOME::ExceptionStruct es;
4427 es.type = SALOME::BAD_PARAM;
4428 std::string text = "The reference file for the YACS schema cannot be read." ;
4429 es.text = CORBA::string_dup(text.c_str());
4430 throw SALOME::SALOME_Exception(es);
4435 // H. Publication du fichier dans l'arbre
4437 std::string Commentaire = "xml" ;
4438 PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
4442 //=============================================================================
4443 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
4444 //=============================================================================
4445 std::string ADAPT_Gen_i::YACSDriverTexteZone(ADAPT::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
4447 MESSAGE ( "YACSDriverTexteZone" );
4448 // A. Les zones associees a cette hypothese
4449 ADAPT::listeZonesHypo* ListZone = myHypo->GetZones();
4450 int numberOfZonesx2 = ListZone->length();
4452 // B. Parcours des zones
4453 std::string texte_control ;
4454 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
4456 // 1. Reperage de la zone
4457 std::string ZoneName = std::string((*ListZone)[iaux]);
4458 MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
4459 ADAPT::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
4460 ASSERT(!CORBA::is_nil(myZone));
4461 // 2. Les instructions python associees a la zone
4462 // La premiere ligne est un commentaire a eliminer
4463 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4464 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4465 std::string pythonStructure_0 = dumpCorbaZone.in();
4466 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4467 std::istringstream tout (pythonStructure_0) ;
4469 std::string pythonStructure ;
4470 while ( std::getline( tout, ligne ) )
4471 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4472 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4473 // 3. Decodage du nom du service
4474 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4475 MESSAGE ( "... methode = " << methode);
4476 // 4. Mise en place des instructions
4477 int ZoneType = myZone->GetType();
4478 MESSAGE ( "... ZoneType = " << ZoneType);
4479 std::string texte_control_0 ;
4480 texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
4481 texte_control += texte_control_0 ;
4486 return texte_control ;
4488 //=============================================================================
4489 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4490 //=============================================================================
4491 std::string ADAPT_Gen_i::YACSDriverTexteBoundary(ADAPT::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4493 MESSAGE ( "YACSDriverTexteBoundary" );
4494 // A. Les frontieres associees au cas
4495 ADAPT::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4496 int numberOfitems = ListBoundaryGroupType->length();
4498 // B. Parcours des frontieres
4499 std::string texte_control ;
4500 std::list<std::string> ListeBoundaryTraitees ;
4501 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4503 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4504 MESSAGE ( "... BoundaryName = " << BoundaryName);
4505 // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4506 // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4508 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4509 while (it != ListeBoundaryTraitees.end())
4511 MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4512 if ( BoundaryName == *it ) { A_faire = 0 ; }
4517 // 1. Caracteristiques de la frontiere
4518 ADAPT::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
4519 ASSERT(!CORBA::is_nil(myBoundary));
4520 // 2. Les instructions python associees a la frontiere
4521 // La premiere ligne est un commentaire a eliminer
4522 // La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4523 CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4524 std::string pythonStructure_0 = dumpCorbaBoundary.in();
4525 MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4526 std::istringstream tout (pythonStructure_0) ;
4528 std::string pythonStructure ;
4529 while ( std::getline( tout, ligne ) )
4530 { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4531 MESSAGE ("pythonStructure :\n"<<pythonStructure);
4532 // 3. Decodage du nom du service
4533 std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4534 MESSAGE ( "... methode = " << methode);
4535 // 4. Mise en place des instructions
4536 int BoundaryType = myBoundary->GetType();
4537 MESSAGE ( "... BoundaryType = " << BoundaryType);
4538 const char* MeshName ;
4539 const char* DataFile ;
4540 if (BoundaryType == -1)
4542 DataFile = myBoundary->GetDataFile() ;
4543 MESSAGE ( ". CAOFile = " << DataFile );
4545 else if (BoundaryType == 0)
4547 MeshName = myBoundary->GetMeshName() ;
4548 MESSAGE ( ". MeshName = " << MeshName );
4549 DataFile = myBoundary->GetDataFile() ;
4550 MESSAGE ( ". MeshFile = " << DataFile );
4552 std::string texte_control_0 ;
4553 texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName, MeshName, DataFile );
4554 texte_control += texte_control_0 ;
4555 // 5. Memorisation du traitement
4556 ListeBoundaryTraitees.push_back( BoundaryName );
4560 return texte_control ;
4563 //=============================================================================
4564 //=============================================================================
4565 // Next functions are inherited from SALOMEDS::Driver interface
4566 //=============================================================================
4567 //=============================================================================
4568 SALOMEDS::TMPFile* ADAPT_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4570 CORBA::Boolean isMultiFile)
4572 MESSAGE ("Save for theURL = "<< theURL);
4573 SALOMEDS::TMPFile_var aStreamFile;
4575 // get temporary directory name
4576 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4578 StudyContext& context = myStudyContext;
4580 // HOMARD data file name
4581 std::string aFileName = "";
4583 aFileName = SALOMEDS_Tool::GetNameFromPath(Kernel_Utils::encode(SMESH_Gen_i::getStudyServant()->URL()));
4584 aFileName += "_HOMARD.dat";
4586 // initialize sequence of file names
4587 SALOMEDS_Tool::ListOfFiles aFileSeq;
4588 aFileSeq.reserve(1);
4589 aFileSeq.push_back(CORBA::string_dup(aFileName.c_str())) ;
4591 // get full path to the data file
4592 aFileName = tmpDir + aFileName;
4596 std::ofstream f(aFileName.c_str());
4598 // clear temporary id map
4599 context._idmap.clear();
4604 std::map<std::string, ADAPT::HOMARD_Cas_var>::const_iterator it_case;
4605 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4606 ADAPT::HOMARD_Cas_var aCas = it_case->second;
4607 PortableServer::ServantBase_var aServant = GetServant(aCas);
4608 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4610 f << ADAPT::GetSignature(ADAPT::Case) << aCasServant->Dump() << std::endl;
4611 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4615 std::map<std::string, ADAPT::HOMARD_Zone_var>::const_iterator it_zone;
4616 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4617 ADAPT::HOMARD_Zone_var aZone = it_zone->second;
4618 PortableServer::ServantBase_var aServant = GetServant(aZone);
4619 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4621 f << ADAPT::GetSignature(ADAPT::Zone) << aZoneServant->Dump() << std::endl;
4622 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4625 // -> save hypotheses
4626 std::map<std::string, ADAPT::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4627 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4628 ADAPT::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4629 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4630 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4632 f << ADAPT::GetSignature(ADAPT::Hypothesis) << aHypoServant->Dump() << std::endl;
4633 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4636 // -> save iterations
4637 std::map<std::string, ADAPT::HOMARD_Iteration_var>::const_iterator it_iter;
4638 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4639 ADAPT::HOMARD_Iteration_var aIter = it_iter->second;
4640 PortableServer::ServantBase_var aServant = GetServant(aIter);
4641 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4643 f << ADAPT::GetSignature(ADAPT::Iteration) << aIterServant->Dump() << std::endl;
4644 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4647 // -> save boundaries
4648 std::map<std::string, ADAPT::HOMARD_Boundary_var>::const_iterator it_boundary;
4649 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4650 ADAPT::HOMARD_Boundary_var aBoundary = it_boundary->second;
4651 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4652 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4653 if (aBoundaryServant) {
4654 f << ADAPT::GetSignature(ADAPT::Boundary) << aBoundaryServant->Dump() << std::endl;
4655 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4659 MESSAGE ("close file");
4662 // put temporary files to the stream
4663 MESSAGE ("put temporary files to the stream");
4664 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq, isMultiFile);
4666 // remove temporary files
4667 MESSAGE ("remove temporary files");
4668 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq, true);
4670 // return data stream
4671 MESSAGE ("return data stream");
4672 return aStreamFile._retn();
4675 //===========================================================================
4676 SALOMEDS::TMPFile* ADAPT_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4678 CORBA::Boolean isMultiFile)
4680 // No specific ASCII persistence
4681 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4682 return aStreamFile._retn();
4685 //===========================================================================
4686 CORBA::Boolean ADAPT_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4687 const SALOMEDS::TMPFile& theStream,
4689 CORBA::Boolean isMultiFile)
4691 MESSAGE ("Load pour theURL = "<< theURL);
4693 // set current study
4694 if (myStudy->_is_nil())
4697 // get temporary directory name
4698 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4700 // Convert the stream into sequence of files to process
4701 SALOMEDS_Tool::ListOfFiles aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4704 // HOMARD data file name
4705 std::string aFileName = "";
4707 aFileName = SALOMEDS_Tool::GetNameFromPath(Kernel_Utils::encode(SMESH_Gen_i::getStudyServant()->URL()));
4708 aFileName = tmpDir + aFileName + "_HOMARD.dat";
4710 StudyContext& context = myStudyContext;
4714 std::ifstream f(aFileName.c_str());
4717 context._mesCas.clear();
4718 context._mesHypotheses.clear();
4719 context._mesIterations.clear();
4720 context._mesZones.clear();
4721 context._mesBoundarys.clear();
4722 context._idmap.clear();
4728 std::getline(f, line);
4729 std::string bounSignature = ADAPT::GetSignature(ADAPT::Boundary);
4730 std::string caseSignature = ADAPT::GetSignature(ADAPT::Case);
4731 std::string hypoSignature = ADAPT::GetSignature(ADAPT::Hypothesis);
4732 std::string iterSignature = ADAPT::GetSignature(ADAPT::Iteration);
4733 std::string zoneSignature = ADAPT::GetSignature(ADAPT::Zone);
4734 std::string yacsSignature = ADAPT::GetSignature(ADAPT::YACS);
4735 if (line.substr(0, bounSignature.size()) == bounSignature) {
4736 // re-create boundary
4737 MESSAGE ("Recreation de la frontiere" );
4738 ADAPT::HOMARD_Boundary_var aBoundary = newBoundary();
4739 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4740 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4741 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4742 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4743 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4746 else if (line.substr(0, caseSignature.size()) == caseSignature) {
4748 MESSAGE ("Recreation du cas" );
4749 ADAPT::HOMARD_Cas_var aCase = newCase();
4750 PortableServer::ServantBase_var aServant = GetServant(aCase);
4751 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4752 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4753 context._mesCas[aCase->GetName()] = aCase;
4754 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4757 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4758 // re-create hypothesis
4759 MESSAGE ("Recreation de l hypothese" );
4760 ADAPT::HOMARD_Hypothesis_var aHypo = newHypothesis();
4761 PortableServer::ServantBase_var aServant = GetServant(aHypo);
4762 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4763 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4764 context._mesHypotheses[aHypo->GetName()] = aHypo;
4765 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4768 else if (line.substr(0, iterSignature.size()) == iterSignature) {
4769 // re-create iteration
4770 MESSAGE ("Recreation de l'iteration" );
4771 ADAPT::HOMARD_Iteration_var aIter = newIteration();
4772 PortableServer::ServantBase_var aServant = GetServant(aIter);
4773 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4774 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4775 context._mesIterations[aIter->GetName()] = aIter;
4776 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4779 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4780 MESSAGE ("Recreation de la zone" );
4782 ADAPT::HOMARD_Zone_var aZone = newZone();
4783 PortableServer::ServantBase_var aServant = GetServant(aZone);
4784 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4785 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4786 context._mesZones[aZone->GetName()] = aZone;
4787 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4790 else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4791 MESSAGE ("Recreation du schema YACS" );
4793 ADAPT::HOMARD_YACS_var aYACS = newYACS();
4794 PortableServer::ServantBase_var aServant = GetServant(aYACS);
4795 HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4796 if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4797 context._mesYACSs[aYACS->GetName()] = aYACS;
4798 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4807 // Remove temporary files created from the stream
4809 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq, true);
4814 //===========================================================================
4815 CORBA::Boolean ADAPT_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4816 const SALOMEDS::TMPFile& theStream,
4818 CORBA::Boolean isMultiFile)
4820 // No specific ASCII persistence
4821 return Load(theComponent, theStream, theURL, isMultiFile);
4824 //===========================================================================
4825 void ADAPT_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4829 //===========================================================================
4830 char* ADAPT_Gen_i::ComponentDataType()
4832 return CORBA::string_dup("HOMARD");
4835 //===========================================================================
4836 char* ADAPT_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4837 const char* IORString,
4838 CORBA::Boolean isMultiFile,
4839 CORBA::Boolean isASCII)
4841 CORBA::String_var aString("");
4842 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4843 StudyContext context = myStudyContext;
4844 CORBA::Object_var anObj = _orb->string_to_object(IORString);
4845 if (!CORBA::is_nil(anObj)) {
4846 PortableServer::ServantBase_var aServant = GetServant(anObj);
4847 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4849 std::map<int, PortableServer::ServantBase*>::const_iterator it;
4850 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4851 if (it->second == aStorable) {
4852 std::stringstream os;
4854 aString = CORBA::string_dup(os.str().c_str());
4860 return aString._retn();
4863 //===========================================================================
4864 char* ADAPT_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4865 const char* aLocalPersistentID,
4866 CORBA::Boolean isMultiFile,
4867 CORBA::Boolean isASCII)
4869 CORBA::String_var aString("");
4870 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4871 StudyContext context = myStudyContext;
4872 int id = atoi(aLocalPersistentID);
4873 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4874 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4875 if (!CORBA::is_nil(object)) {
4876 aString = _orb->object_to_string(object);
4880 return aString._retn();
4883 //===========================================================================
4884 CORBA::Boolean ADAPT_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4886 if(CORBA::is_nil(myStudy))
4889 ADAPT::HOMARD_Cas_var aCas = ADAPT::HOMARD_Cas::_narrow(theIOR);
4890 if(!aCas->_is_nil())
4893 ADAPT::HOMARD_Hypothesis_var aHypo = ADAPT::HOMARD_Hypothesis::_narrow(theIOR);
4894 if(!aHypo->_is_nil())
4897 ADAPT::HOMARD_Zone_var aZone = ADAPT::HOMARD_Zone::_narrow(theIOR);
4898 if(!aZone->_is_nil())
4901 ADAPT::HOMARD_Boundary_var aBoundary = ADAPT::HOMARD_Boundary::_narrow(theIOR);
4902 if(!aBoundary->_is_nil())
4905 /* Iteration is not published directly
4906 ADAPT::HOMARD_Iteration_var aIter = ADAPT::HOMARD_Iteration::_narrow(theIOR);
4907 if(!aIter->_is_nil())
4913 //===========================================================================
4914 CORBA::Boolean ADAPT_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4916 // No Copy/Paste support
4920 //===========================================================================
4921 SALOMEDS::TMPFile* ADAPT_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4922 CORBA::Long& theObjectID)
4924 // No Copy/Paste support
4925 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4926 return aStreamFile._retn();
4929 //===========================================================================
4930 CORBA::Boolean ADAPT_Gen_i::CanPaste(const char *theComponentName,
4931 CORBA::Long theObjectID)
4933 // No Copy/Paste support
4937 //===========================================================================
4938 SALOMEDS::SObject_ptr ADAPT_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4939 CORBA::Long theObjectID,
4940 SALOMEDS::SObject_ptr theSObject)
4942 // No Copy/Paste support
4943 SALOMEDS::SObject_var aResultSO;
4944 return aResultSO._retn();
4947 //===========================================================================
4948 PortableServer::ServantBase_var ADAPT_Gen_i::GetServant(CORBA::Object_ptr theObject)
4950 PortableServer::Servant aServant = 0;
4951 if (!CORBA::is_nil(theObject)) {
4953 aServant = _poa->reference_to_servant(theObject);
4961 //==========================================================================
4962 Engines::TMPFile* ADAPT_Gen_i::DumpPython(CORBA::Boolean isPublished,
4963 CORBA::Boolean isMultiFile,
4964 CORBA::Boolean& isValidScript)
4966 MESSAGE ("Entree dans DumpPython");
4969 SALOMEDS::SObject_var aSO = SMESH_Gen_i::getStudyServant()->FindComponent("HOMARD");
4970 if(CORBA::is_nil(aSO))
4971 return new Engines::TMPFile(0);
4973 std::string aScript = "\"\"\"\n";
4974 aScript += "Python script for HOMARD\n";
4975 aScript += "Copyright 1996, 2011, 2015 EDF\n";
4976 aScript += "\"\"\"\n";
4977 aScript += "__revision__ = \"V1.2\"\n";
4978 aScript += "import HOMARD\n";
4980 aScript += "import salome\n";
4981 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4982 aScript += "\thomard.UpdateStudy()\n";
4983 MESSAGE (". Au depart \n"<<aScript);
4986 if (myStudyContext._mesBoundarys.size() > 0)
4988 MESSAGE (". Ecritures des frontieres");
4989 aScript += "#\n# Creation of the boundaries";
4990 aScript += "\n# ==========================";
4992 std::map<std::string, ADAPT::HOMARD_Boundary_var>::const_iterator it_boundary;
4993 for (it_boundary = myStudyContext._mesBoundarys.begin();
4994 it_boundary != myStudyContext._mesBoundarys.end(); ++it_boundary)
4996 ADAPT::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4997 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4998 std::string dumpBoundary = dumpCorbaBoundary.in();
4999 MESSAGE (dumpBoundary<<"\n");
5000 aScript += dumpBoundary;
5004 if (myStudyContext._mesZones.size() > 0)
5006 MESSAGE (". Ecritures des zones");
5007 aScript += "#\n# Creation of the zones";
5008 aScript += "\n# =====================";
5010 std::map<std::string, ADAPT::HOMARD_Zone_var>::const_iterator it_zone;
5011 for ( it_zone = myStudyContext._mesZones.begin();
5012 it_zone != myStudyContext._mesZones.end(); ++it_zone)
5014 ADAPT::HOMARD_Zone_var myZone = (*it_zone).second;
5015 CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
5016 std::string dumpZone = dumpCorbaZone.in();
5017 MESSAGE (dumpZone<<"\n");
5018 aScript += dumpZone;
5022 if (myStudyContext._mesHypotheses.size() > 0)
5024 MESSAGE (". Ecritures des hypotheses");
5025 aScript += "#\n# Creation of the hypotheses";
5026 aScript += "\n# ==========================";
5028 std::map<std::string, ADAPT::HOMARD_Hypothesis_var>::const_iterator it_hypo;
5029 for ( it_hypo = myStudyContext._mesHypotheses.begin();
5030 it_hypo != myStudyContext._mesHypotheses.end(); it_hypo++)
5032 ADAPT::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
5033 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
5034 std::string dumpHypo = dumpCorbaHypo.in();
5035 MESSAGE (dumpHypo<<"\n");
5036 aScript += dumpHypo;
5040 if (myStudyContext._mesCas.size() > 0)
5042 MESSAGE (". Ecritures des cas");
5043 aScript += "#\n# Creation of the cases";
5044 aScript += "\n# =====================";
5046 std::map<std::string, ADAPT::HOMARD_Cas_var>::const_iterator it_cas;
5047 for (it_cas = myStudyContext._mesCas.begin();
5048 it_cas != myStudyContext._mesCas.end(); it_cas++)
5050 std::string nomCas = (*it_cas).first;
5051 std::string dumpCas = std::string("\n# Creation of the case ") ;
5052 dumpCas += nomCas + std::string("\n");
5053 dumpCas += std::string("\t") + nomCas;
5054 dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
5056 ADAPT::HOMARD_Cas_var myCase = (*it_cas).second;
5057 CORBA::String_var cIter0= myCase->GetIter0Name();
5058 std::string iter0 = cIter0.in();
5060 ADAPT::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[iter0];
5061 CORBA::String_var cMesh0= myIteration->GetMeshFile();
5062 std::string mesh0 = cMesh0.in();
5063 CORBA::String_var cMeshName0= myIteration->GetMeshName();
5064 std::string meshName0 = cMeshName0.in();
5065 dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
5066 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
5067 std::string dumpCas2= dumpCorbaCase.in();
5069 MESSAGE (dumpCas<<dumpCas2<<"\n");
5070 aScript += dumpCas + dumpCas2;
5074 if (myStudyContext._mesIterations.size() > 0)
5076 MESSAGE (". Ecritures des iterations");
5077 aScript += "#\n# Creation of the iterations" ;
5078 aScript += "\n# ==========================";
5080 std::map<std::string, ADAPT::HOMARD_Iteration_var>::const_iterator it_iter;
5081 for (it_iter = myStudyContext._mesIterations.begin();
5082 it_iter != myStudyContext._mesIterations.end(); ++it_iter)
5084 ADAPT::HOMARD_Iteration_var aIter = (*it_iter).second;
5085 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
5086 std::string dumpIter = dumpCorbaIter.in();
5087 MESSAGE (dumpIter<<"\n");
5088 aScript += dumpIter;
5092 if (myStudyContext._mesYACSs.size() > 0)
5094 MESSAGE (". Ecritures des schemas YACS");
5095 aScript += "#\n# Creation of the schemas YACS";
5096 aScript += "\n# ============================";
5098 std::map<std::string, ADAPT::HOMARD_YACS_var>::const_iterator it_yacs;
5099 for ( it_yacs = myStudyContext._mesYACSs.begin();
5100 it_yacs != myStudyContext._mesYACSs.end(); ++it_yacs)
5102 ADAPT::HOMARD_YACS_var myYACS = (*it_yacs).second;
5103 CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
5104 std::string dumpYACS = dumpCorbaYACS.in();
5105 MESSAGE (dumpYACS<<"\n");
5106 aScript += dumpYACS;
5109 MESSAGE (". Ecritures finales");
5111 aScript += "\n\tpass";
5114 if( !isMultiFile ) // remove unnecessary tabulation
5115 aScript = RemoveTabulation( aScript );
5117 // MESSAGE ("A ecrire \n"<<aScript);
5118 const size_t aLen = strlen(aScript.c_str());
5119 char* aBuffer = new char[aLen+1];
5120 strcpy(aBuffer, aScript.c_str());
5122 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
5123 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
5125 MESSAGE ("Sortie de DumpPython");
5126 return aStreamFile._retn();
5130 //=============================================================================
5131 //=============================================================================
5133 //=============================================================================
5134 //=============================================================================
5135 void ADAPT_Gen_i::IsValidStudy( )
5137 // MESSAGE( "IsValidStudy" );
5138 if (CORBA::is_nil(SMESH_Gen_i::getStudyServant()))
5140 SALOME::ExceptionStruct es;
5141 es.type = SALOME::BAD_PARAM;
5142 es.text = "Invalid study context";
5143 throw SALOME::SALOME_Exception(es);
5148 //=============================================================================
5149 char* ADAPT_Gen_i::VerifieDir(const char* nomDir)
5151 std::string casename = std::string("") ;
5152 std::map<std::string, ADAPT::HOMARD_Cas_var>::const_iterator it;
5153 for (it = myStudyContext._mesCas.begin();
5154 it != myStudyContext._mesCas.end(); it++)
5156 if (std::string(nomDir) == std::string(it->second->GetDirName()))
5158 casename = std::string(it->second->GetName()) ;
5162 return CORBA::string_dup( casename.c_str() );
5164 /*//=============================================================================
5165 void SALOMEException( std::string message )
5167 SALOME::ExceptionStruct es;
5168 es.type = SALOME::BAD_PARAM;
5170 throw SALOME::SALOME_Exception(es);
5173 //=============================================================================
5174 char* ADAPT_Gen_i::getVersion()
5176 #if HOMARD_DEVELOPMENT
5177 return CORBA::string_dup(SMESH_VERSION_STR"dev");
5179 return CORBA::string_dup(SMESH_VERSION_STR);
5182 //===============================================================================
5183 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un caractere
5184 // ligne : la ligne a manipuler
5185 // caractere : le caractere a reperer
5186 // option : 0 : la chaine avant la premiere apparition du caractere
5187 // 1 : la chaine apres la premiere apparition du caractere
5188 // 2 : la chaine avant la derniere apparition du caractere
5189 // 3 : la chaine apres la derniere apparition du caractere
5190 // Si le caractere est absent, on retourne la chaine totale
5191 //===============================================================================
5192 std::string ADAPT_Gen_i::GetStringInTexte( const std::string ligne, const std::string caractere, int option )
5194 // MESSAGE("GetStringInTexte, recherche de '"<<caractere<<"' dans '"<<ligne<<"'"<<", option = "<<option);
5196 std::string chaine = ligne ;
5198 if ( option < 2 ) { position = ligne.find_first_of( caractere ) ; }
5199 else { position = ligne.find_last_of( caractere ) ; }
5200 // MESSAGE("position = "<<position);
5201 // MESSAGE("a = "<<ligne.substr( 0, position ).c_str());
5202 // MESSAGE("b = "<<ligne.substr( position+1 ).c_str());
5204 if ( position != std::string::npos )
5206 if ( ( option == 0 ) || ( option == 2 ) ) { chaine = ligne.substr( 0, position ) ; }
5207 else { chaine = ligne.substr( position+1 ) ; }
5212 //=============================================================================
5213 //=============================================================================
5214 // Gestion des preferences
5215 //=============================================================================
5216 //=============================================================================
5217 // Decodage du fichier d'arcihvage des preferences
5219 void ADAPT_Gen_i::SetPreferences( )
5221 MESSAGE ( "SetPreferences" );
5223 std::string ligne, mot_cle, salome_version ;
5226 // A. Les valeurs par defaut ; elles doivent etre coherentes
5227 std::string LanguageShort = "en" ;
5228 int PublisMeshIN = 0 ;
5229 int PublisMeshOUT = 0 ;
5230 int YACSMaxIter = 0 ;
5231 int YACSMaxNode = 0 ;
5232 int YACSMaxElem = 0 ;
5233 std::string YACSTypeTestchaine = "None" ;
5235 // B. La version de salome
5236 // Cela se presente sous la forme :
5237 // [SALOME KERNEL] : 7.3.0
5239 File = getenv("KERNEL_ROOT_DIR") ;
5240 File += "/bin/salome/VERSION" ;
5241 MESSAGE ( "File = "<<File ) ;
5242 std::ifstream fichier0( File.c_str() ) ;
5243 if ( fichier0 ) // ce test échoue si le fichier n'est pas ouvert
5245 std::string ligne; // variable contenant chaque ligne lue
5246 while ( std::getline( fichier0, ligne ) )
5248 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5249 ligne_bis >> mot_cle ;
5250 if ( mot_cle == "[SALOME" )
5252 salome_version = GetStringInTexte ( ligne, " ", 3 ) ;
5253 // MESSAGE ( "salome_version = "<<salome_version<<"|||");
5258 else { ok = false ; }
5260 // B. Decodage du fichier de preferences
5263 std::string PrefFile ;
5264 PrefFile = Kernel_Utils::HomePath() ;
5265 PrefFile += "/.config/salome/SalomeApprc." + salome_version ;
5266 MESSAGE ( "PrefFile = "<<PrefFile ) ;
5268 std::ifstream fichier( PrefFile.c_str() );
5269 if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
5271 bool section_langue = false ;
5272 bool section_homard = false ;
5273 while ( std::getline( fichier, ligne ) )
5275 std::string chaine ;
5276 // 1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
5277 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5278 ligne_bis >> mot_cle ;
5281 // 2.1. Debut d'une section
5282 // MESSAGE(mot_cle);
5283 if ( mot_cle == "<section" )
5284 { /*MESSAGE ( "Debut de la section : "<< ligne);*/
5285 ligne_bis >> mot_cle ;
5286 chaine = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5287 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5288 if ( chaine == "language" ) { section_langue = true ; }
5289 if ( chaine == "HOMARD" ) { section_homard = true ; }
5290 // MESSAGE ( "section_langue = "<<section_langue<<", section_homard = "<<section_homard);
5292 // 2.2. Fin d'une section
5293 else if ( mot_cle == "</section>" )
5294 { /*MESSAGE ( "Fin de la section : "<< ligne<<", section_langue = "<<section_langue<<", section_homard = "<<section_homard);*/
5295 section_langue = false ;
5296 section_homard = false ; }
5300 else if ( section_langue || section_homard )
5301 { MESSAGE ( "a decoder : "<< ligne);
5302 // La valeur : entre les deux premieres quotes
5303 chaine = GetStringInTexte ( ligne, "\"", 1 ) ;
5304 // MESSAGE("chaine 1 = |"<<chaine<<"|");
5305 chaine = GetStringInTexte ( chaine, "\"", 0 ) ;
5306 // MESSAGE("chaine = |"<<chaine<<"|");
5307 // Le mot_cle : entre les deux dernieres quotes
5308 std::string chaine2 = GetStringInTexte ( ligne, "\"", 2 ) ;
5309 // MESSAGE("chaine2 1 = |"<<chaine2<<"|");
5310 chaine2 = GetStringInTexte ( chaine2, "\"", 3 ) ;
5311 // MESSAGE("chaine2 = |"<<chaine2<<"|");
5313 if ( section_langue )
5314 { if ( chaine2 == "language" ) { LanguageShort = chaine ; } }
5316 if ( section_homard )
5318 std::istringstream chainebis( chaine ) ;
5319 // 3.2.1. Les publications
5320 if ( chaine2 == "homard_publish_mesh_in" ) { chainebis >> PublisMeshIN ; }
5321 if ( chaine2 == "homard_publish_mesh_out" ) { chainebis >> PublisMeshOUT ; }
5322 // 3.2.2. Les maximum pour YACS
5323 if ( chaine2 == "homard_yacs_max_iter" ) { chainebis >> YACSMaxIter ; }
5324 if ( chaine2 == "homard_yacs_max_node" ) { chainebis >> YACSMaxNode ; }
5325 if ( chaine2 == "homard_yacs_max_elem" ) { chainebis >> YACSMaxElem ; }
5326 if ( chaine2 == "homard_yacs_type_test" ) { YACSTypeTestchaine = chaine ; }
5333 // C. Enregistrements
5334 MESSAGE ("Enregistrement de LanguageShort = " << LanguageShort );
5335 SetLanguageShort( LanguageShort.c_str() ) ;
5337 MESSAGE ("Enregistrement de PublisMeshIN = " << PublisMeshIN<<", PublisMeshOUT = "<< PublisMeshOUT);
5338 SetPublisMesh(PublisMeshIN, PublisMeshOUT) ;
5340 MESSAGE ("Enregistrement de YACSMaxIter = " << YACSMaxIter<<", YACSMaxNode = "<< YACSMaxNode<<", YACSMaxElem = "<< YACSMaxElem);
5341 SetYACSMaximum(YACSMaxIter, YACSMaxNode, YACSMaxElem) ;
5343 MESSAGE ("Enregistrement de TypeTest = " << YACSTypeTestchaine.c_str() );
5345 if ( ( YACSTypeTestchaine == "VTest > VRef" ) || ( YACSTypeTestchaine == "VTest > VRef" ) ) { YACSTypeTest = 1 ; }
5346 else if ( ( YACSTypeTestchaine == "VTest < VRef" ) || ( YACSTypeTestchaine == "VTest < VRef" ) ) { YACSTypeTest = 2 ; }
5347 else { YACSTypeTest = 0 ; }
5348 MESSAGE ("==> TypeTest = " << YACSTypeTest );
5349 SetYACSConvergenceType( YACSTypeTest ) ;
5353 //===============================================================================
5355 //===============================================================================
5356 void ADAPT_Gen_i::SetLanguageShort(const char* LanguageShort)
5358 // MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
5359 _LangueShort = LanguageShort ;
5360 if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
5361 else { _Langue = "English" ; }
5364 char* ADAPT_Gen_i::GetLanguageShort()
5366 // MESSAGE ("GetLanguageShort");
5367 return CORBA::string_dup( _LangueShort.c_str() );
5369 //===============================================================================
5370 // Options de publications
5371 //===============================================================================
5372 void ADAPT_Gen_i::SetPublisMesh(CORBA::Long PublisMeshIN, CORBA::Long PublisMeshOUT)
5374 _PublisMeshIN = PublisMeshIN ;
5375 _PublisMeshOUT = PublisMeshOUT ;
5378 CORBA::Long ADAPT_Gen_i::GetPublisMeshIN()
5380 return _PublisMeshIN ;
5382 CORBA::Long ADAPT_Gen_i::GetPublisMeshOUT()
5384 return _PublisMeshOUT ;
5386 //===============================================================================
5387 // YACS - test de convergence
5388 //===============================================================================
5389 void ADAPT_Gen_i::SetYACSMaximum(CORBA::Long YACSMaxIter, CORBA::Long YACSMaxNode, CORBA::Long YACSMaxElem)
5391 _YACSMaxIter = YACSMaxIter ;
5392 _YACSMaxNode = YACSMaxNode ;
5393 _YACSMaxElem = YACSMaxElem ;
5396 CORBA::Long ADAPT_Gen_i::GetYACSMaxIter()
5398 return _YACSMaxIter ;
5400 CORBA::Long ADAPT_Gen_i::GetYACSMaxNode()
5402 return _YACSMaxNode ;
5404 CORBA::Long ADAPT_Gen_i::GetYACSMaxElem()
5406 return _YACSMaxElem ;
5408 void ADAPT_Gen_i::SetYACSConvergenceType(CORBA::Long YACSTypeTest)
5410 _YACSTypeTest = YACSTypeTest ;
5413 CORBA::Long ADAPT_Gen_i::GetYACSConvergenceType()
5415 return _YACSTypeTest ;
5418 //=============================================================================
5422 PortableServer::ObjectId* ADAPTEngine_factory(CORBA::ORB_ptr orb,
5423 PortableServer::POA_ptr poa,
5424 PortableServer::ObjectId* contId,
5425 const char* instanceName,
5426 const char* interfaceName)
5428 MESSAGE("PortableServer::ObjectId* ADAPTEngine_factory()");
5429 ADAPT_Gen_i* myADAPT_Gen = new ADAPT_Gen_i(orb, poa, contId, instanceName, interfaceName);
5430 return myADAPT_Gen->getId();