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::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
403 MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
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));
415 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
416 aStudyBuilder->NewCommand();
418 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
419 aStudyBuilder->Addreference(aSubSO, aZoneSO);
420 aStudyBuilder->CommitCommand();
422 myZone->AddHypo(nomHypothesis);
423 myHypo->AddZone(ZoneName, TypeUse);
424 MESSAGE ( "Fin de AssociateHypoZone");
427 //=====================================================================================
428 void HOMARD_Gen_i::DissociateHypoZone(const char* ZoneName, const char* nomHypothesis)
430 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
433 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
434 ASSERT(!CORBA::is_nil(myHypo));
435 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
436 ASSERT(!CORBA::is_nil(aHypoSO));
438 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
439 ASSERT(!CORBA::is_nil(myZone));
440 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
441 ASSERT(!CORBA::is_nil(aZoneSO));
444 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
446 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator(aHypoSO);
447 for (; it->More(); it->Next())
449 SALOMEDS::SObject_var aHypObj = it->Value();
450 SALOMEDS::SObject_var ptrObj;
451 if (aHypObj->ReferencedObject(ptrObj))
453 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
455 aStudyBuilder->NewCommand();
456 aStudyBuilder->RemoveObject(aHypObj);
457 aStudyBuilder->CommitCommand();
463 myZone->SupprHypo(nomHypothesis);
464 myHypo->SupprZone(ZoneName);
467 //=============================================================================
468 void HOMARD_Gen_i::AssociateIterIter(const char* nomIterParent, const char* nomIter)
470 MESSAGE ( "AssociateIterIter : nomIter = " << nomIter << " nomIterParent = " << nomIterParent);
473 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
474 ASSERT(!CORBA::is_nil(myIterationParent));
475 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
476 ASSERT(!CORBA::is_nil(myIteration));
478 myIterationParent->AddIteration(nomIter);
479 myIteration->SetIterParent(nomIterParent);
482 //===================================================================================
483 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
485 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
488 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
489 ASSERT(!CORBA::is_nil(myHypo));
490 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
491 ASSERT(!CORBA::is_nil(aHypoSO));
493 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
494 ASSERT(!CORBA::is_nil(myIteration));
495 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
496 ASSERT(!CORBA::is_nil(aIterSO));
498 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
500 aStudyBuilder->NewCommand();
502 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
503 aStudyBuilder->Addreference(aSubSO, aHypoSO);
505 aStudyBuilder->CommitCommand();
507 myIteration->SetHypoName(nomHypo);
508 myHypo->AddIteration(nomIter);
511 //=============================================================================
512 CORBA::Boolean HOMARD_Gen_i::VerifieDir(const char* nomDir)
514 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
515 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
516 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
518 if (std::string(nomDir) == std::string(it->second->GetDirName())) return false;
523 //=============================================================================
524 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
526 MESSAGE ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
529 if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
531 SALOME::ExceptionStruct es;
532 es.type = SALOME::BAD_PARAM;
533 es.text = "This case has already been defined";
534 throw SALOME::SALOME_Exception(es);
538 HOMARD::HOMARD_Cas_var myCase = newCase();
539 myCase->SetName(nomCas);
540 SALOMEDS::SObject_var aSO;
541 PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
542 myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
545 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile);
546 HOMARD::extrema_var aSeq = new HOMARD::extrema();
547 if (LesExtremes.size()!=10) { return false; }
549 for (int i =0; i< LesExtremes.size(); i++)
550 aSeq[i]=LesExtremes[i];
551 myCase->SetBoundingBox(aSeq);
553 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile);
554 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType;
555 aSeqGroupe->length(LesGroupes.size());
556 std::set<std::string>::const_iterator it;
558 for (it=LesGroupes.begin() ; it != LesGroupes.end(); it++)
559 aSeqGroupe[i++]=(*it).c_str();
560 myCase->SetGroups(aSeqGroupe);
562 // Recherche d'un nom pour l'iteration 0. Par defaut, on prend le nom
563 // du maillage du cas. Si ce nom existe deja, on incremente avec 0, 1, 2, etc.
565 std::string nomIter = std::string(MeshName) ;
566 while ((myContextMap[GetCurrentStudyID()]._mesIterations).find(nomIter) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()))
568 std::ostringstream nom;
569 nom << MeshName << monNum;
574 HOMARD::HOMARD_Iteration_var anIter = newIteration();
575 myContextMap[GetCurrentStudyID()]._mesIterations[nomIter] = anIter;
576 std::ostringstream DirName;
579 anIter->SetDirName(DirName.str().c_str());
580 anIter->SetName(nomIter.c_str());
581 anIter->SetMeshFile(MeshFile);
582 anIter->SetMeshName(MeshName);
583 anIter->SetNumber(0);
585 AssociateCaseIter (nomCas,nomIter.c_str(),"IterationHomard");
586 SetEtatIter(nomIter.c_str(),true);
588 PublishResultInSmesh(MeshFile, 0);
590 // Valeurs par defaut des filtrages
593 return HOMARD::HOMARD_Cas::_duplicate(myCase);
596 //=============================================================================
597 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCas(const char* nomCas)
600 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
601 if (CORBA::is_nil(myCase))
603 SALOME::ExceptionStruct es;
604 es.type = SALOME::BAD_PARAM;
605 es.text = "Invalid Case";
606 throw SALOME::SALOME_Exception(es);
610 return HOMARD::HOMARD_Cas::_duplicate(myCase);
613 //=============================================================================
614 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
617 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
618 ASSERT(!CORBA::is_nil(myZone));
619 return HOMARD::HOMARD_Zone::_duplicate(myZone);
622 //=============================================================================
623 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
625 MESSAGE ( "GetHypothesis : nomHypothesis = " << nomHypothesis );
627 MESSAGE ( "GetHypothesis : GetCurrentStudyID() = " << GetCurrentStudyID() );
628 HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
629 ASSERT(!CORBA::is_nil(myHypothesis));
630 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
633 //=============================================================================
634 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* nomIteration)
637 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIteration];
638 ASSERT(!CORBA::is_nil(myIteration));
639 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
641 //=============================================================================
642 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
646 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
647 ASSERT(!CORBA::is_nil(myBoundary));
648 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
651 //=============================================================================
652 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
654 MESSAGE ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
657 if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
659 SALOME::ExceptionStruct es;
660 es.type = SALOME::BAD_PARAM;
661 es.text = "This hypothesis is already defined.";
662 throw SALOME::SALOME_Exception(es);
666 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
667 myHypothesis->SetName(nomHypothesis);
668 myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
669 SALOMEDS::SObject_var aSO;
670 PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
672 // Valeurs par defaut des options avancees
673 myHypothesis->SetNivMax(-1);
674 myHypothesis->SetDiamMin(-1.0);
675 myHypothesis->SetAdapInit(0);
676 myHypothesis->SetLevelOutput(0);
678 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
681 //============================================================================================================
682 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* nomIteration, const char* nomIterParent)
683 //============================================================================================================
685 MESSAGE ("CreateIteration : nomIteration = " << nomIteration << "nomIterParent = " << nomIterParent);
688 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
689 if (CORBA::is_nil(myIterationParent))
691 SALOME::ExceptionStruct es;
692 es.type = SALOME::BAD_PARAM;
693 es.text = "The parent iteration is not defined.";
694 throw SALOME::SALOME_Exception(es);
698 const char* nomCas = GetCaseName(nomIterParent);
699 MESSAGE ("CreateIteration : nomCas = " << nomCas);
700 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
701 if (CORBA::is_nil(myCase))
703 SALOME::ExceptionStruct es;
704 es.type = SALOME::BAD_PARAM;
705 es.text = "Invalid Case Context ";
706 throw SALOME::SALOME_Exception(es);
710 if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(nomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
712 SALOME::ExceptionStruct es;
713 es.type = SALOME::BAD_PARAM;
714 es.text = "This iteration is already defined. ";
715 throw SALOME::SALOME_Exception(es);
719 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
720 if (CORBA::is_nil(myIteration))
722 SALOME::ExceptionStruct es;
723 es.type = SALOME::BAD_PARAM;
724 es.text = "Unable to create Iteration ";
725 throw SALOME::SALOME_Exception(es);
728 myContextMap[GetCurrentStudyID()]._mesIterations[std::string(nomIteration)] = myIteration;
729 myIteration->SetName(nomIteration);
730 myIteration->SetMeshName(nomIteration);
732 int numero = myIterationParent->GetNumber() + 1;
733 myIteration->SetNumber(numero);
735 // Nombre d'iterations deja connues pour le cas, permettant
736 // la creation d'un sous-repertoire unique
737 int nbitercase = myCase->GetNumber();
738 std::ostringstream iaux ;
739 iaux << std::setw(2) << std::setfill('0') << nbitercase ;
740 std::stringstream DirName;
741 DirName << "I" << iaux.str();
742 myIteration->SetDirName(DirName.str().c_str());
744 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
745 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
746 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est le
747 // cas le plus frequent.
748 // Si on a plusieurs branches, donc des iterations a meme niveau d'adaptation, utiliser
749 // le nombre d'iterations du cas permet d'eviter les collisions.
750 std::stringstream MeshFile;
751 const char* nomDir = myCase->GetDirName();
752 MeshFile << nomDir << "/maill." << iaux.str() << ".med";
753 myIteration->SetMeshFile(MeshFile.str().c_str());
755 // Association avec le cas et l'iteration precedente
756 std::string label = "IterationHomard_" + std::string(nomIterParent);
757 AssociateCaseIter(nomCas, nomIteration, label.c_str());
758 AssociateIterIter (nomIterParent,nomIteration);
760 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
764 //=============================================================================
765 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
767 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
770 if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
772 SALOME::ExceptionStruct es;
773 es.type = SALOME::BAD_PARAM;
774 es.text = "This boundary has already been defined";
775 throw SALOME::SALOME_Exception(es);
779 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
780 myBoundary->SetName(BoundaryName);
781 myBoundary->SetBoundaryType(BoundaryType);
783 myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
785 SALOMEDS::SObject_var aSO;
786 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
788 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
790 //=============================================================================
791 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
793 MESSAGE ("CreateBoundaryDi : BoundaryName = " << BoundaryName << "MeshName = " << MeshName );
794 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
795 myBoundary->SetMeshFile( MeshFile ) ;
796 myBoundary->SetMeshName( MeshName ) ;
798 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
800 //=============================================================================
801 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
802 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
803 CORBA::Double Xaxis, CORBA::Double Yaxis, CORBA::Double Zaxis,
806 MESSAGE ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
807 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
808 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxis, Yaxis, Zaxis, Rayon ) ;
810 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
812 //=============================================================================
813 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
814 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
817 MESSAGE ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
818 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
819 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
821 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
825 //=============================================================================
826 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
828 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
831 if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
833 SALOME::ExceptionStruct es;
834 es.type = SALOME::BAD_PARAM;
835 es.text = "This zone has already been defined";
836 throw SALOME::SALOME_Exception(es);
840 HOMARD::HOMARD_Zone_var myZone = newZone();
841 myZone->SetName(ZoneName);
842 myZone->SetZoneType(ZoneType);
844 myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
846 SALOMEDS::SObject_var aSO;
847 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
849 return HOMARD::HOMARD_Zone::_duplicate(myZone);
851 //=============================================================================
852 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
853 CORBA::Double Xmini, CORBA::Double Xmaxi,
854 CORBA::Double Ymini, CORBA::Double Ymaxi,
855 CORBA::Double Zmini, CORBA::Double Zmaxi)
857 MESSAGE ("CreateZoneBox : ZoneName = " << ZoneName ) ;
858 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
859 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
861 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
863 //=============================================================================
864 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
865 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
867 MESSAGE ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
868 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
869 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
871 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
873 //=============================================================================
874 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
875 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
876 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
877 CORBA::Double Rayon, CORBA::Double Haut)
879 MESSAGE ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
880 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
881 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
883 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
885 //=============================================================================
886 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
887 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
888 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
889 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
891 MESSAGE ("CreateZonePipe : ZoneName = " << ZoneName ) ;
892 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
893 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
895 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
897 //=============================================================================
898 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
899 CORBA::Double Umini, CORBA::Double Umaxi,
900 CORBA::Double Vmini, CORBA::Double Vmaxi,
903 MESSAGE ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
904 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
905 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
906 // MESSAGE ("Orient = " << Orient ) ;
908 double Xmini, Xmaxi ;
909 double Ymini, Ymaxi ;
910 double Zmini, Zmaxi ;
918 else if ( Orient == 2 )
925 else if ( Orient == 3 )
932 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
934 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
935 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
937 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
939 //=============================================================================
940 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
941 CORBA::Double Ucentre, CORBA::Double Vcentre,
945 MESSAGE ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
950 { Xcentre = Ucentre ;
953 else if ( Orient == 2 )
956 Zcentre = Vcentre ; }
957 else if ( Orient == 3 )
958 { Xcentre = Vcentre ;
960 Zcentre = Ucentre ; }
961 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
963 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
964 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
966 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
968 //=============================================================================
969 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
970 CORBA::Double Ucentre, CORBA::Double Vcentre,
971 CORBA::Double Rayon, CORBA::Double Rayonint,
974 MESSAGE ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
979 { Xcentre = Ucentre ;
982 else if ( Orient == 2 )
985 Zcentre = Vcentre ; }
986 else if ( Orient == 3 )
987 { Xcentre = Vcentre ;
989 Zcentre = Ucentre ; }
990 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
992 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
993 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
995 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1001 //=============================================================================
1002 CORBA::Long HOMARD_Gen_i::Compute(const char* nomIteration, CORBA::Long etatMenage)
1004 MESSAGE ( "Compute : calcul de " << nomIteration );
1007 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIteration];
1008 ASSERT(!CORBA::is_nil(myIteration));
1010 // on ne calcule pas l iteration 0
1011 int NumeIter = myIteration->GetNumber();
1012 if ( NumeIter == 0 )
1014 SALOME::ExceptionStruct es;
1015 es.type = SALOME::BAD_PARAM;
1016 es.text = "This iteration is the first of the case and cannot be computed.";
1017 throw SALOME::SALOME_Exception(es);
1021 // on verifie qu il y a une hypothese (erreur improbable);
1022 const char* nomHypo = myIteration->GetHypoName();
1023 if (std::string(nomHypo) == std::string(""))
1025 SALOME::ExceptionStruct es;
1026 es.type = SALOME::BAD_PARAM;
1027 es.text= "This iteration does not have any associated hypothesis.";
1028 throw SALOME::SALOME_Exception(es);
1031 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
1032 ASSERT(!CORBA::is_nil(myHypo));
1035 // A.4. L'iteration parent
1036 const char* nomIterationParent = myIteration->GetIterParent();
1037 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
1038 ASSERT(!CORBA::is_nil(myIterationParent));
1039 if ( ! myIterationParent->GetEtat() )
1042 SALOME::ExceptionStruct es;
1043 es.type = SALOME::BAD_PARAM;
1044 std::string text = "The iteration cannot be computed because the previous iteration " + std::string(nomIterationParent) + " is not valid.";
1045 es.text = CORBA::string_dup(text.c_str());
1046 throw SALOME::SALOME_Exception(es);
1049 int codret = Compute(nomIterationParent, etatMenage);
1052 // GERALD -- QMESSAGE BOX
1053 ASSERT("Pb au calcul de l'iteration precedente" == 0);
1057 const char* nomCas = myIteration->GetCaseName();
1058 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1059 ASSERT(!CORBA::is_nil(myCase));
1062 std::stringstream saux0 ;
1063 saux0 << NumeIter - 1 ;
1064 std::string siter = saux0.str() ;
1065 if (NumeIter < 11) { siter = "0" + siter ; }
1067 std::stringstream saux1 ;
1069 std::string siterp1 = saux1.str() ;
1070 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
1072 // B. Les repertoires
1073 // B.1. Le repertoire du cas
1074 const char* nomDir = myCase->GetDirName();
1075 MESSAGE ( ". nomDir = " << nomDir );
1077 // B.2. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
1078 // B.2.1. Le nom du sous-repertoire
1079 const char* nomDirIt = myIteration->GetDirName();
1081 // B.2.2. Le nom complet du sous-repertoire
1082 std::stringstream DirCompute ;
1083 DirCompute << nomDir << "/" << nomDirIt;
1084 MESSAGE (". DirCompute = " << DirCompute.str() );
1086 // B.2.3. Si le sous-repertoire n'existe pas, on le cree
1087 // Si le sous-repertoire existe :
1088 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
1089 // etatMenage = 1 : on fait le menage du repertoire
1090 if (chdir(DirCompute.str().c_str()) != 0)
1092 // Creation du repertoire car il n'existe pas :
1093 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1095 // GERALD -- QMESSAGE BOX
1096 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
1097 ASSERT("Pb a la creation du repertoire" == 0);
1102 // Le repertoire existe et on fait le menage de son contenu :
1103 if (etatMenage != 0)
1105 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
1106 std::string commande= "rm -rf " + DirCompute.str()+"/*" ;
1107 int codret = system(commande.c_str());
1110 // GERALD -- QMESSAGE BOX
1111 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
1112 ASSERT("Pb au menage du repertoire de calcul" == 0);
1117 // Le repertoire existe et s'il n'est pas vide, on sort en erreur :
1119 struct dirent *dirp;
1120 dp = opendir(DirCompute.str().c_str());
1122 while ((dirp = readdir(dp)) != NULL && result )
1124 std::string file_name(dirp->d_name);
1125 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
1128 if ( result == false)
1130 SALOME::ExceptionStruct es;
1131 es.type = SALOME::BAD_PARAM;
1132 std::string text = "Directory : " + DirCompute.str() + "is not empty";
1133 es.text = CORBA::string_dup(text.c_str());
1134 throw SALOME::SALOME_Exception(es);
1140 // B.3. Le sous-repertoire de l'iteration precedente
1141 const char* nomDirItPa ;
1142 std::stringstream DirComputePa ;
1145 nomDirItPa = nomDirIt;
1146 DirComputePa << DirCompute.str();
1150 nomDirItPa = myIterationParent->GetDirName();
1151 DirComputePa << nomDir << "/" << nomDirItPa;
1153 MESSAGE( ". nomDirItPa = " << nomDirItPa);
1154 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
1156 // B.4. Le fichier des messages
1157 chdir(DirCompute.str().c_str()) ;
1158 std::string MessFile = DirCompute.str() + "/Liste." + siter + ".vers." + siterp1 ;
1159 MESSAGE (". MessFile = " << MessFile);
1160 myIteration->SetMessFile(MessFile.c_str());
1162 // C. On passe dans le repertoire de l'iteration a calculer
1163 chdir(DirCompute.str().c_str()) ;
1165 // D. Les donnees du calcul HOMARD
1166 // D.1. Le type de conformite
1167 int ConfType = myCase->GetConfType();
1168 MESSAGE ( ". ConfType = " << ConfType );
1170 // D.2. Le maillage n
1171 const char* NomMeshParent = myIterationParent->GetMeshName();
1172 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
1173 const char* MeshFileParent = myIterationParent->GetMeshFile();
1174 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
1176 // D.3. Le maillage n+1
1177 const char* NomMesh = myIteration->GetMeshName();
1178 MESSAGE ( ". NomMesh = " << NomMesh );
1179 const char* MeshFile = myIteration->GetMeshFile();
1180 MESSAGE ( ". MeshFile = " << MeshFile );
1181 FILE *file = fopen(MeshFile,"r");
1185 if (etatMenage == 0)
1187 SALOME::ExceptionStruct es;
1188 es.type = SALOME::BAD_PARAM;
1189 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
1190 es.text = CORBA::string_dup(text.c_str());
1191 throw SALOME::SALOME_Exception(es);
1196 std::string commande = "rm -f " + std::string(MeshFile);
1197 codret = system(commande.c_str());
1200 SALOME::ExceptionStruct es;
1201 es.type = SALOME::BAD_PARAM;
1202 std::string text = "PB with meshfile destruction ";
1203 es.text = CORBA::string_dup(text.c_str());
1204 throw SALOME::SALOME_Exception(es);
1215 // D.4. Les types de raffinement et de deraffinement
1216 // Les appels corba sont lourds, il vaut mieux les grouper
1217 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
1218 ASSERT(ListTypes->length() == 3);
1219 int TypeAdap = (*ListTypes)[0];
1220 int TypeRaff = (*ListTypes)[1];
1221 int TypeDera = (*ListTypes)[2];
1223 // D.6. L'option d'interpolation des champs
1224 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
1226 // E. Texte du fichier de configuration
1227 // E.1. Incontournables du texte
1228 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
1229 myDriver->TexteInit(DirCompute.str(), DirComputePa.str(),MessFile);
1230 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
1231 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
1232 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
1234 // E.2. Ajout des informations liees aux zones eventuelles
1237 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
1238 int numberOfZonesx2 = ListZone->length();
1241 for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
1243 std::string ZoneName = std::string((*ListZone)[iaux]);
1244 MESSAGE ( "... ZoneName = " << ZoneName);
1245 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1246 ASSERT(!CORBA::is_nil(myZone));
1248 int ZoneType = myZone->GetZoneType();
1249 std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
1250 int TypeUse = atoi( TypeUsestr.c_str() );
1251 MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
1252 NumZone = iaux/2 + 1 ;
1253 HOMARD::double_array* zone = myZone->GetCoords();
1254 if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
1256 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.);
1258 else if ( ZoneType == 4 ) // Cas d une sphere
1260 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.);
1262 else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
1264 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.);
1266 else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
1268 myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]);
1270 else { ASSERT("ZoneType est incorrect." == 0) ; }
1274 // E.3. Ajout des informations liees aux champs eventuels
1277 // Le fichier du champ
1278 char* FieldFile = myIteration->GetFieldFile();
1279 MESSAGE ( ". FieldFile = " << FieldFile );
1280 if (strlen(FieldFile) == 0)
1282 // GERALD -- QMESSAGE BOX
1283 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1284 ASSERT("The file for the field is not given." == 0);
1286 // Les caracteristiques d'instants
1287 int TimeStep = myIteration->GetTimeStep();
1288 MESSAGE( ". TimeStep = " << TimeStep );
1289 int Rank = myIteration->GetRank();
1290 MESSAGE( ". Rank = " << Rank );
1291 // Les informations sur les champ
1292 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
1294 const char* FieldName = aInfosHypo->FieldName;
1296 int TypeThR = aInfosHypo->TypeThR;
1297 double ThreshR = aInfosHypo->ThreshR;
1298 int TypeThC = aInfosHypo->TypeThC;
1299 double ThreshC = aInfosHypo->ThreshC;
1300 // Saut entre mailles ou non ?
1301 int UsField = aInfosHypo->UsField;
1302 MESSAGE( ". UsField = " << UsField );
1303 // L'usage des composantes
1304 int UsCmpI = aInfosHypo->UsCmpI;
1305 MESSAGE( ". UsCmpI = " << UsCmpI );
1307 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
1310 HOMARD::listeComposantsHypo* mescompo = myHypo->GetListComp();
1311 int numberOfCompos = mescompo->length();
1312 MESSAGE( ". numberOfCompos = " << numberOfCompos );
1313 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
1315 std::string nomCompo = std::string((*mescompo)[NumeComp]);
1316 MESSAGE( "... nomCompo = " << nomCompo );
1317 myDriver->TexteCompo(NumeComp, nomCompo);
1320 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
1321 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
1322 int numberOfGroups = listeGroupes->length();
1323 MESSAGE( ". numberOfGroups = " << numberOfGroups );
1324 if (numberOfGroups > 0)
1327 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
1329 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
1330 MESSAGE( "... GroupName = " << GroupName );
1331 myDriver->TexteGroup(GroupName);
1335 // E.5. Ajout des informations liees a l'eventuel suivi de frontiere
1336 // On ecrit d'abord la definition des frontieres, puis les liens avec les groupes
1337 std::list<std::string> ListeBoundaryTraitees ;
1338 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
1339 int numberOfitems = ListBoundaryGroupType->length();
1340 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
1341 int BoundaryOption = 1 ;
1342 int NumBoundaryAnalytical = 0 ;
1343 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1345 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1346 MESSAGE ( "... BoundaryName = " << BoundaryName);
1348 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
1349 while (it != ListeBoundaryTraitees.end())
1351 MESSAGE ( "... BoundaryNameTraitee = " << *it);
1352 if ( BoundaryName == *it ) { A_faire = 0 ; }
1357 // Caracteristiques de la frontiere
1358 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1359 ASSERT(!CORBA::is_nil(myBoundary));
1360 int BoundaryType = myBoundary->GetBoundaryType();
1361 MESSAGE ( "... BoundaryType = " << BoundaryType );
1362 // Ecriture selon le type
1363 if (BoundaryType == 0) // Cas d une frontiere discrete
1365 const char* MeshName = myBoundary->GetMeshName() ;
1366 const char* MeshFile = myBoundary->GetMeshFile() ;
1367 myDriver->TexteBoundaryDi( MeshName, MeshFile);
1368 BoundaryOption = BoundaryOption*2 ;
1370 else // Cas d une frontiere analytique
1372 NumBoundaryAnalytical++ ;
1373 HOMARD::double_array* coor = myBoundary->GetCoords();
1374 if (BoundaryType == 1) // Cas d un cylindre
1376 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6]);
1377 BoundaryOption = BoundaryOption*3 ;
1379 else if (BoundaryType == 2) // Cas d une sphere
1381 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0.);
1382 BoundaryOption = BoundaryOption*3 ;
1385 // Memorisation du traitement
1386 ListeBoundaryTraitees.push_back( BoundaryName );
1389 NumBoundaryAnalytical = 0 ;
1390 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1392 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1393 MESSAGE ( "... BoundaryName = " << BoundaryName);
1394 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1395 ASSERT(!CORBA::is_nil(myBoundary));
1396 int BoundaryType = myBoundary->GetBoundaryType();
1397 MESSAGE ( "... BoundaryType = " << BoundaryType );
1398 // Recuperation du nom du groupe
1399 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
1400 MESSAGE ( "... GroupName = " << GroupName);
1401 if (BoundaryType == 0) // Cas d une frontiere discrete
1403 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
1405 else // Cas d une frontiere analytique
1407 NumBoundaryAnalytical++ ;
1408 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
1411 myDriver->TexteBoundaryOption(BoundaryOption);
1413 // E.6. Ajout des informations liees a l'eventuelle interpolation des champs
1414 MESSAGE( "... TypeFieldInterp = " << TypeFieldInterp );
1415 if (TypeFieldInterp != 0)
1417 // Le fichier des champs
1418 char* FieldFile = myIteration->GetFieldFile();
1419 MESSAGE ( ". FieldFile = " << FieldFile );
1420 if (strlen(FieldFile) == 0)
1422 // GERALD -- QMESSAGE BOX
1423 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1424 ASSERT("The file for the field is not given." == 0);
1426 // Les caracteristiques d'instants
1427 int TimeStep = myIteration->GetTimeStep();
1428 MESSAGE( ". TimeStep = " << TimeStep );
1429 int Rank = myIteration->GetRank();
1430 MESSAGE( ". Rank = " << Rank );
1432 myDriver->TexteFieldInterp(TypeFieldInterp, FieldFile, MeshFile, TimeStep, Rank);
1434 if (TypeFieldInterp == 2)
1436 HOMARD::listFieldInterpHypo* meschamps = myHypo->GetListFieldInterp();
1437 int numberOfFields = meschamps->length();
1438 MESSAGE( ". numberOfFields = " << numberOfFields );
1439 for (int NumeChamp = 0; NumeChamp< numberOfFields; NumeChamp++)
1441 std::string nomChamp = std::string((*meschamps)[NumeChamp]);
1442 MESSAGE( "... nomChamp = " << nomChamp );
1443 myDriver->TexteFieldInterpName(NumeChamp, nomChamp);
1447 // E.7. Ajout des options avancees
1448 int Pyram = myCase->GetPyram();
1449 MESSAGE ( ". Pyram = " << Pyram );
1450 int NivMax = myHypo->GetNivMax();
1451 MESSAGE ( ". NivMax = " << NivMax );
1452 double DiamMin = myHypo->GetDiamMin() ;
1453 MESSAGE ( ". DiamMin = " << DiamMin );
1454 int AdapInit = myHypo->GetAdapInit();
1455 MESSAGE ( ". AdapInit = " << AdapInit );
1456 int LevelOutput = myHypo->GetLevelOutput();
1457 MESSAGE ( ". LevelOutput = " << LevelOutput );
1458 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
1460 // F. Ecriture du texte dans le fichier
1463 myDriver->CreeFichier();
1468 int codretexec = 12 ;
1471 codretexec = myDriver->ExecuteHomard();
1473 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
1474 if (codretexec == 0)
1476 SetEtatIter(nomIteration,true);
1480 // GERALD -- QMESSAGE BOX
1481 SetEtatIter(nomIteration,false);
1485 // H. Gestion des resultats
1488 // H.1. Le fichier des messages, dans tous les cas
1489 std::stringstream saux1 ;
1490 saux1 << "Mess " << NumeIter ;
1491 PublishFileUnderIteration(nomIteration, MessFile.c_str(), saux1.str().c_str());
1493 // H.2. Si tout s'est bien passe :
1494 if (codretexec == 0)
1496 // H.2.1. Le fichier de bilan
1497 std::stringstream saux2 ;
1498 saux2 << "Summary " << NumeIter ;
1499 std::string SummaryFile = DirCompute.str() + "/apad." + siterp1 + ".bilan" ;
1500 PublishFileUnderIteration(nomIteration, SummaryFile.c_str(), saux2.str().c_str());
1501 // H.2.2. Le fichier de maillage obtenu
1502 std::stringstream saux0 ;
1503 saux0 <<"Iteration " << NumeIter ;
1504 PublishFileUnderIteration(nomIteration, MeshFile, saux0.str().c_str());
1505 PublishResultInSmesh(MeshFile, 1);
1507 // H.3 Message d'erreur en cas de probleme
1510 SALOME::ExceptionStruct es;
1511 es.type = SALOME::BAD_PARAM;
1512 std::string text = "Error during the adaptation.\n" ;
1515 ifstream fichier(MessFile.c_str(), ios::in);
1517 while(getline(fichier, ligne) and (ligne != "===== HOMARD ===== STOP ====="));
1518 while (getline(fichier, ligne)) { text += ligne+ "\n";};
1521 text += "no log file ....";
1523 es.text = CORBA::string_dup(text.c_str());
1524 throw SALOME::SALOME_Exception(es);
1537 //===========================================================================
1538 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
1539 SALOMEDS::SObject_ptr theSObject,
1540 CORBA::Object_ptr theObject,
1541 const char* theName)
1543 MESSAGE("PublishInStudy pour " << theName);
1544 SALOMEDS::SObject_var aResultSO;
1545 if (CORBA::is_nil(theStudy))
1547 SALOME::ExceptionStruct es;
1548 es.type = SALOME::BAD_PARAM;
1549 es.text = "Invalid Study Context ";
1550 throw SALOME::SALOME_Exception(es);
1554 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
1555 // Rq : Iteration est publiee ailleurs
1556 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
1557 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
1558 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
1559 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
1561 addInStudy(theStudy);
1563 // Controle de la non publication d'un objet de meme nom
1564 if ((!aHypo->_is_nil()) or (!aZone->_is_nil()) or (!aBoundary->_is_nil()))
1566 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
1567 if (listSO->length() >= 1)
1569 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
1570 std::cerr <<"This name "<<theName<<" is already used "<<listSO->length()<<" time(s)" << std::endl;
1571 aResultSO = listSO[0];
1572 return aResultSO._retn();
1576 // Caracteristiques de l'etude
1577 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1578 aStudyBuilder->NewCommand();
1579 if(!aCase->_is_nil())
1580 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
1581 else if(!aHypo->_is_nil())
1582 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
1583 else if(!aZone->_is_nil())
1584 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
1585 else if(!aBoundary->_is_nil())
1586 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
1588 aStudyBuilder->CommitCommand();
1589 return aResultSO._retn();
1591 //=============================================================================
1592 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
1593 SALOMEDS::StudyBuilder_var aStudyBuilder,
1594 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
1596 MESSAGE("PublishCaseInStudy pour "<<theName);
1597 SALOMEDS::SObject_var aResultSO;
1598 SALOMEDS::GenericAttribute_var anAttr;
1600 if (CORBA::is_nil(theObject)) {
1601 MESSAGE("HOMARD_Gen_i.cxx::theObject->_is_nil()");
1602 return aResultSO._retn();
1604 if (theStudy->_is_nil()) {
1605 MESSAGE("HOMARD_Gen_i.cxx::theStudy->_is_nil()");
1606 return aResultSO._retn();
1609 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1610 if (theFatherHomard->_is_nil())
1612 MESSAGE("theFatherHomard->_is_nil()");
1613 return aResultSO._retn();
1616 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
1617 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
1618 _orb->object_to_string(theObject) ) ;
1619 return aResultSO._retn();
1622 //=============================================================================
1623 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
1624 SALOMEDS::StudyBuilder_var aStudyBuilder,
1625 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
1627 MESSAGE("PublishZoneStudy pour "<<theName);
1628 SALOMEDS::SObject_var aResultSO;
1629 SALOMEDS::GenericAttribute_var anAttr;
1631 if (CORBA::is_nil(theObject))
1633 MESSAGE("HOMARD_Gen_i.cxx::theObject->_is_nil()");
1634 return aResultSO._retn();
1636 if (theStudy->_is_nil())
1638 MESSAGE("HOMARD_Gen_i.cxx::theStudy->_is_nil()");
1639 return aResultSO._retn();
1641 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1642 if (theFatherHomard->_is_nil())
1644 MESSAGE("theFatherHomard->_is_nil()");
1645 return aResultSO._retn();
1648 // Caracteristique de la zone
1649 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
1650 CORBA::Long ZoneType = myZone->GetZoneType();
1652 // On ajoute la categorie des zones dans l etude si necessaire
1653 SALOMEDS::SObject_var aSOZone;
1654 if (!theFatherHomard->FindSubObject(100, aSOZone))
1656 MESSAGE("Ajout de la categorie des zones");
1657 aSOZone = aStudyBuilder->NewObjectToTag(theFatherHomard, 100);
1658 PublishInStudyAttr(aStudyBuilder, aSOZone, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
1660 else { MESSAGE("La categorie des zones existe deja."); }
1662 aResultSO = aStudyBuilder->NewObject(aSOZone);
1671 { icone = "boxdxy_2.png" ;
1675 { icone = "boxdxyz_2.png" ;
1683 { icone = "disk_2.png" ;
1687 { icone = "spherepoint_2.png" ;
1691 { icone = "cylinderpointvector_2.png" ;
1699 { icone = "diskwithhole_2.png" ;
1703 { icone = "pipe_2.png" ;
1707 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone, _orb->object_to_string(theObject) ) ;
1709 return aResultSO._retn();
1711 //=============================================================================
1712 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
1713 SALOMEDS::StudyBuilder_var aStudyBuilder,
1714 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
1716 MESSAGE("PublishBoundaryStudy pour "<<theName);
1717 SALOMEDS::SObject_var aResultSO;
1718 SALOMEDS::GenericAttribute_var anAttr;
1720 // Caracteristique de la Boundary
1721 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
1723 // On recupere le module pere dans l etude
1724 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1725 if (theFatherHomard->_is_nil())
1727 MESSAGE("theFatherHomard->_is_nil()");
1728 return aResultSO._retn();
1731 // On ajoute la categorie des boundarys dans l etude si necessaire
1732 SALOMEDS::SObject_var aSOBoundary;
1733 if (!theFatherHomard->FindSubObject(101, aSOBoundary))
1735 MESSAGE("Ajout de la categorie des boundarys");
1736 aSOBoundary = aStudyBuilder->NewObjectToTag(theFatherHomard, 101);
1737 PublishInStudyAttr(aStudyBuilder, aSOBoundary, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
1739 else { MESSAGE("La categorie des boundarys existe deja."); }
1741 aResultSO = aStudyBuilder->NewObject(aSOBoundary);
1742 CORBA::Long BoundaryType = myBoundary->GetBoundaryType();
1743 // MESSAGE("BoundaryType : "<<BoundaryType);
1746 switch (BoundaryType)
1749 { value = "BoundaryDiHomard" ;
1750 icone = "mesh_tree_mesh.png" ;
1754 { value = "BoundaryAnHomard" ;
1755 icone = "cylinderpointvector_2.png" ;
1759 { value = "BoundaryAnHomard" ;
1760 icone = "spherepoint_2.png" ;
1764 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value, icone, _orb->object_to_string(theObject));
1765 return aResultSO._retn();
1768 //=============================================================================
1769 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
1770 SALOMEDS::StudyBuilder_var aStudyBuilder,
1771 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
1773 MESSAGE("PublishHypotheseInStudy pour "<<theName);
1774 SALOMEDS::SObject_var aResultSO;
1775 SALOMEDS::GenericAttribute_var anAttr;
1777 // On recupere le module pere dans l etude
1778 // On ajoute la categorie des hypotheses dans l etude si necessaire
1779 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1780 if (theFatherHomard->_is_nil())
1782 MESSAGE("theFatherHomard->_is_nil()");
1783 return aResultSO._retn();
1785 SALOMEDS::SObject_var aSOHypothese;
1786 if (!theFatherHomard->FindSubObject(0, aSOHypothese))
1788 MESSAGE("Ajout de la categorie des hypotheses");
1789 aSOHypothese = aStudyBuilder->NewObjectToTag(theFatherHomard, 0);
1790 PublishInStudyAttr(aStudyBuilder, aSOHypothese, "Hypothesis", "HypoList","hypotheses.png", NULL);
1792 else { MESSAGE("La categorie des hypotheses existe deja."); }
1794 // Creation du resultat dans l'etude
1795 aResultSO = aStudyBuilder->NewObject(aSOHypothese);
1796 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
1798 return aResultSO._retn();
1800 //===========================================================================
1801 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
1802 SALOMEDS::SObject_var aResultSO,
1803 const char* name, const char* value, const char* icone, const char* ior)
1805 SALOMEDS::GenericAttribute_var anAttr ;
1809 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
1810 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
1811 aNameAttrib->SetValue(name);
1814 // Ajout du commentaire
1815 if ( value != NULL )
1817 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
1818 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
1819 aCommentAttrib->SetValue(value);
1823 if ( icone != NULL )
1825 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO,"AttributePixMap");
1826 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
1827 aPixmap->SetPixMap(icone);
1833 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
1834 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1835 anIOR->SetValue(ior);
1839 //=============================================================================
1840 HOMARD::listeCases* HOMARD_Gen_i::GetAllCases()
1842 MESSAGE("GetAllCases");
1845 HOMARD::listeCases_var ret = new HOMARD::listeCases;
1846 ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
1847 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
1849 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
1850 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
1852 ret[i++] = CORBA::string_dup((*it).first.c_str());
1858 //=============================================================================
1859 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypotheses()
1861 MESSAGE("GetAllHypotheses");
1864 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
1865 ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
1866 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
1868 for (it = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
1869 it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
1871 ret[i++] = CORBA::string_dup((*it).first.c_str());
1877 //=============================================================================
1878 HOMARD::listeZones* HOMARD_Gen_i::GetAllZones()
1880 MESSAGE("GetAllZones");
1883 HOMARD::listeZones_var ret = new HOMARD::listeZones;
1884 ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
1885 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
1887 for (it = myContextMap[GetCurrentStudyID()]._mesZones.begin();
1888 it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
1890 ret[i++] = CORBA::string_dup((*it).first.c_str());
1896 //=============================================================================
1897 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterations()
1899 MESSAGE("GetAllIterations");
1902 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
1903 ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
1904 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
1906 for (it = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
1907 it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
1909 ret[i++] = CORBA::string_dup((*it).first.c_str());
1914 //=============================================================================
1915 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarys()
1917 MESSAGE("GetAllBoundarys");
1920 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
1921 ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
1922 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
1924 for (it = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
1925 it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
1927 ret[i++] = CORBA::string_dup((*it).first.c_str());
1933 //=============================================================================
1934 char* HOMARD_Gen_i::GetCaseName(const char* nomIteration)
1936 if (CORBA::is_nil(myCurrentStudy))
1938 SALOME::ExceptionStruct es;
1939 es.type = SALOME::BAD_PARAM;
1940 es.text = "Invalid Study Context ";
1941 throw SALOME::SALOME_Exception(es);
1945 HOMARD::HOMARD_Iteration_var monIter = myContextMap[GetCurrentStudyID()]._mesIterations[nomIteration];
1946 ASSERT(!CORBA::is_nil(monIter));
1947 return CORBA::string_dup(monIter->GetCaseName());
1949 //=============================================================================
1950 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long IconeType)
1952 MESSAGE( "PublishResultInSmesh " << NomFich);
1953 if (CORBA::is_nil(myCurrentStudy))
1955 SALOME::ExceptionStruct es;
1956 es.type = SALOME::BAD_PARAM;
1957 es.text = "Invalid Study Context ";
1958 throw SALOME::SALOME_Exception(es);
1962 // Le module SMESH est-il actif ?
1963 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
1965 if (!CORBA::is_nil(aSmeshSO))
1967 // On verifie que le fichier n est pas deja publie
1968 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
1969 for (; aIter->More(); aIter->Next())
1971 SALOMEDS::SObject_var aSO = aIter->Value();
1972 SALOMEDS::GenericAttribute_var aGAttr;
1973 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
1975 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
1976 CORBA::String_var value=anAttr->Value();
1977 if (strcmp((const char*)value,NomFich) == 0)
1979 // GERALD -- QMESSAGE BOX
1980 std::cerr << "fichier : "<< NomFich << " deja publie "<< std::endl;
1988 // On enregistre le fichier
1989 MESSAGE( "Enregistrement du fichier");
1990 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
1991 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
1992 ASSERT(!CORBA::is_nil(aSmeshEngine));
1993 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
1994 SMESH::DriverMED_ReadStatus theStatus;
1995 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
1997 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
1998 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
1999 for (int i = 0; i < mesMaillages->length(); i++)
2001 MESSAGE( ". Mise a jour des attributs du maillage");
2002 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
2003 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
2004 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2005 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
2006 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2007 anAttr->SetValue(NomFich);
2008 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
2009 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
2010 // IconeType = 0 : fichier issu d'une importation
2011 // IconeType = 1 : fichier issu d'une execution HOMARD
2013 if ( IconeType == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
2014 else { icone = "mesh_tree_mesh.png" ; }
2015 anAttr2->SetPixMap( icone );
2019 //=============================================================================
2020 void HOMARD_Gen_i::DeleteResultInSmesh(const char* NomFich, const char* MeshName)
2022 MESSAGE (" DeleteResultInSmesh pour "<< NomFich << "et le maillage "<< MeshName);
2023 if (CORBA::is_nil(myCurrentStudy))
2025 SALOME::ExceptionStruct es;
2026 es.type = SALOME::BAD_PARAM;
2027 es.text = "Invalid Study Context ";
2028 throw SALOME::SALOME_Exception(es);
2032 // Le module SMESH est-il actif ?
2033 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
2035 if (CORBA::is_nil(aSmeshSO))
2039 // On verifie que le fichier est deja publie
2040 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
2041 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
2042 for (; aIter->More(); aIter->Next())
2044 SALOMEDS::SObject_var aSO = aIter->Value();
2045 SALOMEDS::GenericAttribute_var aGAttr;
2046 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
2048 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2049 CORBA::String_var value=anAttr->Value();
2050 if (strcmp((const char*)value,NomFich) == 0)
2052 if (aSO->FindAttribute(aGAttr,"AttributeName"))
2054 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
2055 CORBA::String_var value2=anAttr2->Value();
2056 if (strcmp((const char*)value2,MeshName) == 0)
2058 myBuilder->RemoveObjectWithChildren( aSO ) ;
2066 //=============================================================================
2067 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
2069 if (CORBA::is_nil(myCurrentStudy))
2071 SALOME::ExceptionStruct es;
2072 es.type = SALOME::BAD_PARAM;
2073 es.text = "Invalid Study Context ";
2074 throw SALOME::SALOME_Exception(es);
2078 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
2079 if (CORBA::is_nil(myIteration))
2081 SALOME::ExceptionStruct es;
2082 es.type = SALOME::BAD_PARAM;
2083 es.text = "Invalid Iteration ";
2084 throw SALOME::SALOME_Exception(es);
2087 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
2088 if (CORBA::is_nil(myIteration))
2090 SALOME::ExceptionStruct es;
2091 es.type = SALOME::BAD_PARAM;
2092 es.text = "Invalid Iteration Study Object";
2093 throw SALOME::SALOME_Exception(es);
2097 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2099 aStudyBuilder->NewCommand();
2101 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
2102 // Pour les fichiers med, on affiche une icone de maillage
2103 // Pour les fichiers qui sont texte, on affiche une icone de fichier texte 'texte'
2104 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
2106 const char* ior = " " ;
2107 if ( Commentaire[0] == 'I' )
2108 { icone = "med.png" ; }
2110 { icone = "texte_2.png" ; }
2111 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone, ior ) ;
2113 aStudyBuilder->CommitCommand();
2116 //=====================================================================================
2117 void HOMARD_Gen_i::IsValidStudy( )
2118 //=====================================================================================
2120 MESSAGE( "IsValidStudy" );
2121 if (CORBA::is_nil(myCurrentStudy))
2123 SALOME::ExceptionStruct es;
2124 es.type = SALOME::BAD_PARAM;
2125 es.text = "Invalid Study Context";
2126 throw SALOME::SALOME_Exception(es);
2131 //===========================================================================
2133 // Next functions are inherited from SALOMEDS::Driver interface
2135 //===========================================================================
2137 //===========================================================================
2138 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
2140 CORBA::Boolean isMultiFile)
2142 MESSAGE (" Save pour theURL = "<< theURL);
2143 SALOMEDS::TMPFile_var aStreamFile;
2145 // get temporary directory name
2146 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2148 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2149 StudyContext& context = myContextMap[ aStudy->StudyId() ];
2151 // HOMARD data file name
2152 std::string aFileName = "";
2154 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2155 aFileName += "_HOMARD.dat";
2157 // initialize sequence of file names
2158 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
2159 aFileSeq->length(1);
2160 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
2162 // get full path to the data file
2163 aFileName = tmpDir + aFileName;
2167 std::ofstream f(aFileName.c_str());
2169 // clear temporary id map
2170 context._idmap.clear();
2175 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
2176 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
2177 HOMARD::HOMARD_Cas_var aCas = it_case->second;
2178 PortableServer::ServantBase_var aServant = GetServant(aCas);
2179 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2181 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
2182 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
2186 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2187 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
2188 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
2189 PortableServer::ServantBase_var aServant = GetServant(aZone);
2190 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2192 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
2193 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2196 // -> dump hypotheses
2197 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2198 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
2199 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
2200 PortableServer::ServantBase_var aServant = GetServant(aHypo);
2201 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2203 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
2204 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2207 // -> dump iterations
2208 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2209 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
2210 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
2211 PortableServer::ServantBase_var aServant = GetServant(aIter);
2212 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2214 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
2215 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2218 // -> dump boundaries
2219 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2220 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
2221 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
2222 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2223 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2224 if (aBoundaryServant) {
2225 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
2226 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2230 MESSAGE ("close file");
2233 // put temporary files to the stream
2234 MESSAGE ("put temporary files to the stream");
2235 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
2237 // remove temporary files
2238 MESSAGE ("remove temporary files");
2239 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2241 // return data stream
2242 MESSAGE ("return data stream");
2243 return aStreamFile._retn();
2246 //===========================================================================
2247 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
2249 CORBA::Boolean isMultiFile)
2251 // No specific ASCII persistence
2252 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
2253 return aStreamFile._retn();
2256 //===========================================================================
2257 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
2258 const SALOMEDS::TMPFile& theStream,
2260 CORBA::Boolean isMultiFile)
2262 MESSAGE (" Load pour theURL = "<< theURL);
2263 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2265 // set current study
2266 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
2267 SetCurrentStudy(aStudy);
2269 // get temporary directory name
2270 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2272 // Convert the stream into sequence of files to process
2273 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
2276 // HOMARD data file name
2277 std::string aFileName = "";
2279 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2280 aFileName = tmpDir + aFileName + "_HOMARD.dat";
2282 StudyContext& context = myContextMap[ aStudy->StudyId() ];
2286 std::ifstream f(aFileName.c_str());
2289 context._mesCas.clear();
2290 context._mesHypotheses.clear();
2291 context._mesIterations.clear();
2292 context._mesZones.clear();
2293 context._mesBoundarys.clear();
2294 context._idmap.clear();
2300 std::getline(f, line);
2301 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
2302 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
2303 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
2304 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
2305 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
2306 if (line.substr(0, caseSignature.size()) == caseSignature) {
2308 MESSAGE (" Recreation du cas" );
2309 HOMARD::HOMARD_Cas_var aCase = newCase();
2310 PortableServer::ServantBase_var aServant = GetServant(aCase);
2311 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2312 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
2313 context._mesCas[aCase->GetName()] = aCase;
2314 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
2317 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
2318 MESSAGE (" Recreation de la zone" );
2320 HOMARD::HOMARD_Zone_var aZone = newZone();
2321 PortableServer::ServantBase_var aServant = GetServant(aZone);
2322 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2323 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
2324 context._mesZones[aZone->GetName()] = aZone;
2325 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2328 else if (line.substr(0, iterSignature.size()) == iterSignature) {
2329 // re-create iteration
2330 MESSAGE (" Recreation de l iteration" );
2331 HOMARD::HOMARD_Iteration_var aIter = newIteration();
2332 PortableServer::ServantBase_var aServant = GetServant(aIter);
2333 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2334 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
2335 context._mesIterations[aIter->GetName()] = aIter;
2336 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2339 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
2340 // re-create hypothesis
2341 MESSAGE (" Recreation de l hypothese" );
2342 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
2343 PortableServer::ServantBase_var aServant = GetServant(aHypo);
2344 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2345 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
2346 context._mesHypotheses[aHypo->GetName()] = aHypo;
2347 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2350 else if (line.substr(0, bounSignature.size()) == bounSignature) {
2351 // re-create boundary
2352 MESSAGE (" Recreation de la frontiere" );
2353 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
2354 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2355 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2356 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
2357 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
2358 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2367 // Remove temporary files created from the stream
2369 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2374 //===========================================================================
2375 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
2376 const SALOMEDS::TMPFile& theStream,
2378 CORBA::Boolean isMultiFile)
2380 // No specific ASCII persistence
2381 return Load(theComponent, theStream, theURL, isMultiFile);
2384 //===========================================================================
2385 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
2387 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
2388 // clearing study context should be done here:
2389 // - destroy all servants and related CORBA objects
2391 // - remove context from myContextMap
2392 myContextMap.erase(theComponent->GetStudy()->StudyId());
2393 // - nullify myCurrentStudy
2394 myCurrentStudy = SALOMEDS::Study::_nil();
2398 //===========================================================================
2399 char* HOMARD_Gen_i::ComponentDataType()
2401 return CORBA::string_dup("HOMARD");
2404 //===========================================================================
2405 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
2406 const char* IORString,
2407 CORBA::Boolean isMultiFile,
2408 CORBA::Boolean isASCII)
2410 CORBA::String_var aString("");
2411 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
2412 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2413 CORBA::Object_var anObj = _orb->string_to_object(IORString);
2414 if (!CORBA::is_nil(anObj)) {
2415 PortableServer::ServantBase_var aServant = GetServant(anObj);
2416 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
2418 std::map<int, PortableServer::ServantBase*>::const_iterator it;
2419 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
2420 if (it->second == aStorable) {
2421 std::stringstream os;
2423 aString = CORBA::string_dup(os.str().c_str());
2429 return aString._retn();
2432 //===========================================================================
2433 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
2434 const char* aLocalPersistentID,
2435 CORBA::Boolean isMultiFile,
2436 CORBA::Boolean isASCII)
2438 CORBA::String_var aString("");
2439 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
2440 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2441 int id = atoi(aLocalPersistentID);
2442 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
2443 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
2444 if (!CORBA::is_nil(object)) {
2445 aString = _orb->object_to_string(object);
2449 return aString._retn();
2452 //===========================================================================
2453 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
2455 if(CORBA::is_nil(myCurrentStudy))
2458 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
2459 if(!aCas->_is_nil())
2462 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
2463 if(!aHypo->_is_nil())
2466 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
2467 if(!aZone->_is_nil())
2470 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
2471 if(!aBoundary->_is_nil())
2474 /* Iteration is not published directly
2475 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
2476 if(!aIter->_is_nil())
2482 //===========================================================================
2483 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
2485 // No Copy/Paste support
2489 //===========================================================================
2490 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
2491 CORBA::Long& theObjectID)
2493 // No Copy/Paste support
2494 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
2495 return aStreamFile._retn();
2498 //===========================================================================
2499 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
2500 CORBA::Long theObjectID)
2502 // No Copy/Paste support
2506 //===========================================================================
2507 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
2508 CORBA::Long theObjectID,
2509 SALOMEDS::SObject_ptr theSObject)
2511 // No Copy/Paste support
2512 SALOMEDS::SObject_var aResultSO;
2513 return aResultSO._retn();
2516 //===========================================================================
2517 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
2519 PortableServer::Servant aServant = 0;
2520 if (!CORBA::is_nil(theObject)) {
2522 aServant = _poa->reference_to_servant(theObject);
2530 //===========================================================================
2531 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
2533 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2534 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
2535 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
2536 return aCase._retn();
2539 //===========================================================================
2540 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
2542 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2543 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
2544 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
2545 return aHypo._retn();
2548 //===========================================================================
2549 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
2551 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2552 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
2553 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
2554 return aIter._retn();
2557 //===========================================================================
2558 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
2560 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2561 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
2562 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
2563 return aBoundary._retn();
2565 //===========================================================================
2566 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
2568 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2569 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
2570 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
2571 return aZone._retn();
2573 //==========================================================================
2574 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
2575 CORBA::Boolean isPublished,
2576 CORBA::Boolean isMultiFile,
2577 CORBA::Boolean& isValidScript)
2579 MESSAGE ("Entree dans DumpPython");
2581 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
2582 if(CORBA::is_nil(aStudy))
2583 return new Engines::TMPFile(0);
2585 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
2586 if(CORBA::is_nil(aSO))
2587 return new Engines::TMPFile(0);
2589 std::string aScript = "\"\"\"\n";
2590 aScript += "Python script for HOMARD\n";
2591 aScript += "Copyright EDF-R&D 2010\n";
2592 aScript += "\"\"\"\n";
2593 aScript += "__revision__ = \"V1.2\"\n";
2594 aScript += "import HOMARD\n";
2596 aScript += "import salome\n";
2597 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
2599 aScript += "def RebuildData(theStudy):\n";
2600 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
2603 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
2606 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
2608 aScript += "#\n# Creation of the boundaries";
2609 aScript += "\n# ==========================";
2611 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2612 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
2613 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
2615 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
2616 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
2617 std::string dumpBoundary = dumpCorbaBoundary.in();
2618 aScript+=dumpBoundary;
2622 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
2624 aScript += "#\n# Creation of the zones";
2625 aScript += "\n# =====================";
2627 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2628 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
2629 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
2631 HOMARD::HOMARD_Zone_var maZone = (*it_zone).second;
2632 CORBA::String_var dumpCorbaZone = maZone->GetDumpPython();
2633 std::string dumpZone = dumpCorbaZone.in();
2638 aScript += "#\n# Creation of the hypotheses";
2639 aScript += "\n# ==========================";
2640 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2641 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
2642 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
2644 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
2645 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
2646 std::string dumpHypo = dumpCorbaHypo.in();
2651 aScript += "#\n# Creation of the cases";
2652 aScript += "\n# =====================";
2653 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
2654 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
2655 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
2657 std::string nomCas = (*it_cas).first;
2658 std::string dumpCas = std::string("\n# Creation of the case ") ;
2659 dumpCas += nomCas + std::string("\n");
2660 dumpCas += std::string("\t") + nomCas;
2661 dumpCas += std::string(" = homard.CreateCase('") + nomCas + std::string("', '");
2663 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
2664 CORBA::String_var cIter0= myCase->GetIter0Name();
2665 std::string iter0 = cIter0.in();
2667 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
2668 CORBA::String_var cMesh0= myIteration->GetMeshFile();
2669 std::string mesh0 = cMesh0.in();
2670 CORBA::String_var cMeshName0= myIteration->GetMeshName();
2671 std::string meshName0 = cMeshName0.in();
2672 dumpCas += meshName0 + std::string("', '")+ mesh0 + std::string("')\n");
2673 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
2674 std::string dumpCas2= dumpCorbaCase.in();
2676 aScript+=dumpCas + dumpCas2;
2680 aScript += "#\n# Creation of the iterations" ;
2681 aScript += "\n# ==========================";
2682 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2683 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
2684 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
2686 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
2687 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
2688 std::string dumpIter = dumpCorbaIter.in();
2693 aScript += "\n\tpass";
2696 if( !isMultiFile ) // remove unnecessary tabulation
2697 aScript = RemoveTabulation( aScript );
2699 const size_t aLen = strlen(aScript.c_str());
2700 char* aBuffer = new char[aLen+1];
2701 strcpy(aBuffer, aScript.c_str());
2703 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
2704 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
2706 return aStreamFile._retn();
2710 // Version information
2711 char* HOMARD_Gen_i::getVersion()
2713 #if HOMARD_DEVELOPMENT
2714 return CORBA::string_dup(HOMARD_VERSION_STR"dev");
2716 return CORBA::string_dup(HOMARD_VERSION_STR);
2720 //=============================================================================
2723 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
2724 PortableServer::POA_ptr poa,
2725 PortableServer::ObjectId* contId,
2726 const char* instanceName,
2727 const char* interfaceName)
2729 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
2730 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
2731 return myHOMARD_Gen->getId();