1 // Copyright (C) 2011-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "HOMARD_Gen_i.hxx"
21 #include "HOMARD_Cas_i.hxx"
22 #include "HOMARD_Hypothesis_i.hxx"
23 #include "HOMARD_Iteration_i.hxx"
24 #include "HOMARD_Boundary_i.hxx"
25 #include "HOMARD_Zone_i.hxx"
26 #include "HomardDriver.hxx"
27 #include "HOMARD_DriverTools.hxx"
28 #include "HomardMedCommun.h"
30 #include "HOMARD_version.h"
32 #include "utilities.h"
33 #include "Utils_SINGLETON.hxx"
34 #include "Utils_CorbaException.hxx"
35 #include "SALOMEDS_Tool.hxx"
36 #include "SALOME_LifeCycleCORBA.hxx"
37 #include "SALOMEconfig.h"
38 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
39 #include CORBA_CLIENT_HEADER(SMESH_Gen)
55 //=======================================================================
56 //function : RemoveTabulation
58 //=======================================================================
59 std::string RemoveTabulation( std::string theScript )
61 std::string::size_type aPos = 0;
62 while( aPos < theScript.length() )
64 aPos = theScript.find( "\n\t", aPos );
65 if( aPos == std::string::npos )
67 theScript.replace( aPos, 2, "\n" );
73 //=============================================================================
75 * standard constructor
77 //=============================================================================
78 HOMARD_Gen_i::HOMARD_Gen_i( CORBA::ORB_ptr orb,
79 PortableServer::POA_ptr poa,
80 PortableServer::ObjectId * contId,
81 const char *instanceName,
82 const char *interfaceName) :
83 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
85 MESSAGE("constructor");
87 _id = _poa->activate_object(_thisObj);
89 myHomard = new ::HOMARD_Gen();
90 _NS = SINGLETON_<SALOME_NamingService>::Instance();
91 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
95 //=================================
99 //================================
100 HOMARD_Gen_i::~HOMARD_Gen_i()
103 //=============================================================================
105 * Ajoute le composant homard dans l etude si necessaire
107 //=============================================================================
108 void HOMARD_Gen_i::addInStudy(SALOMEDS::Study_ptr theStudy)
110 ASSERT(!CORBA::is_nil(theStudy));
111 MESSAGE("addInStudy: ajout eventuel du composant HOMARD dans current study ID = " << GetCurrentStudyID()) ;
112 SALOMEDS::StudyBuilder_var myBuilder = theStudy->NewBuilder();
114 // Create SComponent labelled 'homard' if it doesn't already exit
115 SALOMEDS::SComponent_var homardFather = theStudy->FindComponent(ComponentDataType());
116 if (CORBA::is_nil(homardFather))
118 myBuilder->NewCommand();
119 MESSAGE("Add Component HOMARD");
121 bool aLocked = theStudy->GetProperties()->IsLocked();
122 if (aLocked) theStudy->GetProperties()->SetLocked(false);
124 homardFather = myBuilder->NewComponent(ComponentDataType());
125 SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
126 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
127 CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
128 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
129 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
130 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
131 if (!Comp->_is_nil())
133 aName->SetValue(ComponentDataType());
136 anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributePixMap");
137 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
138 aPixmap->SetPixMap("HOMARD_2.png");
139 myBuilder->DefineComponentInstance(homardFather, HOMARD_Gen::_this());
141 if (aLocked) theStudy->GetProperties()->SetLocked(true);
142 myBuilder->CommitCommand();
146 //=============================================================================
151 //=============================================================================
152 void HOMARD_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy)
154 MESSAGE("SetCurrentStudy: current study Id = " << GetCurrentStudyID());
155 myCurrentStudy = SALOMEDS::Study::_duplicate(theStudy);
156 this->addInStudy(myCurrentStudy);
159 //=============================================================================
160 SALOMEDS::Study_ptr HOMARD_Gen_i::GetCurrentStudy()
161 //=============================================================================
163 MESSAGE("GetCurrentStudy: study Id = " << GetCurrentStudyID());
164 return SALOMEDS::Study::_duplicate(myCurrentStudy);
167 //=============================================================================
168 CORBA::Long HOMARD_Gen_i::GetCurrentStudyID()
169 //=============================================================================
171 return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId();
174 //=============================================================================
175 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
177 MESSAGE( "AssociateCaseIter : " << nomCas << " ," << nomIter << "," << labelIter );
180 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
181 if (CORBA::is_nil(myCase))
183 SALOME::ExceptionStruct es;
184 es.type = SALOME::BAD_PARAM;
185 es.text = "Invalid Case ";
186 throw SALOME::SALOME_Exception(es);
190 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
191 if (CORBA::is_nil(myIteration))
193 SALOME::ExceptionStruct es;
194 es.type = SALOME::BAD_PARAM;
195 es.text = "Invalid Case ";
196 throw SALOME::SALOME_Exception(es);
200 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
201 SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
202 if (CORBA::is_nil(aCasSO))
204 SALOME::ExceptionStruct es;
205 es.type = SALOME::BAD_PARAM;
206 es.text = "Invalid Case ";
207 throw SALOME::SALOME_Exception(es);
211 aStudyBuilder->NewCommand();
212 SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
213 PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
214 "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
215 aStudyBuilder->CommitCommand();
217 myCase->AddIteration(nomIter);
218 myIteration->SetCaseName(nomCas);
221 //=====================================================================================
222 void HOMARD_Gen_i::SetEtatIter(const char* nomIter, const CORBA::Boolean EtatCalcul)
223 //=====================================================================================
225 MESSAGE( "SetEtatIter : nomIter = " << nomIter << " etat " << EtatCalcul );
226 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
227 if (CORBA::is_nil(myIteration))
229 SALOME::ExceptionStruct es;
230 es.type = SALOME::BAD_PARAM;
231 es.text = "Invalid Iteration ";
232 throw SALOME::SALOME_Exception(es);
236 myIteration->SetEtat(EtatCalcul);
238 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
239 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
240 if (CORBA::is_nil(myIteration))
242 SALOME::ExceptionStruct es;
243 es.type = SALOME::BAD_PARAM;
244 es.text = "Invalid Iteration ";
245 throw SALOME::SALOME_Exception(es);
249 int number = myIteration->GetNumber() ;
252 icone = "iter0.png" ;
254 icone = "iter_calculee.png" ;
256 icone = "iter_non_calculee.png" ;
257 PublishInStudyAttr(aStudyBuilder, aIterSO, NULL , NULL, icone, NULL) ;
259 aStudyBuilder->CommitCommand();
262 //=====================================================================================
263 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
264 //=====================================================================================
266 MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName );
267 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
268 if (CORBA::is_nil(myBoundary))
270 SALOME::ExceptionStruct es;
271 es.type = SALOME::BAD_PARAM;
272 es.text = "Invalid Boundary ";
273 throw SALOME::SALOME_Exception(es);
276 SALOME::ExceptionStruct es;
277 es.type = SALOME::BAD_PARAM;
278 es.text = "No change is allowed in boundary. Ask for evolution.";
279 throw SALOME::SALOME_Exception(es);
281 /* HOMARD::listeHypo* maListe = myBoundary->GetHypo();
282 int numberOfHypo = maListe->length();
283 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
285 std::string nomHypo = std::string((*maListe)[NumeHypo]);
286 InvalideHypo(nomHypo.c_str());
289 //=====================================================================================
290 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
291 //=====================================================================================
293 MESSAGE( "InvalideZone : ZoneName = " << ZoneName );
294 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
295 if (CORBA::is_nil(myZone))
297 SALOME::ExceptionStruct es;
298 es.type = SALOME::BAD_PARAM;
299 es.text = "Invalid Zone ";
300 throw SALOME::SALOME_Exception(es);
303 HOMARD::listeHypo* maListe = myZone->GetHypo();
304 int numberOfHypo = maListe->length();
305 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
307 std::string nomHypo = std::string((*maListe)[NumeHypo]);
308 InvalideHypo(nomHypo.c_str());
311 //=====================================================================================
312 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
313 //=====================================================================================
315 MESSAGE( "InvalideHypo : nomHypo = " << nomHypo );
316 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
317 if (CORBA::is_nil(myHypo))
319 SALOME::ExceptionStruct es;
320 es.type = SALOME::BAD_PARAM;
321 es.text = "Invalid Hypothesis ";
322 throw SALOME::SALOME_Exception(es);
326 HOMARD::listeIters* maListe = myHypo->GetIterations();
327 int numberOfIter = maListe->length();
328 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
330 std::string nomIter = std::string((*maListe)[NumeIter]);
331 InvalideIter(nomIter.c_str());
335 //=====================================================================================
336 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
337 //=====================================================================================
339 MESSAGE("InvalideIter : nomIter = " << nomIter);
340 SetEtatIter(nomIter,false);
341 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
342 if (CORBA::is_nil(myIteration))
344 SALOME::ExceptionStruct es;
345 es.type = SALOME::BAD_PARAM;
346 es.text = "Invalid Iteration ";
347 throw SALOME::SALOME_Exception(es);
351 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
352 int numberOfIter = maListe->length();
353 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
355 std::string nomIterFille = std::string((*maListe)[NumeIter]);
356 InvalideIter(nomIterFille.c_str());
359 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
360 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
361 for (; aIter->More(); aIter->Next())
363 SALOMEDS::SObject_var so = aIter->Value();
364 SALOMEDS::GenericAttribute_var anAttr;
365 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
366 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
367 std::string value (aCommentAttr->Value());
368 if(value == std::string("HypoHomard")) continue;
369 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
370 aStudyBuilder->RemoveObject(so);
372 const char * nomCas = myIteration->GetCaseName();
373 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
374 if (CORBA::is_nil(myCase))
376 SALOME::ExceptionStruct es;
377 es.type = SALOME::BAD_PARAM;
378 es.text = "Invalid Case Context ";
379 throw SALOME::SALOME_Exception(es);
382 const char* dirParent = myCase->GetDirName();
383 const char* nomDir = myIteration->GetDirName();
384 const char* nomFichier = myIteration->GetMeshFile();
385 std::string commande= "rm -rf " + std::string(dirParent) + "/" + std::string(nomDir);
386 commande = commande + ";rm -rf " + std::string(nomFichier);
387 if ((system(commande.c_str())) != 0)
389 SALOME::ExceptionStruct es;
390 es.type = SALOME::BAD_PARAM;
391 es.text = "Menage du repertoire de calcul impossible" ;
392 throw SALOME::SALOME_Exception(es);
395 // Suppression du maillage publie dans SMESH
396 const char* MeshName = myIteration->GetMeshName();
397 DeleteResultInSmesh(nomFichier, MeshName) ;
400 //=====================================================================================
401 void HOMARD_Gen_i::DissociateHypoZone(const char* ZoneName, const char* nomHypothesis)
403 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
406 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
407 ASSERT(!CORBA::is_nil(myHypo));
408 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
409 ASSERT(!CORBA::is_nil(aHypoSO));
411 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
412 ASSERT(!CORBA::is_nil(myZone));
413 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
414 ASSERT(!CORBA::is_nil(aZoneSO));
417 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
419 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator(aHypoSO);
420 for (; it->More(); it->Next())
422 SALOMEDS::SObject_var aHypObj = it->Value();
423 SALOMEDS::SObject_var ptrObj;
424 if (aHypObj->ReferencedObject(ptrObj))
426 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
428 aStudyBuilder->NewCommand();
429 aStudyBuilder->RemoveObject(aHypObj);
430 aStudyBuilder->CommitCommand();
436 myZone->SupprHypo(nomHypothesis);
437 myHypo->SupprZone(ZoneName);
440 //===================================================================================
441 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
443 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
446 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
447 ASSERT(!CORBA::is_nil(myHypo));
448 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
449 ASSERT(!CORBA::is_nil(aHypoSO));
451 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
452 ASSERT(!CORBA::is_nil(myIteration));
453 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
454 ASSERT(!CORBA::is_nil(aIterSO));
456 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
458 aStudyBuilder->NewCommand();
460 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
461 aStudyBuilder->Addreference(aSubSO, aHypoSO);
463 aStudyBuilder->CommitCommand();
465 myIteration->SetHypoName(nomHypo);
466 myHypo->AddIteration(nomIter);
469 //=============================================================================
470 CORBA::Boolean HOMARD_Gen_i::VerifieDir(const char* nomDir)
472 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
473 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
474 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
476 if (std::string(nomDir) == std::string(it->second->GetDirName())) return false;
481 //=============================================================================
482 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
484 MESSAGE ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
487 if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
489 SALOME::ExceptionStruct es;
490 es.type = SALOME::BAD_PARAM;
491 es.text = "This case has already been defined";
492 throw SALOME::SALOME_Exception(es);
496 HOMARD::HOMARD_Cas_var myCase = newCase();
497 myCase->SetName(nomCas);
498 SALOMEDS::SObject_var aSO;
499 PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
500 myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
503 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile);
504 HOMARD::extrema_var aSeq = new HOMARD::extrema();
505 if (LesExtremes.size()!=10) { return false; }
507 for (int i =0; i< LesExtremes.size(); i++)
508 aSeq[i]=LesExtremes[i];
509 myCase->SetBoundingBox(aSeq);
511 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile);
512 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType;
513 aSeqGroupe->length(LesGroupes.size());
514 std::set<std::string>::const_iterator it;
516 for (it=LesGroupes.begin() ; it != LesGroupes.end(); it++)
517 aSeqGroupe[i++]=(*it).c_str();
518 myCase->SetGroups(aSeqGroupe);
520 // Recherche d'un nom pour l'iteration 0. Par defaut, on prend le nom
521 // du maillage du cas. Si ce nom existe deja, on incremente avec 0, 1, 2, etc.
523 std::string nomIter = std::string(MeshName) ;
524 while ((myContextMap[GetCurrentStudyID()]._mesIterations).find(nomIter) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()))
526 std::ostringstream nom;
527 nom << MeshName << monNum;
531 MESSAGE ( "CreateCase : nomIter = " << nomIter );
533 HOMARD::HOMARD_Iteration_var anIter = newIteration();
534 myContextMap[GetCurrentStudyID()]._mesIterations[nomIter] = anIter;
535 std::ostringstream DirName;
538 anIter->SetDirName(DirName.str().c_str());
539 anIter->SetName(nomIter.c_str());
540 anIter->SetMeshFile(MeshFile);
541 anIter->SetMeshName(MeshName);
542 anIter->SetNumber(0);
544 AssociateCaseIter (nomCas,nomIter.c_str(),"IterationHomard");
545 SetEtatIter(nomIter.c_str(),true);
547 PublishResultInSmesh(MeshFile, 0);
549 // Valeurs par defaut des filtrages
552 return HOMARD::HOMARD_Cas::_duplicate(myCase);
555 //=============================================================================
556 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
559 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
560 if (CORBA::is_nil(myCase))
562 SALOME::ExceptionStruct es;
563 es.type = SALOME::BAD_PARAM;
564 es.text = "Invalid Case";
565 throw SALOME::SALOME_Exception(es);
569 return HOMARD::HOMARD_Cas::_duplicate(myCase);
572 //=============================================================================
573 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
576 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
577 ASSERT(!CORBA::is_nil(myZone));
578 return HOMARD::HOMARD_Zone::_duplicate(myZone);
581 //=============================================================================
582 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
584 MESSAGE ( "GetHypothesis : nomHypothesis = " << nomHypothesis );
586 MESSAGE ( "GetHypothesis : GetCurrentStudyID() = " << GetCurrentStudyID() );
587 HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
588 ASSERT(!CORBA::is_nil(myHypothesis));
589 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
592 //=============================================================================
593 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* nomIteration)
596 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIteration];
597 ASSERT(!CORBA::is_nil(myIteration));
598 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
600 //=============================================================================
601 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
605 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
606 ASSERT(!CORBA::is_nil(myBoundary));
607 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
610 //=============================================================================
611 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
613 MESSAGE ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
616 if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
618 SALOME::ExceptionStruct es;
619 es.type = SALOME::BAD_PARAM;
620 es.text = "This hypothesis is already defined.";
621 throw SALOME::SALOME_Exception(es);
625 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
626 myHypothesis->SetName(nomHypothesis);
627 myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
628 SALOMEDS::SObject_var aSO;
629 PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
631 // Valeurs par defaut des options avancees
632 myHypothesis->SetNivMax(-1);
633 myHypothesis->SetDiamMin(-1.0);
634 myHypothesis->SetAdapInit(0);
635 myHypothesis->SetLevelOutput(0);
637 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
640 //============================================================================================================
641 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* nomIteration, const char* nomIterParent)
642 //============================================================================================================
644 MESSAGE ("CreateIteration : nomIteration = " << nomIteration << "nomIterParent = " << nomIterParent);
647 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
648 if (CORBA::is_nil(myIterationParent))
650 SALOME::ExceptionStruct es;
651 es.type = SALOME::BAD_PARAM;
652 es.text = "The parent iteration is not defined.";
653 throw SALOME::SALOME_Exception(es);
657 const char* nomCas = myIterationParent->GetCaseName();
658 MESSAGE ("CreateIteration : nomCas = " << nomCas);
659 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
660 if (CORBA::is_nil(myCase))
662 SALOME::ExceptionStruct es;
663 es.type = SALOME::BAD_PARAM;
664 es.text = "Invalid Case Context ";
665 throw SALOME::SALOME_Exception(es);
669 if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(nomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
671 SALOME::ExceptionStruct es;
672 es.type = SALOME::BAD_PARAM;
673 es.text = "This iteration is already defined. ";
674 throw SALOME::SALOME_Exception(es);
678 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
679 if (CORBA::is_nil(myIteration))
681 SALOME::ExceptionStruct es;
682 es.type = SALOME::BAD_PARAM;
683 es.text = "Unable to create Iteration ";
684 throw SALOME::SALOME_Exception(es);
687 myContextMap[GetCurrentStudyID()]._mesIterations[std::string(nomIteration)] = myIteration;
688 // Nom de l'iteration et du maillage
689 myIteration->SetName(nomIteration);
690 myIteration->SetMeshName(nomIteration);
692 int numero = myIterationParent->GetNumber() + 1;
693 myIteration->SetNumber(numero);
695 // Nombre d'iterations deja connues pour le cas, permettant
696 // la creation d'un sous-repertoire unique
697 int nbitercase = myCase->GetNumber();
698 std::ostringstream iaux ;
699 iaux << std::setw(2) << std::setfill('0') << nbitercase ;
700 std::stringstream DirName;
701 DirName << "I" << iaux.str();
702 myIteration->SetDirName(DirName.str().c_str());
704 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
705 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
706 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est le
707 // cas le plus frequent.
708 // Si on a plusieurs branches, donc des iterations a meme niveau d'adaptation, utiliser
709 // le nombre d'iterations du cas permet d'eviter les collisions.
710 std::stringstream MeshFile;
711 const char* nomDir = myCase->GetDirName();
712 MeshFile << nomDir << "/maill." << iaux.str() << ".med";
713 myIteration->SetMeshFile(MeshFile.str().c_str());
715 // Association avec le cas
716 std::string label = "IterationHomard_" + std::string(nomIterParent);
717 AssociateCaseIter(nomCas, nomIteration, label.c_str());
718 // Association avec l'iteration precedente
719 myIterationParent->AddIteration(nomIteration);
720 myIteration->SetIterParentName(nomIterParent);
722 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
726 //=============================================================================
727 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
729 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
732 if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
734 SALOME::ExceptionStruct es;
735 es.type = SALOME::BAD_PARAM;
736 es.text = "This boundary has already been defined";
737 throw SALOME::SALOME_Exception(es);
741 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
742 myBoundary->SetName(BoundaryName);
743 myBoundary->SetType(BoundaryType);
745 myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
747 SALOMEDS::SObject_var aSO;
748 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
750 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
752 //=============================================================================
753 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
755 MESSAGE ("CreateBoundaryDi : BoundaryName = " << BoundaryName << "MeshName = " << MeshName );
756 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
757 myBoundary->SetMeshFile( MeshFile ) ;
758 myBoundary->SetMeshName( MeshName ) ;
760 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
762 //=============================================================================
763 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
764 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
765 CORBA::Double Xaxis, CORBA::Double Yaxis, CORBA::Double Zaxis,
768 MESSAGE ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
769 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
770 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxis, Yaxis, Zaxis, Rayon ) ;
772 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
774 //=============================================================================
775 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
776 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
779 MESSAGE ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
780 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
781 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
783 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
787 //=============================================================================
788 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
790 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
793 if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
795 SALOME::ExceptionStruct es;
796 es.type = SALOME::BAD_PARAM;
797 es.text = "This zone has already been defined";
798 throw SALOME::SALOME_Exception(es);
802 HOMARD::HOMARD_Zone_var myZone = newZone();
803 myZone->SetName(ZoneName);
804 myZone->SetType(ZoneType);
806 myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
808 SALOMEDS::SObject_var aSO;
809 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
811 return HOMARD::HOMARD_Zone::_duplicate(myZone);
813 //=============================================================================
814 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
815 CORBA::Double Xmini, CORBA::Double Xmaxi,
816 CORBA::Double Ymini, CORBA::Double Ymaxi,
817 CORBA::Double Zmini, CORBA::Double Zmaxi)
819 MESSAGE ("CreateZoneBox : ZoneName = " << ZoneName ) ;
820 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
821 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
823 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
825 //=============================================================================
826 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
827 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
829 MESSAGE ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
830 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
831 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
833 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
835 //=============================================================================
836 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
837 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
838 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
839 CORBA::Double Rayon, CORBA::Double Haut)
841 MESSAGE ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
842 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
843 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
845 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
847 //=============================================================================
848 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
849 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
850 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
851 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
853 MESSAGE ("CreateZonePipe : ZoneName = " << ZoneName ) ;
854 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
855 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
857 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
859 //=============================================================================
860 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
861 CORBA::Double Umini, CORBA::Double Umaxi,
862 CORBA::Double Vmini, CORBA::Double Vmaxi,
865 MESSAGE ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
866 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
867 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
868 // MESSAGE ("Orient = " << Orient ) ;
870 double Xmini, Xmaxi ;
871 double Ymini, Ymaxi ;
872 double Zmini, Zmaxi ;
880 else if ( Orient == 2 )
887 else if ( Orient == 3 )
894 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
896 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
897 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
899 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
901 //=============================================================================
902 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
903 CORBA::Double Ucentre, CORBA::Double Vcentre,
907 MESSAGE ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
912 { Xcentre = Ucentre ;
915 else if ( Orient == 2 )
918 Zcentre = Vcentre ; }
919 else if ( Orient == 3 )
920 { Xcentre = Vcentre ;
922 Zcentre = Ucentre ; }
923 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
925 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
926 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
928 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
930 //=============================================================================
931 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
932 CORBA::Double Ucentre, CORBA::Double Vcentre,
933 CORBA::Double Rayon, CORBA::Double Rayonint,
936 MESSAGE ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
941 { Xcentre = Ucentre ;
944 else if ( Orient == 2 )
947 Zcentre = Vcentre ; }
948 else if ( Orient == 3 )
949 { Xcentre = Vcentre ;
951 Zcentre = Ucentre ; }
952 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
954 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
955 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
957 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
963 //=============================================================================
964 CORBA::Long HOMARD_Gen_i::Compute(const char* nomIteration, CORBA::Long etatMenage)
966 MESSAGE ( "Compute : calcul de " << nomIteration );
969 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIteration];
970 ASSERT(!CORBA::is_nil(myIteration));
972 // on ne calcule pas l iteration 0
973 int NumeIter = myIteration->GetNumber();
976 SALOME::ExceptionStruct es;
977 es.type = SALOME::BAD_PARAM;
978 es.text = "This iteration is the first of the case and cannot be computed.";
979 throw SALOME::SALOME_Exception(es);
983 // on verifie qu il y a une hypothese (erreur improbable);
984 const char* nomHypo = myIteration->GetHypoName();
985 if (std::string(nomHypo) == std::string(""))
987 SALOME::ExceptionStruct es;
988 es.type = SALOME::BAD_PARAM;
989 es.text= "This iteration does not have any associated hypothesis.";
990 throw SALOME::SALOME_Exception(es);
993 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
994 ASSERT(!CORBA::is_nil(myHypo));
997 // A.4. L'iteration parent
998 const char* nomIterationParent = myIteration->GetIterParentName();
999 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
1000 ASSERT(!CORBA::is_nil(myIterationParent));
1001 if ( ! myIterationParent->GetEtat() )
1004 SALOME::ExceptionStruct es;
1005 es.type = SALOME::BAD_PARAM;
1006 std::string text = "The iteration cannot be computed because the previous iteration " + std::string(nomIterationParent) + " is not valid.";
1007 es.text = CORBA::string_dup(text.c_str());
1008 throw SALOME::SALOME_Exception(es);
1011 int codret = Compute(nomIterationParent, etatMenage);
1014 // GERALD -- QMESSAGE BOX
1015 ASSERT("Pb au calcul de l'iteration precedente" == 0);
1019 const char* nomCas = myIteration->GetCaseName();
1020 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1021 ASSERT(!CORBA::is_nil(myCase));
1024 std::stringstream saux0 ;
1025 saux0 << NumeIter - 1 ;
1026 std::string siter = saux0.str() ;
1027 if (NumeIter < 11) { siter = "0" + siter ; }
1029 std::stringstream saux1 ;
1031 std::string siterp1 = saux1.str() ;
1032 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
1034 // B. Les repertoires
1035 // B.1. Le repertoire du cas
1036 const char* nomDir = myCase->GetDirName();
1037 MESSAGE ( ". nomDir = " << nomDir );
1039 // B.2. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
1040 // B.2.1. Le nom du sous-repertoire
1041 const char* nomDirIt = myIteration->GetDirName();
1043 // B.2.2. Le nom complet du sous-repertoire
1044 std::stringstream DirCompute ;
1045 DirCompute << nomDir << "/" << nomDirIt;
1046 MESSAGE (". DirCompute = " << DirCompute.str() );
1048 // B.2.3. Si le sous-repertoire n'existe pas, on le cree
1049 // Si le sous-repertoire existe :
1050 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
1051 // etatMenage = 1 : on fait le menage du repertoire
1052 if (chdir(DirCompute.str().c_str()) != 0)
1054 // Creation du repertoire car il n'existe pas :
1055 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1057 // GERALD -- QMESSAGE BOX
1058 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
1059 ASSERT("Pb a la creation du repertoire" == 0);
1064 // Le repertoire existe et on fait le menage de son contenu :
1065 if (etatMenage != 0)
1067 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
1068 std::string commande= "rm -rf " + DirCompute.str()+"/*" ;
1069 int codret = system(commande.c_str());
1072 // GERALD -- QMESSAGE BOX
1073 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
1074 ASSERT("Pb au menage du repertoire de calcul" == 0);
1079 // Le repertoire existe et s'il n'est pas vide, on sort en erreur :
1081 struct dirent *dirp;
1082 dp = opendir(DirCompute.str().c_str());
1084 while ((dirp = readdir(dp)) != NULL && result )
1086 std::string file_name(dirp->d_name);
1087 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
1090 if ( result == false)
1092 SALOME::ExceptionStruct es;
1093 es.type = SALOME::BAD_PARAM;
1094 std::string text = "Directory : " + DirCompute.str() + "is not empty";
1095 es.text = CORBA::string_dup(text.c_str());
1096 throw SALOME::SALOME_Exception(es);
1102 // B.3. Le sous-repertoire de l'iteration precedente
1103 const char* nomDirItPa ;
1104 std::stringstream DirComputePa ;
1107 nomDirItPa = nomDirIt;
1108 DirComputePa << DirCompute.str();
1112 nomDirItPa = myIterationParent->GetDirName();
1113 DirComputePa << nomDir << "/" << nomDirItPa;
1115 MESSAGE( ". nomDirItPa = " << nomDirItPa);
1116 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
1118 // B.4. Le fichier des messages
1119 chdir(DirCompute.str().c_str()) ;
1120 std::string MessFile = DirCompute.str() + "/Liste." + siter + ".vers." + siterp1 ;
1121 MESSAGE (". MessFile = " << MessFile);
1122 myIteration->SetMessFile(MessFile.c_str());
1124 // C. On passe dans le repertoire de l'iteration a calculer
1125 chdir(DirCompute.str().c_str()) ;
1127 // D. Les donnees du calcul HOMARD
1128 // D.1. Le type de conformite
1129 int ConfType = myCase->GetConfType();
1130 MESSAGE ( ". ConfType = " << ConfType );
1132 // D.2. Le maillage n
1133 const char* NomMeshParent = myIterationParent->GetMeshName();
1134 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
1135 const char* MeshFileParent = myIterationParent->GetMeshFile();
1136 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
1138 // D.3. Le maillage n+1
1139 const char* NomMesh = myIteration->GetMeshName();
1140 MESSAGE ( ". NomMesh = " << NomMesh );
1141 const char* MeshFile = myIteration->GetMeshFile();
1142 MESSAGE ( ". MeshFile = " << MeshFile );
1143 FILE *file = fopen(MeshFile,"r");
1147 if (etatMenage == 0)
1149 SALOME::ExceptionStruct es;
1150 es.type = SALOME::BAD_PARAM;
1151 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
1152 es.text = CORBA::string_dup(text.c_str());
1153 throw SALOME::SALOME_Exception(es);
1158 std::string commande = "rm -f " + std::string(MeshFile);
1159 codret = system(commande.c_str());
1162 SALOME::ExceptionStruct es;
1163 es.type = SALOME::BAD_PARAM;
1164 std::string text = "PB with meshfile destruction ";
1165 es.text = CORBA::string_dup(text.c_str());
1166 throw SALOME::SALOME_Exception(es);
1177 // D.4. Les types de raffinement et de deraffinement
1178 // Les appels corba sont lourds, il vaut mieux les grouper
1179 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
1180 ASSERT(ListTypes->length() == 3);
1181 int TypeAdap = (*ListTypes)[0];
1182 int TypeRaff = (*ListTypes)[1];
1183 int TypeDera = (*ListTypes)[2];
1185 // D.6. L'option d'interpolation des champs
1186 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
1188 // E. Texte du fichier de configuration
1189 // E.1. Incontournables du texte
1190 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
1191 myDriver->TexteInit(DirCompute.str(), DirComputePa.str(),MessFile);
1192 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
1193 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
1194 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
1196 // E.2. Ajout des informations liees aux zones eventuelles
1199 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
1200 int numberOfZonesx2 = ListZone->length();
1203 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
1205 std::string ZoneName = std::string((*ListZone)[iaux]);
1206 MESSAGE ( "... ZoneName = " << ZoneName);
1207 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1208 ASSERT(!CORBA::is_nil(myZone));
1210 int ZoneType = myZone->GetType();
1211 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
1212 int TypeUse = atoi( TypeUsestr.c_str() );
1213 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
1214 NumZone = iaux/2 + 1 ;
1215 HOMARD::double_array* zone = myZone->GetCoords();
1216 if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
1218 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.);
1220 else if ( ZoneType == 4 ) // Cas d une sphere
1222 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.);
1224 else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
1226 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.);
1228 else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
1230 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]);
1232 else { ASSERT("ZoneType est incorrect." == 0) ; }
1236 // E.3. Ajout des informations liees aux champs eventuels
1239 // Le fichier du champ
1240 char* FieldFile = myIteration->GetFieldFile();
1241 MESSAGE ( ". FieldFile = " << FieldFile );
1242 if (strlen(FieldFile) == 0)
1244 // GERALD -- QMESSAGE BOX
1245 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1246 ASSERT("The file for the field is not given." == 0);
1248 // Les caracteristiques d'instants
1249 int TimeStep = myIteration->GetTimeStep();
1250 MESSAGE( ". TimeStep = " << TimeStep );
1251 int Rank = myIteration->GetRank();
1252 MESSAGE( ". Rank = " << Rank );
1253 // Les informations sur les champ
1254 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
1256 const char* FieldName = aInfosHypo->FieldName;
1258 int TypeThR = aInfosHypo->TypeThR;
1259 double ThreshR = aInfosHypo->ThreshR;
1260 int TypeThC = aInfosHypo->TypeThC;
1261 double ThreshC = aInfosHypo->ThreshC;
1262 // Saut entre mailles ou non ?
1263 int UsField = aInfosHypo->UsField;
1264 MESSAGE( ". UsField = " << UsField );
1265 // L'usage des composantes
1266 int UsCmpI = aInfosHypo->UsCmpI;
1267 MESSAGE( ". UsCmpI = " << UsCmpI );
1269 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
1272 HOMARD::listeComposantsHypo* mescompo = myHypo->GetListComp();
1273 int numberOfCompos = mescompo->length();
1274 MESSAGE( ". numberOfCompos = " << numberOfCompos );
1275 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
1277 std::string nomCompo = std::string((*mescompo)[NumeComp]);
1278 MESSAGE( "... nomCompo = " << nomCompo );
1279 myDriver->TexteCompo(NumeComp, nomCompo);
1282 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
1283 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
1284 int numberOfGroups = listeGroupes->length();
1285 MESSAGE( ". numberOfGroups = " << numberOfGroups );
1286 if (numberOfGroups > 0)
1289 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
1291 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
1292 MESSAGE( "... GroupName = " << GroupName );
1293 myDriver->TexteGroup(GroupName);
1297 // E.5. Ajout des informations liees a l'eventuel suivi de frontiere
1298 // On ecrit d'abord la definition des frontieres, puis les liens avec les groupes
1299 std::list<std::string> ListeBoundaryTraitees ;
1300 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
1301 int numberOfitems = ListBoundaryGroupType->length();
1302 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
1303 int BoundaryOption = 1 ;
1304 int NumBoundaryAnalytical = 0 ;
1305 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1307 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1308 MESSAGE ( "... BoundaryName = " << BoundaryName);
1310 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
1311 while (it != ListeBoundaryTraitees.end())
1313 MESSAGE ( "... BoundaryNameTraitee = " << *it);
1314 if ( BoundaryName == *it ) { A_faire = 0 ; }
1319 // Caracteristiques de la frontiere
1320 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1321 ASSERT(!CORBA::is_nil(myBoundary));
1322 int BoundaryType = myBoundary->GetType();
1323 MESSAGE ( "... BoundaryType = " << BoundaryType );
1324 // Ecriture selon le type
1325 if (BoundaryType == 0) // Cas d une frontiere discrete
1327 const char* MeshName = myBoundary->GetMeshName() ;
1328 const char* MeshFile = myBoundary->GetMeshFile() ;
1329 myDriver->TexteBoundaryDi( MeshName, MeshFile);
1330 BoundaryOption = BoundaryOption*2 ;
1332 else // Cas d une frontiere analytique
1334 NumBoundaryAnalytical++ ;
1335 HOMARD::double_array* coor = myBoundary->GetCoords();
1336 if (BoundaryType == 1) // Cas d un cylindre
1338 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6]);
1339 BoundaryOption = BoundaryOption*3 ;
1341 else if (BoundaryType == 2) // Cas d une sphere
1343 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0.);
1344 BoundaryOption = BoundaryOption*3 ;
1347 // Memorisation du traitement
1348 ListeBoundaryTraitees.push_back( BoundaryName );
1351 NumBoundaryAnalytical = 0 ;
1352 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1354 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1355 MESSAGE ( "... BoundaryName = " << BoundaryName);
1356 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1357 ASSERT(!CORBA::is_nil(myBoundary));
1358 int BoundaryType = myBoundary->GetType();
1359 MESSAGE ( "... BoundaryType = " << BoundaryType );
1360 // Recuperation du nom du groupe
1361 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
1362 MESSAGE ( "... GroupName = " << GroupName);
1363 if (BoundaryType == 0) // Cas d une frontiere discrete
1365 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
1367 else // Cas d une frontiere analytique
1369 NumBoundaryAnalytical++ ;
1370 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
1373 myDriver->TexteBoundaryOption(BoundaryOption);
1375 // E.6. Ajout des informations liees a l'eventuelle interpolation des champs
1376 MESSAGE( "... TypeFieldInterp = " << TypeFieldInterp );
1377 if (TypeFieldInterp != 0)
1379 // Le fichier des champs
1380 char* FieldFile = myIteration->GetFieldFile();
1381 MESSAGE ( ". FieldFile = " << FieldFile );
1382 if (strlen(FieldFile) == 0)
1384 // GERALD -- QMESSAGE BOX
1385 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1386 ASSERT("The file for the field is not given." == 0);
1388 // Les caracteristiques d'instants
1389 int TimeStep = myIteration->GetTimeStep();
1390 MESSAGE( ". TimeStep = " << TimeStep );
1391 int Rank = myIteration->GetRank();
1392 MESSAGE( ". Rank = " << Rank );
1394 myDriver->TexteFieldInterp(TypeFieldInterp, FieldFile, MeshFile, TimeStep, Rank);
1396 if (TypeFieldInterp == 2)
1398 HOMARD::listFieldInterpHypo* meschamps = myHypo->GetListFieldInterp();
1399 int numberOfFields = meschamps->length();
1400 MESSAGE( ". numberOfFields = " << numberOfFields );
1401 for (int NumeChamp = 0; NumeChamp< numberOfFields; NumeChamp++)
1403 std::string nomChamp = std::string((*meschamps)[NumeChamp]);
1404 MESSAGE( "... nomChamp = " << nomChamp );
1405 myDriver->TexteFieldInterpName(NumeChamp, nomChamp);
1409 // E.7. Ajout des options avancees
1410 int Pyram = myCase->GetPyram();
1411 MESSAGE ( ". Pyram = " << Pyram );
1412 int NivMax = myHypo->GetNivMax();
1413 MESSAGE ( ". NivMax = " << NivMax );
1414 double DiamMin = myHypo->GetDiamMin() ;
1415 MESSAGE ( ". DiamMin = " << DiamMin );
1416 int AdapInit = myHypo->GetAdapInit();
1417 MESSAGE ( ". AdapInit = " << AdapInit );
1418 int LevelOutput = myHypo->GetLevelOutput();
1419 MESSAGE ( ". LevelOutput = " << LevelOutput );
1420 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
1422 // F. Ecriture du texte dans le fichier
1425 myDriver->CreeFichier();
1430 int codretexec = 12 ;
1433 codretexec = myDriver->ExecuteHomard();
1435 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
1436 if (codretexec == 0)
1438 SetEtatIter(nomIteration,true);
1442 // GERALD -- QMESSAGE BOX
1443 SetEtatIter(nomIteration,false);
1447 // H. Gestion des resultats
1450 // H.1. Le fichier des messages, dans tous les cas
1451 std::stringstream saux1 ;
1452 saux1 << "Mess " << NumeIter ;
1453 PublishFileUnderIteration(nomIteration, MessFile.c_str(), saux1.str().c_str());
1455 // H.2. Si tout s'est bien passe :
1456 if (codretexec == 0)
1458 // H.2.1. Le fichier de bilan
1459 std::stringstream saux2 ;
1460 saux2 << "Summary " << NumeIter ;
1461 std::string SummaryFile = DirCompute.str() + "/apad." + siterp1 + ".bilan" ;
1462 PublishFileUnderIteration(nomIteration, SummaryFile.c_str(), saux2.str().c_str());
1463 // H.2.2. Le fichier de maillage obtenu
1464 std::stringstream saux0 ;
1465 saux0 <<"Iteration " << NumeIter ;
1466 PublishFileUnderIteration(nomIteration, MeshFile, saux0.str().c_str());
1467 PublishResultInSmesh(MeshFile, 1);
1469 // H.3 Message d'erreur en cas de probleme
1472 SALOME::ExceptionStruct es;
1473 es.type = SALOME::BAD_PARAM;
1474 std::string text = "Error during the adaptation.\n" ;
1477 ifstream fichier(MessFile.c_str(), ios::in);
1479 while(getline(fichier, ligne) and (ligne != "===== HOMARD ===== STOP ====="));
1480 while (getline(fichier, ligne)) { text += ligne+ "\n";};
1483 text += "no log file ....";
1485 es.text = CORBA::string_dup(text.c_str());
1486 throw SALOME::SALOME_Exception(es);
1499 //===========================================================================
1500 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
1501 SALOMEDS::SObject_ptr theSObject,
1502 CORBA::Object_ptr theObject,
1503 const char* theName)
1505 MESSAGE("PublishInStudy pour " << theName);
1506 SALOMEDS::SObject_var aResultSO;
1507 if (CORBA::is_nil(theStudy))
1509 SALOME::ExceptionStruct es;
1510 es.type = SALOME::BAD_PARAM;
1511 es.text = "Invalid Study Context ";
1512 throw SALOME::SALOME_Exception(es);
1516 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
1517 // Rq : Iteration est publiee ailleurs
1518 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
1519 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
1520 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
1521 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
1523 addInStudy(theStudy);
1525 // Controle de la non publication d'un objet de meme nom
1526 if ((!aHypo->_is_nil()) or (!aZone->_is_nil()) or (!aBoundary->_is_nil()))
1528 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
1529 if (listSO->length() >= 1)
1531 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
1532 std::cerr <<"This name "<<theName<<" is already used "<<listSO->length()<<" time(s)" << std::endl;
1533 aResultSO = listSO[0];
1534 return aResultSO._retn();
1538 // Caracteristiques de l'etude
1539 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1540 aStudyBuilder->NewCommand();
1541 if(!aCase->_is_nil())
1542 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
1543 else if(!aHypo->_is_nil())
1544 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
1545 else if(!aZone->_is_nil())
1546 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
1547 else if(!aBoundary->_is_nil())
1548 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
1550 aStudyBuilder->CommitCommand();
1551 return aResultSO._retn();
1553 //=============================================================================
1554 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
1555 SALOMEDS::StudyBuilder_var aStudyBuilder,
1556 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
1558 MESSAGE("PublishCaseInStudy pour "<<theName);
1559 SALOMEDS::SObject_var aResultSO;
1560 SALOMEDS::GenericAttribute_var anAttr;
1562 if (CORBA::is_nil(theObject)) {
1563 MESSAGE("HOMARD_Gen_i.cxx::theObject->_is_nil()");
1564 return aResultSO._retn();
1566 if (theStudy->_is_nil()) {
1567 MESSAGE("HOMARD_Gen_i.cxx::theStudy->_is_nil()");
1568 return aResultSO._retn();
1571 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1572 if (theFatherHomard->_is_nil())
1574 MESSAGE("theFatherHomard->_is_nil()");
1575 return aResultSO._retn();
1578 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
1579 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
1580 _orb->object_to_string(theObject) ) ;
1581 return aResultSO._retn();
1584 //=============================================================================
1585 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
1586 SALOMEDS::StudyBuilder_var aStudyBuilder,
1587 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
1589 MESSAGE("PublishZoneStudy pour "<<theName);
1590 SALOMEDS::SObject_var aResultSO;
1591 SALOMEDS::GenericAttribute_var anAttr;
1593 if (CORBA::is_nil(theObject))
1595 MESSAGE("HOMARD_Gen_i.cxx::theObject->_is_nil()");
1596 return aResultSO._retn();
1598 if (theStudy->_is_nil())
1600 MESSAGE("HOMARD_Gen_i.cxx::theStudy->_is_nil()");
1601 return aResultSO._retn();
1603 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1604 if (theFatherHomard->_is_nil())
1606 MESSAGE("theFatherHomard->_is_nil()");
1607 return aResultSO._retn();
1610 // Caracteristique de la zone
1611 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
1612 CORBA::Long ZoneType = myZone->GetType();
1614 // On ajoute la categorie des zones dans l etude si necessaire
1615 SALOMEDS::SObject_var aSOZone;
1616 if (!theFatherHomard->FindSubObject(100, aSOZone))
1618 MESSAGE("Ajout de la categorie des zones");
1619 aSOZone = aStudyBuilder->NewObjectToTag(theFatherHomard, 100);
1620 PublishInStudyAttr(aStudyBuilder, aSOZone, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
1622 else { MESSAGE("La categorie des zones existe deja."); }
1624 aResultSO = aStudyBuilder->NewObject(aSOZone);
1633 { icone = "boxdxy_2.png" ;
1637 { icone = "boxdxyz_2.png" ;
1645 { icone = "disk_2.png" ;
1649 { icone = "spherepoint_2.png" ;
1653 { icone = "cylinderpointvector_2.png" ;
1661 { icone = "diskwithhole_2.png" ;
1665 { icone = "pipe_2.png" ;
1669 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone, _orb->object_to_string(theObject) ) ;
1671 return aResultSO._retn();
1673 //=============================================================================
1674 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
1675 SALOMEDS::StudyBuilder_var aStudyBuilder,
1676 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
1678 MESSAGE("PublishBoundaryStudy pour "<<theName);
1679 SALOMEDS::SObject_var aResultSO;
1680 SALOMEDS::GenericAttribute_var anAttr;
1682 // Caracteristique de la Boundary
1683 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
1685 // On recupere le module pere dans l etude
1686 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1687 if (theFatherHomard->_is_nil())
1689 MESSAGE("theFatherHomard->_is_nil()");
1690 return aResultSO._retn();
1693 // On ajoute la categorie des boundarys dans l etude si necessaire
1694 SALOMEDS::SObject_var aSOBoundary;
1695 if (!theFatherHomard->FindSubObject(101, aSOBoundary))
1697 MESSAGE("Ajout de la categorie des boundarys");
1698 aSOBoundary = aStudyBuilder->NewObjectToTag(theFatherHomard, 101);
1699 PublishInStudyAttr(aStudyBuilder, aSOBoundary, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
1701 else { MESSAGE("La categorie des boundarys existe deja."); }
1703 aResultSO = aStudyBuilder->NewObject(aSOBoundary);
1704 CORBA::Long BoundaryType = myBoundary->GetType();
1705 // MESSAGE("BoundaryType : "<<BoundaryType);
1708 switch (BoundaryType)
1711 { value = "BoundaryDiHomard" ;
1712 icone = "mesh_tree_mesh.png" ;
1716 { value = "BoundaryAnHomard" ;
1717 icone = "cylinderpointvector_2.png" ;
1721 { value = "BoundaryAnHomard" ;
1722 icone = "spherepoint_2.png" ;
1726 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value, icone, _orb->object_to_string(theObject));
1727 return aResultSO._retn();
1730 //=============================================================================
1731 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
1732 SALOMEDS::StudyBuilder_var aStudyBuilder,
1733 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
1735 MESSAGE("PublishHypotheseInStudy pour "<<theName);
1736 SALOMEDS::SObject_var aResultSO;
1737 SALOMEDS::GenericAttribute_var anAttr;
1739 // On recupere le module pere dans l etude
1740 // On ajoute la categorie des hypotheses dans l etude si necessaire
1741 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1742 if (theFatherHomard->_is_nil())
1744 MESSAGE("theFatherHomard->_is_nil()");
1745 return aResultSO._retn();
1747 SALOMEDS::SObject_var aSOHypothese;
1748 if (!theFatherHomard->FindSubObject(0, aSOHypothese))
1750 MESSAGE("Ajout de la categorie des hypotheses");
1751 aSOHypothese = aStudyBuilder->NewObjectToTag(theFatherHomard, 0);
1752 PublishInStudyAttr(aStudyBuilder, aSOHypothese, "Hypothesis", "HypoList","hypotheses.png", NULL);
1754 else { MESSAGE("La categorie des hypotheses existe deja."); }
1756 // Creation du resultat dans l'etude
1757 aResultSO = aStudyBuilder->NewObject(aSOHypothese);
1758 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
1760 return aResultSO._retn();
1762 //===========================================================================
1763 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
1764 SALOMEDS::SObject_var aResultSO,
1765 const char* name, const char* value, const char* icone, const char* ior)
1767 SALOMEDS::GenericAttribute_var anAttr ;
1771 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
1772 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
1773 aNameAttrib->SetValue(name);
1776 // Ajout du commentaire
1777 if ( value != NULL )
1779 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
1780 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
1781 aCommentAttrib->SetValue(value);
1785 if ( icone != NULL )
1787 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO,"AttributePixMap");
1788 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
1789 aPixmap->SetPixMap(icone);
1795 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
1796 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1797 anIOR->SetValue(ior);
1801 //=============================================================================
1802 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
1804 MESSAGE("GetAllCasesName");
1807 HOMARD::listeCases_var ret = new HOMARD::listeCases;
1808 ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
1809 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
1811 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
1812 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
1814 ret[i++] = CORBA::string_dup((*it).first.c_str());
1820 //=============================================================================
1821 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
1823 MESSAGE("GetAllHypothesesName");
1826 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
1827 ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
1828 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
1830 for (it = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
1831 it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
1833 ret[i++] = CORBA::string_dup((*it).first.c_str());
1839 //=============================================================================
1840 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
1842 MESSAGE("GetAllZonesName");
1845 HOMARD::listeZones_var ret = new HOMARD::listeZones;
1846 ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
1847 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
1849 for (it = myContextMap[GetCurrentStudyID()]._mesZones.begin();
1850 it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
1852 ret[i++] = CORBA::string_dup((*it).first.c_str());
1858 //=============================================================================
1859 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
1861 MESSAGE("GetAllIterationsName");
1864 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
1865 ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
1866 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
1868 for (it = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
1869 it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
1871 ret[i++] = CORBA::string_dup((*it).first.c_str());
1876 //=============================================================================
1877 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
1879 MESSAGE("GetAllBoundarysName");
1882 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
1883 ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
1884 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
1886 for (it = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
1887 it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
1889 ret[i++] = CORBA::string_dup((*it).first.c_str());
1895 //=============================================================================
1896 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long IconeType)
1898 MESSAGE( "PublishResultInSmesh " << NomFich);
1899 if (CORBA::is_nil(myCurrentStudy))
1901 SALOME::ExceptionStruct es;
1902 es.type = SALOME::BAD_PARAM;
1903 es.text = "Invalid Study Context ";
1904 throw SALOME::SALOME_Exception(es);
1908 // Le module SMESH est-il actif ?
1909 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
1911 if (!CORBA::is_nil(aSmeshSO))
1913 // On verifie que le fichier n est pas deja publie
1914 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
1915 for (; aIter->More(); aIter->Next())
1917 SALOMEDS::SObject_var aSO = aIter->Value();
1918 SALOMEDS::GenericAttribute_var aGAttr;
1919 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
1921 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
1922 CORBA::String_var value=anAttr->Value();
1923 if (strcmp((const char*)value,NomFich) == 0)
1925 // GERALD -- QMESSAGE BOX
1926 std::cerr << "fichier : "<< NomFich << " deja publie "<< std::endl;
1934 // On enregistre le fichier
1935 MESSAGE( "Enregistrement du fichier");
1936 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
1937 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
1938 ASSERT(!CORBA::is_nil(aSmeshEngine));
1939 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
1940 SMESH::DriverMED_ReadStatus theStatus;
1941 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
1943 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
1944 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
1945 for (int i = 0; i < mesMaillages->length(); i++)
1947 MESSAGE( ". Mise a jour des attributs du maillage");
1948 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
1949 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
1950 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1951 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
1952 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
1953 anAttr->SetValue(NomFich);
1954 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
1955 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
1956 // IconeType = 0 : fichier issu d'une importation
1957 // IconeType = 1 : fichier issu d'une execution HOMARD
1959 if ( IconeType == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
1960 else { icone = "mesh_tree_mesh.png" ; }
1961 anAttr2->SetPixMap( icone );
1965 //=============================================================================
1966 void HOMARD_Gen_i::DeleteResultInSmesh(const char* NomFich, const char* MeshName)
1968 MESSAGE (" DeleteResultInSmesh pour "<< NomFich << "et le maillage "<< MeshName);
1969 if (CORBA::is_nil(myCurrentStudy))
1971 SALOME::ExceptionStruct es;
1972 es.type = SALOME::BAD_PARAM;
1973 es.text = "Invalid Study Context ";
1974 throw SALOME::SALOME_Exception(es);
1978 // Le module SMESH est-il actif ?
1979 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
1981 if (CORBA::is_nil(aSmeshSO))
1985 // On verifie que le fichier est deja publie
1986 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
1987 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
1988 for (; aIter->More(); aIter->Next())
1990 SALOMEDS::SObject_var aSO = aIter->Value();
1991 SALOMEDS::GenericAttribute_var aGAttr;
1992 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
1994 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
1995 CORBA::String_var value=anAttr->Value();
1996 if (strcmp((const char*)value,NomFich) == 0)
1998 if (aSO->FindAttribute(aGAttr,"AttributeName"))
2000 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
2001 CORBA::String_var value2=anAttr2->Value();
2002 if (strcmp((const char*)value2,MeshName) == 0)
2004 myBuilder->RemoveObjectWithChildren( aSO ) ;
2012 //=============================================================================
2013 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
2015 if (CORBA::is_nil(myCurrentStudy))
2017 SALOME::ExceptionStruct es;
2018 es.type = SALOME::BAD_PARAM;
2019 es.text = "Invalid Study Context ";
2020 throw SALOME::SALOME_Exception(es);
2024 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
2025 if (CORBA::is_nil(myIteration))
2027 SALOME::ExceptionStruct es;
2028 es.type = SALOME::BAD_PARAM;
2029 es.text = "Invalid Iteration ";
2030 throw SALOME::SALOME_Exception(es);
2033 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
2034 if (CORBA::is_nil(myIteration))
2036 SALOME::ExceptionStruct es;
2037 es.type = SALOME::BAD_PARAM;
2038 es.text = "Invalid Iteration Study Object";
2039 throw SALOME::SALOME_Exception(es);
2043 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2045 aStudyBuilder->NewCommand();
2047 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
2048 // Pour les fichiers med, on affiche une icone de maillage
2049 // Pour les fichiers qui sont texte, on affiche une icone de fichier texte 'texte'
2050 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
2052 const char* ior = " " ;
2053 if ( Commentaire[0] == 'I' )
2054 { icone = "med.png" ; }
2056 { icone = "texte_2.png" ; }
2057 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone, ior ) ;
2059 aStudyBuilder->CommitCommand();
2062 //=====================================================================================
2063 void HOMARD_Gen_i::IsValidStudy( )
2064 //=====================================================================================
2066 MESSAGE( "IsValidStudy" );
2067 if (CORBA::is_nil(myCurrentStudy))
2069 SALOME::ExceptionStruct es;
2070 es.type = SALOME::BAD_PARAM;
2071 es.text = "Invalid Study Context";
2072 throw SALOME::SALOME_Exception(es);
2077 //===========================================================================
2079 // Next functions are inherited from SALOMEDS::Driver interface
2081 //===========================================================================
2083 //===========================================================================
2084 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
2086 CORBA::Boolean isMultiFile)
2088 MESSAGE (" Save for theURL = "<< theURL);
2089 SALOMEDS::TMPFile_var aStreamFile;
2091 // get temporary directory name
2092 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2094 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2095 StudyContext& context = myContextMap[ aStudy->StudyId() ];
2097 // HOMARD data file name
2098 std::string aFileName = "";
2100 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2101 aFileName += "_HOMARD.dat";
2103 // initialize sequence of file names
2104 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
2105 aFileSeq->length(1);
2106 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
2108 // get full path to the data file
2109 aFileName = tmpDir + aFileName;
2113 std::ofstream f(aFileName.c_str());
2115 // clear temporary id map
2116 context._idmap.clear();
2121 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
2122 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
2123 HOMARD::HOMARD_Cas_var aCas = it_case->second;
2124 PortableServer::ServantBase_var aServant = GetServant(aCas);
2125 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2127 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
2128 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
2132 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2133 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
2134 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
2135 PortableServer::ServantBase_var aServant = GetServant(aZone);
2136 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2138 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
2139 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2142 // -> save hypotheses
2143 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2144 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
2145 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
2146 PortableServer::ServantBase_var aServant = GetServant(aHypo);
2147 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2149 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
2150 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2153 // -> save iterations
2154 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2155 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
2156 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
2157 PortableServer::ServantBase_var aServant = GetServant(aIter);
2158 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2160 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
2161 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2164 // -> save boundaries
2165 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2166 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
2167 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
2168 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2169 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2170 if (aBoundaryServant) {
2171 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
2172 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2176 MESSAGE ("close file");
2179 // put temporary files to the stream
2180 MESSAGE ("put temporary files to the stream");
2181 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
2183 // remove temporary files
2184 MESSAGE ("remove temporary files");
2185 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2187 // return data stream
2188 MESSAGE ("return data stream");
2189 return aStreamFile._retn();
2192 //===========================================================================
2193 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
2195 CORBA::Boolean isMultiFile)
2197 // No specific ASCII persistence
2198 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
2199 return aStreamFile._retn();
2202 //===========================================================================
2203 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
2204 const SALOMEDS::TMPFile& theStream,
2206 CORBA::Boolean isMultiFile)
2208 MESSAGE (" Load pour theURL = "<< theURL);
2209 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2211 // set current study
2212 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
2213 SetCurrentStudy(aStudy);
2215 // get temporary directory name
2216 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2218 // Convert the stream into sequence of files to process
2219 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
2222 // HOMARD data file name
2223 std::string aFileName = "";
2225 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2226 aFileName = tmpDir + aFileName + "_HOMARD.dat";
2228 StudyContext& context = myContextMap[ aStudy->StudyId() ];
2232 std::ifstream f(aFileName.c_str());
2235 context._mesCas.clear();
2236 context._mesHypotheses.clear();
2237 context._mesIterations.clear();
2238 context._mesZones.clear();
2239 context._mesBoundarys.clear();
2240 context._idmap.clear();
2246 std::getline(f, line);
2247 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
2248 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
2249 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
2250 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
2251 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
2252 if (line.substr(0, caseSignature.size()) == caseSignature) {
2254 MESSAGE (" Recreation du cas" );
2255 HOMARD::HOMARD_Cas_var aCase = newCase();
2256 PortableServer::ServantBase_var aServant = GetServant(aCase);
2257 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2258 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
2259 context._mesCas[aCase->GetName()] = aCase;
2260 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
2263 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
2264 MESSAGE (" Recreation de la zone" );
2266 HOMARD::HOMARD_Zone_var aZone = newZone();
2267 PortableServer::ServantBase_var aServant = GetServant(aZone);
2268 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2269 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
2270 context._mesZones[aZone->GetName()] = aZone;
2271 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2274 else if (line.substr(0, iterSignature.size()) == iterSignature) {
2275 // re-create iteration
2276 MESSAGE (" Recreation de l iteration" );
2277 HOMARD::HOMARD_Iteration_var aIter = newIteration();
2278 PortableServer::ServantBase_var aServant = GetServant(aIter);
2279 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2280 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
2281 context._mesIterations[aIter->GetName()] = aIter;
2282 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2285 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
2286 // re-create hypothesis
2287 MESSAGE (" Recreation de l hypothese" );
2288 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
2289 PortableServer::ServantBase_var aServant = GetServant(aHypo);
2290 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2291 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
2292 context._mesHypotheses[aHypo->GetName()] = aHypo;
2293 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2296 else if (line.substr(0, bounSignature.size()) == bounSignature) {
2297 // re-create boundary
2298 MESSAGE (" Recreation de la frontiere" );
2299 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
2300 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2301 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2302 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
2303 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
2304 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2313 // Remove temporary files created from the stream
2315 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2320 //===========================================================================
2321 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
2322 const SALOMEDS::TMPFile& theStream,
2324 CORBA::Boolean isMultiFile)
2326 // No specific ASCII persistence
2327 return Load(theComponent, theStream, theURL, isMultiFile);
2330 //===========================================================================
2331 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
2333 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
2334 // clearing study context should be done here:
2335 // - destroy all servants and related CORBA objects
2337 // - remove context from myContextMap
2338 myContextMap.erase(theComponent->GetStudy()->StudyId());
2339 // - nullify myCurrentStudy
2340 myCurrentStudy = SALOMEDS::Study::_nil();
2344 //===========================================================================
2345 char* HOMARD_Gen_i::ComponentDataType()
2347 return CORBA::string_dup("HOMARD");
2350 //===========================================================================
2351 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
2352 const char* IORString,
2353 CORBA::Boolean isMultiFile,
2354 CORBA::Boolean isASCII)
2356 CORBA::String_var aString("");
2357 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
2358 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2359 CORBA::Object_var anObj = _orb->string_to_object(IORString);
2360 if (!CORBA::is_nil(anObj)) {
2361 PortableServer::ServantBase_var aServant = GetServant(anObj);
2362 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
2364 std::map<int, PortableServer::ServantBase*>::const_iterator it;
2365 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
2366 if (it->second == aStorable) {
2367 std::stringstream os;
2369 aString = CORBA::string_dup(os.str().c_str());
2375 return aString._retn();
2378 //===========================================================================
2379 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
2380 const char* aLocalPersistentID,
2381 CORBA::Boolean isMultiFile,
2382 CORBA::Boolean isASCII)
2384 CORBA::String_var aString("");
2385 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
2386 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2387 int id = atoi(aLocalPersistentID);
2388 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
2389 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
2390 if (!CORBA::is_nil(object)) {
2391 aString = _orb->object_to_string(object);
2395 return aString._retn();
2398 //===========================================================================
2399 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
2401 if(CORBA::is_nil(myCurrentStudy))
2404 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
2405 if(!aCas->_is_nil())
2408 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
2409 if(!aHypo->_is_nil())
2412 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
2413 if(!aZone->_is_nil())
2416 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
2417 if(!aBoundary->_is_nil())
2420 /* Iteration is not published directly
2421 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
2422 if(!aIter->_is_nil())
2428 //===========================================================================
2429 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
2431 // No Copy/Paste support
2435 //===========================================================================
2436 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
2437 CORBA::Long& theObjectID)
2439 // No Copy/Paste support
2440 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
2441 return aStreamFile._retn();
2444 //===========================================================================
2445 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
2446 CORBA::Long theObjectID)
2448 // No Copy/Paste support
2452 //===========================================================================
2453 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
2454 CORBA::Long theObjectID,
2455 SALOMEDS::SObject_ptr theSObject)
2457 // No Copy/Paste support
2458 SALOMEDS::SObject_var aResultSO;
2459 return aResultSO._retn();
2462 //===========================================================================
2463 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
2465 PortableServer::Servant aServant = 0;
2466 if (!CORBA::is_nil(theObject)) {
2468 aServant = _poa->reference_to_servant(theObject);
2476 //===========================================================================
2477 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
2479 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2480 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
2481 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
2482 return aCase._retn();
2485 //===========================================================================
2486 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
2488 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2489 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
2490 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
2491 return aHypo._retn();
2494 //===========================================================================
2495 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
2497 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2498 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
2499 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
2500 return aIter._retn();
2503 //===========================================================================
2504 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
2506 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2507 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
2508 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
2509 return aBoundary._retn();
2511 //===========================================================================
2512 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
2514 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2515 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
2516 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
2517 return aZone._retn();
2519 //==========================================================================
2520 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
2521 CORBA::Boolean isPublished,
2522 CORBA::Boolean isMultiFile,
2523 CORBA::Boolean& isValidScript)
2525 MESSAGE ("Entree dans DumpPython");
2527 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
2528 if(CORBA::is_nil(aStudy))
2529 return new Engines::TMPFile(0);
2531 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
2532 if(CORBA::is_nil(aSO))
2533 return new Engines::TMPFile(0);
2535 std::string aScript = "\"\"\"\n";
2536 aScript += "Python script for HOMARD\n";
2537 aScript += "Copyright EDF-R&D 2010\n";
2538 aScript += "\"\"\"\n";
2539 aScript += "__revision__ = \"V1.2\"\n";
2540 aScript += "import HOMARD\n";
2542 aScript += "import salome\n";
2543 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
2545 aScript += "def RebuildData(theStudy):\n";
2546 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
2549 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
2550 MESSAGE (". Au depart \n"<<aScript);
2553 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
2555 MESSAGE (". Ecritures des frontieres");
2556 aScript += "#\n# Creation of the boundaries";
2557 aScript += "\n# ==========================";
2559 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2560 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
2561 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
2563 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
2564 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
2565 std::string dumpBoundary = dumpCorbaBoundary.in();
2566 MESSAGE (dumpBoundary<<"\n");
2567 aScript+=dumpBoundary;
2571 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
2573 MESSAGE (". Ecritures des zones");
2574 aScript += "#\n# Creation of the zones";
2575 aScript += "\n# =====================";
2577 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2578 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
2579 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
2581 HOMARD::HOMARD_Zone_var maZone = (*it_zone).second;
2582 CORBA::String_var dumpCorbaZone = maZone->GetDumpPython();
2583 std::string dumpZone = dumpCorbaZone.in();
2584 MESSAGE (dumpZone<<"\n");
2589 MESSAGE (". Ecritures des hypotheses");
2590 aScript += "#\n# Creation of the hypotheses";
2591 aScript += "\n# ==========================";
2592 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2593 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
2594 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
2596 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
2597 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
2598 std::string dumpHypo = dumpCorbaHypo.in();
2599 MESSAGE (dumpHypo<<"\n");
2604 MESSAGE (". Ecritures des cas");
2605 aScript += "#\n# Creation of the cases";
2606 aScript += "\n# =====================";
2607 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
2608 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
2609 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
2611 std::string nomCas = (*it_cas).first;
2612 std::string dumpCas = std::string("\n# Creation of the case ") ;
2613 dumpCas += nomCas + std::string("\n");
2614 dumpCas += std::string("\t") + nomCas;
2615 dumpCas += std::string(" = homard.CreateCase('") + nomCas + std::string("', '");
2617 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
2618 CORBA::String_var cIter0= myCase->GetIter0Name();
2619 std::string iter0 = cIter0.in();
2621 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
2622 CORBA::String_var cMesh0= myIteration->GetMeshFile();
2623 std::string mesh0 = cMesh0.in();
2624 CORBA::String_var cMeshName0= myIteration->GetMeshName();
2625 std::string meshName0 = cMeshName0.in();
2626 dumpCas += meshName0 + std::string("', '")+ mesh0 + std::string("')\n");
2627 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
2628 std::string dumpCas2= dumpCorbaCase.in();
2630 MESSAGE (dumpCas<<dumpCas2<<"\n");
2631 aScript+=dumpCas + dumpCas2;
2635 MESSAGE (". Ecritures des iterations");
2636 aScript += "#\n# Creation of the iterations" ;
2637 aScript += "\n# ==========================";
2638 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2639 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
2640 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
2642 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
2643 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
2644 std::string dumpIter = dumpCorbaIter.in();
2645 MESSAGE (dumpIter<<"\n");
2649 MESSAGE (". Ecritures finales");
2651 aScript += "\n\tpass";
2654 if( !isMultiFile ) // remove unnecessary tabulation
2655 aScript = RemoveTabulation( aScript );
2657 /* MESSAGE ("A ecrire \n"<<aScript);*/
2658 const size_t aLen = strlen(aScript.c_str());
2659 char* aBuffer = new char[aLen+1];
2660 strcpy(aBuffer, aScript.c_str());
2662 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
2663 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
2665 MESSAGE ("Sortie de DumpPython");
2666 return aStreamFile._retn();
2670 // Version information
2671 char* HOMARD_Gen_i::getVersion()
2673 #if HOMARD_DEVELOPMENT
2674 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
2676 return CORBA::string_dup(HOMARD_VERSION_STR);
2680 //=============================================================================
2683 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
2684 PortableServer::POA_ptr poa,
2685 PortableServer::ObjectId* contId,
2686 const char* instanceName,
2687 const char* interfaceName)
2689 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
2690 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
2691 return myHOMARD_Gen->getId();