1 // Copyright (C) 2011 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 "utilities.h"
31 #include "Utils_SINGLETON.hxx"
32 #include "Utils_CorbaException.hxx"
33 #include "SALOMEDS_Tool.hxx"
34 #include "SALOME_LifeCycleCORBA.hxx"
35 #include "SALOMEconfig.h"
36 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
37 #include CORBA_CLIENT_HEADER(SMESH_Gen)
53 //=======================================================================
54 //function : RemoveTabulation
56 //=======================================================================
57 std::string RemoveTabulation( std::string theScript )
59 std::string::size_type aPos = 0;
60 while( aPos < theScript.length() )
62 aPos = theScript.find( "\n\t", aPos );
63 if( aPos == std::string::npos )
65 theScript.replace( aPos, 2, "\n" );
71 //=============================================================================
73 * standard constructor
75 //=============================================================================
76 HOMARD_Gen_i::HOMARD_Gen_i( CORBA::ORB_ptr orb,
77 PortableServer::POA_ptr poa,
78 PortableServer::ObjectId * contId,
79 const char *instanceName,
80 const char *interfaceName) :
81 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
83 MESSAGE("constructor");
85 _id = _poa->activate_object(_thisObj);
87 myHomard = new ::HOMARD_Gen();
88 _NS = SINGLETON_<SALOME_NamingService>::Instance();
89 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
93 //=================================
97 //================================
98 HOMARD_Gen_i::~HOMARD_Gen_i()
101 //=============================================================================
103 * Ajoute le composant homard dans l etude si necessaire
105 //=============================================================================
106 void HOMARD_Gen_i::addInStudy(SALOMEDS::Study_ptr theStudy)
108 ASSERT(!CORBA::is_nil(theStudy));
109 MESSAGE("addInStudy: ajout eventuel du composant HOMARD dans current study ID = " << GetCurrentStudyID()) ;
110 SALOMEDS::StudyBuilder_var myBuilder = theStudy->NewBuilder();
112 // Create SComponent labelled 'homard' if it doesn't already exit
113 SALOMEDS::SComponent_var homardFather = theStudy->FindComponent(ComponentDataType());
114 if (CORBA::is_nil(homardFather))
116 myBuilder->NewCommand();
117 MESSAGE("Add Component HOMARD");
119 bool aLocked = theStudy->GetProperties()->IsLocked();
120 if (aLocked) theStudy->GetProperties()->SetLocked(false);
122 homardFather = myBuilder->NewComponent(ComponentDataType());
123 SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
124 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
125 CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
126 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
127 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
128 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
129 if (!Comp->_is_nil())
131 aName->SetValue(ComponentDataType());
134 anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributePixMap");
135 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
136 aPixmap->SetPixMap("HOMARD_2.png");
137 myBuilder->DefineComponentInstance(homardFather, HOMARD_Gen::_this());
139 if (aLocked) theStudy->GetProperties()->SetLocked(true);
140 myBuilder->CommitCommand();
144 //=============================================================================
149 //=============================================================================
150 void HOMARD_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy)
152 MESSAGE("SetCurrentStudy: current study Id = " << GetCurrentStudyID());
153 myCurrentStudy = SALOMEDS::Study::_duplicate(theStudy);
154 this->addInStudy(myCurrentStudy);
157 //=============================================================================
158 SALOMEDS::Study_ptr HOMARD_Gen_i::GetCurrentStudy()
159 //=============================================================================
161 MESSAGE("GetCurrentStudy: study Id = " << GetCurrentStudyID());
162 return SALOMEDS::Study::_duplicate(myCurrentStudy);
165 //=============================================================================
166 int HOMARD_Gen_i::GetCurrentStudyID()
167 //=============================================================================
169 return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId();
172 //=============================================================================
173 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
175 MESSAGE( "AssociateCaseIter : " << nomCas << " ," << nomIter << "," << labelIter );
178 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
179 if (CORBA::is_nil(myCase))
181 SALOME::ExceptionStruct es;
182 es.type = SALOME::BAD_PARAM;
183 es.text = "Invalid Case ";
184 throw SALOME::SALOME_Exception(es);
188 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
189 if (CORBA::is_nil(myIteration))
191 SALOME::ExceptionStruct es;
192 es.type = SALOME::BAD_PARAM;
193 es.text = "Invalid Case ";
194 throw SALOME::SALOME_Exception(es);
198 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
199 SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
200 if (CORBA::is_nil(aCasSO))
202 SALOME::ExceptionStruct es;
203 es.type = SALOME::BAD_PARAM;
204 es.text = "Invalid Case ";
205 throw SALOME::SALOME_Exception(es);
209 aStudyBuilder->NewCommand();
210 SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
211 PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
212 "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
213 aStudyBuilder->CommitCommand();
215 myCase->AddIteration(nomIter);
216 myIteration->SetCaseName(nomCas);
219 //=====================================================================================
220 void HOMARD_Gen_i::SetEtatIter(const char* nomIter, const bool EtatCalcul)
221 //=====================================================================================
223 MESSAGE( "SetEtatIter : nomIter = " << nomIter << " etat " << EtatCalcul );
224 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
225 if (CORBA::is_nil(myIteration))
227 SALOME::ExceptionStruct es;
228 es.type = SALOME::BAD_PARAM;
229 es.text = "Invalid Iteration ";
230 throw SALOME::SALOME_Exception(es);
234 myIteration->SetEtat(EtatCalcul);
236 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
237 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
238 if (CORBA::is_nil(myIteration))
240 SALOME::ExceptionStruct es;
241 es.type = SALOME::BAD_PARAM;
242 es.text = "Invalid Iteration ";
243 throw SALOME::SALOME_Exception(es);
247 int number = myIteration->GetNumber() ;
250 icone = "iter0.png" ;
252 icone = "iter_calculee.png" ;
254 icone = "iter_non_calculee.png" ;
255 PublishInStudyAttr(aStudyBuilder, aIterSO, NULL , NULL, icone, NULL) ;
257 aStudyBuilder->CommitCommand();
260 //=====================================================================================
261 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
262 //=====================================================================================
264 MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName );
265 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
266 if (CORBA::is_nil(myBoundary))
268 SALOME::ExceptionStruct es;
269 es.type = SALOME::BAD_PARAM;
270 es.text = "Invalid Boundary ";
271 throw SALOME::SALOME_Exception(es);
274 SALOME::ExceptionStruct es;
275 es.type = SALOME::BAD_PARAM;
276 es.text = "No change is allowed in boundary. Ask for evolution.";
277 throw SALOME::SALOME_Exception(es);
279 /* HOMARD::listeHypo* maListe = myBoundary->GetHypo();
280 int numberOfHypo = maListe->length();
281 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
283 std::string nomHypo = std::string((*maListe)[NumeHypo]);
284 InvalideHypo(nomHypo.c_str());
287 //=====================================================================================
288 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
289 //=====================================================================================
291 MESSAGE( "InvalideZone : ZoneName = " << ZoneName );
292 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
293 if (CORBA::is_nil(myZone))
295 SALOME::ExceptionStruct es;
296 es.type = SALOME::BAD_PARAM;
297 es.text = "Invalid Zone ";
298 throw SALOME::SALOME_Exception(es);
301 HOMARD::listeHypo* maListe = myZone->GetHypo();
302 int numberOfHypo = maListe->length();
303 for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
305 std::string nomHypo = std::string((*maListe)[NumeHypo]);
306 InvalideHypo(nomHypo.c_str());
309 //=====================================================================================
310 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
311 //=====================================================================================
313 MESSAGE( "InvalideHypo : nomHypo = " << nomHypo );
314 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
315 if (CORBA::is_nil(myHypo))
317 SALOME::ExceptionStruct es;
318 es.type = SALOME::BAD_PARAM;
319 es.text = "Invalid Hypothesis ";
320 throw SALOME::SALOME_Exception(es);
324 HOMARD::listeIters* maListe = myHypo->GetIterations();
325 int numberOfIter = maListe->length();
326 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
328 std::string nomIter = std::string((*maListe)[NumeIter]);
329 InvalideIter(nomIter.c_str());
333 //=====================================================================================
334 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
335 //=====================================================================================
337 MESSAGE("InvalideIter : nomIter = " << nomIter);
338 SetEtatIter(nomIter,false);
339 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
340 if (CORBA::is_nil(myIteration))
342 SALOME::ExceptionStruct es;
343 es.type = SALOME::BAD_PARAM;
344 es.text = "Invalid Iteration ";
345 throw SALOME::SALOME_Exception(es);
349 HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
350 int numberOfIter = maListe->length();
351 for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
353 std::string nomIterFille = std::string((*maListe)[NumeIter]);
354 InvalideIter(nomIterFille.c_str());
357 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
358 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aIterSO);
359 for (; aIter->More(); aIter->Next())
361 SALOMEDS::SObject_var so = aIter->Value();
362 SALOMEDS::GenericAttribute_var anAttr;
363 if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
364 SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
365 std::string value (aCommentAttr->Value());
366 if(value == std::string("HypoHomard")) continue;
367 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
368 aStudyBuilder->RemoveObject(so);
370 const char * nomCas = myIteration->GetCaseName();
371 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
372 if (CORBA::is_nil(myCase))
374 SALOME::ExceptionStruct es;
375 es.type = SALOME::BAD_PARAM;
376 es.text = "Invalid Case Context ";
377 throw SALOME::SALOME_Exception(es);
380 const char* dirParent = myCase->GetDirName();
381 const char* nomDir = myIteration->GetDirName();
382 const char* nomFichier = myIteration->GetMeshFile();
383 std::string commande= "rm -rf " + std::string(dirParent) + "/" + std::string(nomDir);
384 commande = commande + ";rm -rf " + std::string(nomFichier);
385 if ((system(commande.c_str())) != 0)
387 SALOME::ExceptionStruct es;
388 es.type = SALOME::BAD_PARAM;
389 es.text = "Menage du repertoire de calcul impossible" ;
390 throw SALOME::SALOME_Exception(es);
393 // Suppression du maillage publie dans SMESH
394 const char* MeshName = myIteration->GetMeshName();
395 DeleteResultInSmesh(nomFichier, MeshName) ;
398 //=====================================================================================
399 void HOMARD_Gen_i::AssociateHypoZone(const char* ZoneName, const char* nomHypothesis)
401 MESSAGE ( "AssociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
404 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
405 ASSERT(!CORBA::is_nil(myHypo));
406 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
407 ASSERT(!CORBA::is_nil(aHypoSO));
409 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
410 ASSERT(!CORBA::is_nil(myZone));
411 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
412 ASSERT(!CORBA::is_nil(aZoneSO));
413 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
414 aStudyBuilder->NewCommand();
416 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
417 aStudyBuilder->Addreference(aSubSO, aZoneSO);
418 aStudyBuilder->CommitCommand();
420 myZone->AddHypo(nomHypothesis);
421 myHypo->AddZone(ZoneName);
422 MESSAGE ( "Fin de AssociateHypoZone");
425 //=====================================================================================
426 void HOMARD_Gen_i::DissociateHypoZone(const char* ZoneName, const char* nomHypothesis)
428 MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
431 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
432 ASSERT(!CORBA::is_nil(myHypo));
433 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
434 ASSERT(!CORBA::is_nil(aHypoSO));
436 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
437 ASSERT(!CORBA::is_nil(myZone));
438 SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
439 ASSERT(!CORBA::is_nil(aZoneSO));
442 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
444 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator(aHypoSO);
445 for (; it->More(); it->Next())
447 SALOMEDS::SObject_var aHypObj = it->Value();
448 SALOMEDS::SObject_var ptrObj;
449 if (aHypObj->ReferencedObject(ptrObj))
451 if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
453 aStudyBuilder->NewCommand();
454 aStudyBuilder->RemoveObject(aHypObj);
455 aStudyBuilder->CommitCommand();
461 myZone->SupprHypo(nomHypothesis);
462 myHypo->SupprZone(ZoneName);
465 //=============================================================================
466 void HOMARD_Gen_i::AssociateIterIter(const char* nomIterParent, const char* nomIter)
468 MESSAGE ( "AssociateIterIter : nomIter = " << nomIter << " nomIterParent = " << nomIterParent);
471 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
472 ASSERT(!CORBA::is_nil(myIterationParent));
473 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
474 ASSERT(!CORBA::is_nil(myIteration));
476 myIterationParent->AddIteration(nomIter);
477 myIteration->SetIterParent(nomIterParent);
480 //===================================================================================
481 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
483 MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
486 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
487 ASSERT(!CORBA::is_nil(myHypo));
488 SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
489 ASSERT(!CORBA::is_nil(aHypoSO));
491 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
492 ASSERT(!CORBA::is_nil(myIteration));
493 SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
494 ASSERT(!CORBA::is_nil(aIterSO));
496 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
498 aStudyBuilder->NewCommand();
500 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
501 aStudyBuilder->Addreference(aSubSO, aHypoSO);
503 aStudyBuilder->CommitCommand();
505 myIteration->SetHypoName(nomHypo);
506 myHypo->AddIteration(nomIter);
509 //=============================================================================
510 CORBA::Boolean HOMARD_Gen_i::VerifieDir(const char* nomDir)
512 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
513 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
514 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
516 if (std::string(nomDir) == std::string(it->second->GetDirName())) return false;
521 //=============================================================================
522 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
524 MESSAGE ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
527 if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
529 SALOME::ExceptionStruct es;
530 es.type = SALOME::BAD_PARAM;
531 es.text = "This case has already been defined";
532 throw SALOME::SALOME_Exception(es);
536 HOMARD::HOMARD_Cas_var myCase = newCase();
537 myCase->SetName(nomCas);
538 SALOMEDS::SObject_var aSO;
539 PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
540 myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
543 std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile);
544 HOMARD::extrema_var aSeq = new HOMARD::extrema();
545 if (LesExtremes.size()!=10) { return false; }
547 for (int i =0; i< LesExtremes.size(); i++)
548 aSeq[i]=LesExtremes[i];
549 myCase->SetBoundingBox(aSeq);
551 std::set<std::string> LesGroupes =GetListeGroupesInMedFile(MeshFile);
552 HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType;
553 aSeqGroupe->length(LesGroupes.size());
554 std::set<std::string>::const_iterator it;
556 for (it=LesGroupes.begin() ; it != LesGroupes.end(); it++)
557 aSeqGroupe[i++]=(*it).c_str();
558 myCase->SetGroups(aSeqGroupe);
560 // Valeurs par defaut des filtrages
561 myCase->SetNivMax(-1);
562 myCase->SetDiamMin(-1.0);
564 // Recherche d'un nom pour l'iteration 0. Par defaut, on prend le nom
565 // du maillage du cas. Si ce nom existe deja, on incremente avec 0, 1, 2, etc.
567 std::string nomIter = std::string(MeshName) ;
568 while ((myContextMap[GetCurrentStudyID()]._mesIterations).find(nomIter) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()))
570 std::ostringstream nom;
571 nom << MeshName << monNum;
576 HOMARD::HOMARD_Iteration_var anIter = newIteration();
577 myContextMap[GetCurrentStudyID()]._mesIterations[nomIter] = anIter;
578 std::ostringstream DirName;
581 anIter->SetDirName(DirName.str().c_str());
582 anIter->SetName(nomIter.c_str());
583 anIter->SetMeshFile(MeshFile);
584 anIter->SetMeshName(MeshName);
585 anIter->SetNumber(0);
587 AssociateCaseIter (nomCas,nomIter.c_str(),"IterationHomard");
588 SetEtatIter(nomIter.c_str(),true);
590 PublishResultInSmesh(MeshFile, 0);
592 return HOMARD::HOMARD_Cas::_duplicate(myCase);
595 //=============================================================================
596 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCas(const char* nomCas)
599 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
600 if (CORBA::is_nil(myCase))
602 SALOME::ExceptionStruct es;
603 es.type = SALOME::BAD_PARAM;
604 es.text = "Invalid Case";
605 throw SALOME::SALOME_Exception(es);
608 return HOMARD::HOMARD_Cas::_duplicate(myCase);
611 //=============================================================================
612 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
615 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
616 ASSERT(!CORBA::is_nil(myZone));
617 return HOMARD::HOMARD_Zone::_duplicate(myZone);
620 //=============================================================================
621 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
623 MESSAGE ( "GetHypothesis : nomHypothesis = " << nomHypothesis );
625 MESSAGE ( "GetHypothesis : GetCurrentStudyID() = " << GetCurrentStudyID() );
626 HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
627 ASSERT(!CORBA::is_nil(myHypothesis));
628 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
631 //=============================================================================
632 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* nomIteration)
635 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIteration];
636 ASSERT(!CORBA::is_nil(myIteration));
637 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
639 //=============================================================================
640 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
644 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
645 ASSERT(!CORBA::is_nil(myBoundary));
646 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
649 //=============================================================================
650 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
652 MESSAGE ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
655 if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
657 SALOME::ExceptionStruct es;
658 es.type = SALOME::BAD_PARAM;
659 es.text = "This hypothesis is already defined.";
660 throw SALOME::SALOME_Exception(es);
664 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
665 myHypothesis->SetName(nomHypothesis);
666 myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
667 SALOMEDS::SObject_var aSO;
668 PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
670 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
673 //============================================================================================================
674 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* nomIteration, const char* nomIterParent)
675 //============================================================================================================
677 MESSAGE ("CreateIteration : nomIteration = " << nomIteration << "nomIterParent = " << nomIterParent);
680 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
681 if (CORBA::is_nil(myIterationParent))
683 SALOME::ExceptionStruct es;
684 es.type = SALOME::BAD_PARAM;
685 es.text = "The parent iteration is not defined.";
686 throw SALOME::SALOME_Exception(es);
690 const char* nomCas = GetCaseName(nomIterParent);
691 MESSAGE ("CreateIteration : nomCas = " << nomCas);
692 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
693 if (CORBA::is_nil(myCase))
695 SALOME::ExceptionStruct es;
696 es.type = SALOME::BAD_PARAM;
697 es.text = "Invalid Case Context ";
698 throw SALOME::SALOME_Exception(es);
702 if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(nomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
704 SALOME::ExceptionStruct es;
705 es.type = SALOME::BAD_PARAM;
706 es.text = "This iteration is already defined. ";
707 throw SALOME::SALOME_Exception(es);
711 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
712 if (CORBA::is_nil(myIteration))
714 SALOME::ExceptionStruct es;
715 es.type = SALOME::BAD_PARAM;
716 es.text = "Unable to create Iteration ";
717 throw SALOME::SALOME_Exception(es);
720 myContextMap[GetCurrentStudyID()]._mesIterations[std::string(nomIteration)] = myIteration;
721 myIteration->SetName(nomIteration);
722 myIteration->SetMeshName(nomIteration);
724 int numero = myIterationParent->GetNumber() + 1;
725 myIteration->SetNumber(numero);
727 // Nombre d'iterations deja connues pour le cas, permettant
728 // la creation d'un sous-repertoire unique
729 int nbitercase = myCase->GetNumber();
730 std::ostringstream iaux ;
731 iaux << std::setw(2) << std::setfill('0') << nbitercase ;
732 std::stringstream DirName;
733 DirName << "I" << iaux.str();
734 myIteration->SetDirName(DirName.str().c_str());
736 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
737 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
738 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est le
739 // cas le plus frequent.
740 // Si on a plusieurs branches, donc des iterations a meme niveau d'adaptation, utiliser
741 // le nombre d'iterations du cas permet d'eviter les collisions.
742 std::stringstream MeshFile;
743 const char* nomDir = myCase->GetDirName();
744 MeshFile << nomDir << "/maill." << iaux.str() << ".med";
745 myIteration->SetMeshFile(MeshFile.str().c_str());
747 // Association avec le cas et l'iteration precedente
748 std::string label = "IterationHomard_" + std::string(nomIterParent);
749 AssociateCaseIter(nomCas, nomIteration, label.c_str());
750 AssociateIterIter (nomIterParent,nomIteration);
752 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
756 //=============================================================================
757 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
759 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
762 if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
764 SALOME::ExceptionStruct es;
765 es.type = SALOME::BAD_PARAM;
766 es.text = "This boundary has already been defined";
767 throw SALOME::SALOME_Exception(es);
771 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
772 myBoundary->SetName(BoundaryName);
773 myBoundary->SetBoundaryType(BoundaryType);
775 myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
777 SALOMEDS::SObject_var aSO;
778 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
780 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
782 //=============================================================================
783 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
785 MESSAGE ("CreateBoundaryDi : BoundaryName = " << BoundaryName << "MeshName = " << MeshName );
786 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
787 myBoundary->SetMeshFile( MeshFile ) ;
788 myBoundary->SetMeshName( MeshName ) ;
790 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
792 //=============================================================================
793 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
794 double Xcentre, double Ycentre, double Zcentre,
795 double Xaxis, double Yaxis, double Zaxis,
798 MESSAGE ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
799 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
800 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxis, Yaxis, Zaxis, Rayon ) ;
802 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
804 //=============================================================================
805 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
806 double Xcentre, double Ycentre, double Zcentre,
809 MESSAGE ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
810 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
811 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
813 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
817 //=============================================================================
818 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
820 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
823 if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
825 SALOME::ExceptionStruct es;
826 es.type = SALOME::BAD_PARAM;
827 es.text = "This zone has already been defined";
828 throw SALOME::SALOME_Exception(es);
832 HOMARD::HOMARD_Zone_var myZone = newZone();
833 myZone->SetName(ZoneName);
834 myZone->SetZoneType(ZoneType);
836 myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
838 SALOMEDS::SObject_var aSO;
839 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
841 return HOMARD::HOMARD_Zone::_duplicate(myZone);
843 //=============================================================================
844 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
845 double Xmini, double Xmaxi,
846 double Ymini, double Ymaxi,
847 double Zmini, double Zmaxi)
849 MESSAGE ("CreateZoneBox : ZoneName = " << ZoneName ) ;
850 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
851 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
853 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
855 //=============================================================================
856 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
857 double Xcentre, double Ycentre, double Zcentre, double Rayon)
859 MESSAGE ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
860 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
861 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
863 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
865 //=============================================================================
866 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
867 double Xcentre, double Ycentre, double Zcentre,
868 double Xaxe, double Yaxe, double Zaxe,
869 double Rayon, double Haut)
871 MESSAGE ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
872 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
873 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
875 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
877 //=============================================================================
878 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
879 double Xcentre, double Ycentre, double Zcentre,
880 double Xaxe, double Yaxe, double Zaxe,
881 double Rayon, double Haut, double Rayonint)
883 MESSAGE ("CreateZonePipe : ZoneName = " << ZoneName ) ;
884 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
885 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
887 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
889 //=============================================================================
890 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
891 double Umini, double Umaxi,
892 double Vmini, double Vmaxi,
895 MESSAGE ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
896 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
897 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
898 // MESSAGE ("Orient = " << Orient ) ;
900 double Xmini, Xmaxi ;
901 double Ymini, Ymaxi ;
902 double Zmini, Zmaxi ;
910 else if ( Orient == 2 )
917 else if ( Orient == 3 )
924 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
926 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
927 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
929 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
931 //=============================================================================
932 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
933 double Ucentre, double Vcentre,
937 MESSAGE ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
942 { Xcentre = Ucentre ;
945 else if ( Orient == 2 )
948 Zcentre = Vcentre ; }
949 else if ( Orient == 3 )
950 { Xcentre = Vcentre ;
952 Zcentre = Ucentre ; }
953 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
955 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
956 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
958 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
960 //=============================================================================
961 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
962 double Ucentre, double Vcentre,
963 double Rayon, double Rayonint,
966 MESSAGE ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
971 { Xcentre = Ucentre ;
974 else if ( Orient == 2 )
977 Zcentre = Vcentre ; }
978 else if ( Orient == 3 )
979 { Xcentre = Vcentre ;
981 Zcentre = Ucentre ; }
982 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
984 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
985 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
987 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
993 //=============================================================================
994 CORBA::Boolean HOMARD_Gen_i::Compute(const char* nomIteration, CORBA::Long etatMenage)
996 MESSAGE ( "Compute : calcul de " << nomIteration );
999 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIteration];
1000 ASSERT(!CORBA::is_nil(myIteration));
1002 // on ne calcule pas l iteration 0
1003 int NumeIter = myIteration->GetNumber();
1004 if ( NumeIter == 0 )
1006 SALOME::ExceptionStruct es;
1007 es.type = SALOME::BAD_PARAM;
1008 es.text = "This iteration is the first of the case and cannot be computed.";
1009 throw SALOME::SALOME_Exception(es);
1013 // on verifie qu il y a une hypothese (erreur improbable);
1014 const char* nomHypo = myIteration->GetHypoName();
1015 if (std::string(nomHypo) == std::string(""))
1017 SALOME::ExceptionStruct es;
1018 es.type = SALOME::BAD_PARAM;
1019 es.text= "This iteration does not have any associated hypothesis.";
1020 throw SALOME::SALOME_Exception(es);
1023 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
1024 ASSERT(!CORBA::is_nil(myHypo));
1027 // A.4. L'iteration parent
1028 const char* nomIterationParent = myIteration->GetIterParent();
1029 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
1030 ASSERT(!CORBA::is_nil(myIterationParent));
1031 if ( ! myIterationParent->GetEtat() )
1034 SALOME::ExceptionStruct es;
1035 es.type = SALOME::BAD_PARAM;
1036 std::string text = "The iteration cannot be computed because the previous iteration " + std::string(nomIterationParent) + " is not valid.";
1037 es.text = CORBA::string_dup(text.c_str());
1038 throw SALOME::SALOME_Exception(es);
1041 Compute(nomIterationParent, etatMenage);
1044 const char* nomCas = myIteration->GetCaseName();
1045 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1046 ASSERT(!CORBA::is_nil(myCase));
1049 std::stringstream saux0 ;
1050 saux0 << NumeIter - 1 ;
1051 std::string siter = saux0.str() ;
1052 if (NumeIter < 11) { siter = "0" + siter ; }
1054 std::stringstream saux1 ;
1056 std::string siterp1 = saux1.str() ;
1057 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
1059 // A.3. Hypothese associee
1060 // B. Les repertoires
1061 // B.1. Le repertoire du cas
1062 const char* nomDir = myCase->GetDirName();
1063 MESSAGE ( ". nomDir = " << nomDir );
1065 // B.2. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
1066 // B.2.1. Le nom du sous-repertoire
1067 const char* nomDirIt = myIteration->GetDirName();
1069 // B.2.2. Le nom complet du sous-repertoire
1070 std::stringstream DirCompute ;
1071 DirCompute << nomDir << "/" << nomDirIt;
1072 MESSAGE (". DirCompute = " << DirCompute.str() );
1074 // B.2.3. Si le sous-repertoire n'existe pas, on le cree
1075 // Si le sous-repertoire existe :
1076 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
1077 // etatMenage = 1 : on fait le menage du repertoire
1078 if (chdir(DirCompute.str().c_str()) != 0)
1080 // Creation du repertoire car il n'existe pas :
1081 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1083 // GERALD -- QMESSAGE BOX
1084 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
1085 ASSERT("Pb a la creation du repertoire" == 0);
1090 // Le repertoire existe et on fait le menage de son contenu :
1091 if (etatMenage != 0)
1093 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
1094 std::string commande= "rm -rf " + DirCompute.str()+"/*" ;
1095 int codret = system(commande.c_str());
1098 // GERALD -- QMESSAGE BOX
1099 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
1100 ASSERT("Pb au menage du repertoire de calcul" == 0);
1105 // Le repertoire existe et s'il n'est pas vide, on sort en erreur :
1107 struct dirent *dirp;
1108 dp = opendir(DirCompute.str().c_str());
1110 while ((dirp = readdir(dp)) != NULL && result )
1112 std::string file_name(dirp->d_name);
1113 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
1116 if ( result == false)
1118 SALOME::ExceptionStruct es;
1119 es.type = SALOME::BAD_PARAM;
1120 std::string text = "Directory : " + DirCompute.str() + "is not empty";
1121 es.text = CORBA::string_dup(text.c_str());
1122 throw SALOME::SALOME_Exception(es);
1128 // B.3. Le sous-repertoire de l'iteration precedente
1129 const char* nomDirItPa ;
1130 std::stringstream DirComputePa ;
1133 nomDirItPa = nomDirIt;
1134 DirComputePa << DirCompute.str();
1138 nomDirItPa = myIterationParent->GetDirName();
1139 DirComputePa << nomDir << "/" << nomDirItPa;
1141 MESSAGE( ". nomDirItPa = " << nomDirItPa);
1142 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
1144 // B.4. Le fichier des messages
1145 chdir(DirCompute.str().c_str()) ;
1146 std::string MessFile = DirCompute.str() + "/Liste." + siter + ".vers." + siterp1 ;
1147 MESSAGE (". MessFile = " << MessFile);
1148 myIteration->SetMessFile(MessFile.c_str());
1150 // C. On passe dans le repertoire de l'iteration a calculer
1151 chdir(DirCompute.str().c_str()) ;
1153 // D. Les donnees du calcul HOMARD
1154 // D.1. Le type de conformite
1155 int ConfType = myCase->GetConfType();
1156 MESSAGE ( ". ConfType = " << ConfType );
1158 // D.2. Le maillage n
1159 const char* NomMeshParent = myIterationParent->GetMeshName();
1160 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
1161 const char* MeshFileParent = myIterationParent->GetMeshFile();
1162 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
1164 // D.3. Le maillage n+1
1165 const char* NomMesh = myIteration->GetMeshName();
1166 MESSAGE ( ". NomMesh = " << NomMesh );
1167 const char* MeshFile = myIteration->GetMeshFile();
1168 MESSAGE ( ". MeshFile = " << MeshFile );
1169 FILE *file = fopen(MeshFile,"r");
1173 if (etatMenage == 0)
1175 SALOME::ExceptionStruct es;
1176 es.type = SALOME::BAD_PARAM;
1177 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
1178 es.text = CORBA::string_dup(text.c_str());
1179 throw SALOME::SALOME_Exception(es);
1184 std::string commande = "rm -f " + std::string(MeshFile);
1185 codret = system(commande.c_str());
1188 SALOME::ExceptionStruct es;
1189 es.type = SALOME::BAD_PARAM;
1190 std::string text = "PB with meshfile destruction ";
1191 es.text = CORBA::string_dup(text.c_str());
1192 throw SALOME::SALOME_Exception(es);
1203 // D.4. Les types de raffinement et de deraffinement
1204 // Les appels corba sont lourds, il vaut mieux les grouper
1205 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
1206 ASSERT(ListTypes->length() == 3);
1207 int TypeAdap = (*ListTypes)[0];
1208 int TypeRaff = (*ListTypes)[1];
1209 int TypeDera = (*ListTypes)[2];
1211 // D.6. L'option d'interpolation des champs
1212 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
1214 // E. Texte du fichier de configuration
1215 // E.1. Incontournables du texte
1216 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
1217 myDriver->TexteInit(DirCompute.str(), DirComputePa.str(),MessFile);
1218 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
1219 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
1220 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
1222 // E.2. Ajout des informations liees aux zones eventuelles
1225 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
1226 int numberOfZones = ListZone->length();
1228 for (int NumZone = 0; NumZone< numberOfZones; NumZone++)
1230 std::string ZoneName = std::string((*ListZone)[NumZone]);
1231 MESSAGE ( "... ZoneName = " << ZoneName);
1232 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1233 ASSERT(!CORBA::is_nil(myZone));
1235 int ZoneType = myZone->GetZoneType();
1236 MESSAGE ( "... ZoneType = " << ZoneType);
1237 HOMARD::double_array* zone = myZone->GetCoords();
1238 if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
1240 myDriver->TexteZone(NumZone+1, ZoneType, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.);
1242 else if ( ZoneType == 4 ) // Cas d une sphere
1244 myDriver->TexteZone(NumZone+1, ZoneType, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.);
1246 else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
1248 myDriver->TexteZone(NumZone+1, ZoneType, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.);
1250 else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
1252 myDriver->TexteZone(NumZone+1, ZoneType, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]);
1254 else { ASSERT("ZoneType est incorrect." == 0) ; }
1257 // E.3. Ajout des informations liees aux champs eventuels
1260 // Le fichier du champ
1261 char* FieldFile = myIteration->GetFieldFile();
1262 MESSAGE ( ". FieldFile = " << FieldFile );
1263 if (strlen(FieldFile) == 0)
1265 // GERALD -- QMESSAGE BOX
1266 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1267 ASSERT("The file for the field is not given." == 0);
1269 // Les caracteristiques d'instants
1270 int TimeStep = myIteration->GetTimeStep();
1271 MESSAGE( ". TimeStep = " << TimeStep );
1272 int Rank = myIteration->GetRank();
1273 MESSAGE( ". Rank = " << Rank );
1274 // Les informations sur les champ
1275 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
1277 const char* FieldName = aInfosHypo->FieldName;
1279 int TypeThR = aInfosHypo->TypeThR;
1280 double ThreshR = aInfosHypo->ThreshR;
1281 int TypeThC = aInfosHypo->TypeThC;
1282 double ThreshC = aInfosHypo->ThreshC;
1283 // Saut entre mailles ou non ?
1284 int UsField = aInfosHypo->UsField;
1285 MESSAGE( ". UsField = " << UsField );
1286 // L'usage des composantes
1287 int UsCmpI = aInfosHypo->UsCmpI;
1288 MESSAGE( ". UsCmpI = " << UsCmpI );
1290 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
1293 HOMARD::listeComposantsHypo* mescompo = myHypo->GetListComp();
1294 int numberOfCompos = mescompo->length();
1295 MESSAGE( ". numberOfCompos = " << numberOfCompos );
1296 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
1298 std::string nomCompo = std::string((*mescompo)[NumeComp]);
1299 MESSAGE( "... nomCompo = " << nomCompo );
1300 myDriver->TexteCompo(NumeComp, nomCompo);
1303 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
1304 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
1305 int numberOfGroups = listeGroupes->length();
1306 MESSAGE( ". numberOfGroups = " << numberOfGroups );
1307 if (numberOfGroups > 0)
1310 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
1312 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
1313 MESSAGE( "... GroupName = " << GroupName );
1314 myDriver->TexteGroup(GroupName);
1318 // E.5. Ajout des informations liees a l'eventuel suivi de frontiere
1319 // On ecrit d'abord la definition des frontieres, puis les liens avec les groupes
1320 std::list<std::string> ListeBoundaryTraitees ;
1321 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
1322 int numberOfitems = ListBoundaryGroupType->length();
1323 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
1324 int BoundaryOption = 1 ;
1325 int NumBoundaryAnalytical = 0 ;
1326 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1328 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1329 MESSAGE ( "... BoundaryName = " << BoundaryName);
1331 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
1332 while (it != ListeBoundaryTraitees.end())
1334 MESSAGE ( "... BoundaryNameTraitee = " << *it);
1335 if ( BoundaryName == *it ) { A_faire = 0 ; }
1340 // Caracteristiques de la frontiere
1341 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1342 ASSERT(!CORBA::is_nil(myBoundary));
1343 int BoundaryType = myBoundary->GetBoundaryType();
1344 MESSAGE ( "... BoundaryType = " << BoundaryType );
1345 // Ecriture selon le type
1346 if (BoundaryType == 0) // Cas d une frontiere discrete
1348 const char* MeshName = myBoundary->GetMeshName() ;
1349 const char* MeshFile = myBoundary->GetMeshFile() ;
1350 myDriver->TexteBoundaryDi( MeshName, MeshFile);
1351 BoundaryOption = BoundaryOption*2 ;
1353 else // Cas d une frontiere analytique
1355 NumBoundaryAnalytical++ ;
1356 HOMARD::double_array* coor = myBoundary->GetCoords();
1357 if (BoundaryType == 1) // Cas d un cylindre
1359 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6]);
1360 BoundaryOption = BoundaryOption*3 ;
1362 else if (BoundaryType == 2) // Cas d une sphere
1364 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0.);
1365 BoundaryOption = BoundaryOption*3 ;
1368 // Memorisation du traitement
1369 ListeBoundaryTraitees.push_back( BoundaryName );
1372 NumBoundaryAnalytical = 0 ;
1373 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1375 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1376 MESSAGE ( "... BoundaryName = " << BoundaryName);
1377 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1378 ASSERT(!CORBA::is_nil(myBoundary));
1379 int BoundaryType = myBoundary->GetBoundaryType();
1380 MESSAGE ( "... BoundaryType = " << BoundaryType );
1381 // Recuperation du nom du groupe
1382 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
1383 MESSAGE ( "... GroupName = " << GroupName);
1384 if (BoundaryType == 0) // Cas d une frontiere discrete
1386 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
1388 else // Cas d une frontiere analytique
1390 NumBoundaryAnalytical++ ;
1391 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
1394 myDriver->TexteBoundaryOption(BoundaryOption);
1396 // E.6. Ajout des informations liees a l'eventuelle interpolation des champs
1397 MESSAGE( "... TypeFieldInterp = " << TypeFieldInterp );
1398 if (TypeFieldInterp != 0)
1400 // Le fichier des champs
1401 char* FieldFile = myIteration->GetFieldFile();
1402 MESSAGE ( ". FieldFile = " << FieldFile );
1403 if (strlen(FieldFile) == 0)
1405 // GERALD -- QMESSAGE BOX
1406 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1407 ASSERT("The file for the field is not given." == 0);
1409 // Les caracteristiques d'instants
1410 int TimeStep = myIteration->GetTimeStep();
1411 MESSAGE( ". TimeStep = " << TimeStep );
1412 int Rank = myIteration->GetRank();
1413 MESSAGE( ". Rank = " << Rank );
1415 myDriver->TexteFieldInterp(TypeFieldInterp, FieldFile, MeshFile, TimeStep, Rank);
1417 if (TypeFieldInterp == 2)
1419 HOMARD::listFieldInterpHypo* meschamps = myHypo->GetListFieldInterp();
1420 int numberOfFields = meschamps->length();
1421 MESSAGE( ". numberOfFields = " << numberOfFields );
1422 for (int NumeChamp = 0; NumeChamp< numberOfFields; NumeChamp++)
1424 std::string nomChamp = std::string((*meschamps)[NumeChamp]);
1425 MESSAGE( "... nomChamp = " << nomChamp );
1426 myDriver->TexteFieldInterpName(NumeChamp, nomChamp);
1430 // E.7. Ajout des options avancees
1431 int NivMax = myCase->GetNivMax();
1432 MESSAGE ( ". NivMax = " << NivMax );
1435 double DiamMin = myCase->GetDiamMin();
1436 MESSAGE ( ". DiamMin = " << DiamMin );
1437 myDriver->TexteAdvanced(NivMax, DiamMin);
1440 // F. Ecriture du texte dans le fichier
1443 myDriver->CreeFichier();
1448 int codretexec = 1 ;
1451 codretexec = myDriver->ExecuteHomard();
1453 if (codretexec == 0)
1455 SetEtatIter(nomIteration,true);
1459 // GERALD -- QMESSAGE BOX
1460 SetEtatIter(nomIteration,false);
1464 // H. Gestion des resultats
1467 // H.1. Le fichier des messages, dans tous les cas
1468 std::stringstream saux1 ;
1469 saux1 << "Mess " << NumeIter ;
1470 PublishFileUnderIteration(nomIteration, MessFile.c_str(), saux1.str().c_str());
1472 // H.2. Si tout s'est bien passe :
1473 if (codretexec == 0)
1475 // H.2.1. Le fichier de bilan
1476 std::stringstream saux2 ;
1477 saux2 << "Summary " << NumeIter ;
1478 std::string SummaryFile = DirCompute.str() + "/apad." + siterp1 + ".bilan" ;
1479 PublishFileUnderIteration(nomIteration, SummaryFile.c_str(), saux2.str().c_str());
1480 // H.2.2. Le fichier de maillage obtenu
1481 std::stringstream saux0 ;
1482 saux0 <<"Iteration " << NumeIter ;
1483 PublishFileUnderIteration(nomIteration, MeshFile, saux0.str().c_str());
1484 PublishResultInSmesh(MeshFile, 1);
1486 // H.3 Message d'erreur en cas de probleme
1489 SALOME::ExceptionStruct es;
1490 es.type = SALOME::BAD_PARAM;
1491 std::string text = "Error during the adaptation.\n" ;
1494 ifstream fichier(MessFile.c_str(), ios::in);
1496 while(getline(fichier, ligne) and (ligne != "===== HOMARD ===== STOP ====="));
1497 while (getline(fichier, ligne)) { text += ligne+ "\n";};
1500 text += "no log file ....";
1502 es.text = CORBA::string_dup(text.c_str());
1503 throw SALOME::SALOME_Exception(es);
1513 if (codret == 0) { return true; }
1514 else { return false; }
1517 //===========================================================================
1518 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
1519 SALOMEDS::SObject_ptr theSObject,
1520 CORBA::Object_ptr theObject,
1521 const char* theName)
1523 MESSAGE("PublishInStudy pour " << theName);
1524 SALOMEDS::SObject_var aResultSO;
1525 if (CORBA::is_nil(theStudy))
1527 SALOME::ExceptionStruct es;
1528 es.type = SALOME::BAD_PARAM;
1529 es.text = "Invalid Study Context ";
1530 throw SALOME::SALOME_Exception(es);
1534 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
1535 // Rq : Iteration est publiee ailleurs
1536 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
1537 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
1538 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
1539 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
1541 addInStudy(theStudy);
1543 // Controle de la non publication d'un objet de meme nom
1544 if ((!aHypo->_is_nil()) or (!aZone->_is_nil()) or (!aBoundary->_is_nil()))
1546 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
1547 if (listSO->length() >= 1)
1549 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
1550 std::cerr <<"This name "<<theName<<" is already used "<<listSO->length()<<" time(s)" << std::endl;
1551 aResultSO = listSO[0];
1552 return aResultSO._retn();
1556 // Caracteristiques de l'etude
1557 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1558 aStudyBuilder->NewCommand();
1559 if(!aCase->_is_nil())
1560 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
1561 else if(!aHypo->_is_nil())
1562 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
1563 else if(!aZone->_is_nil())
1564 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
1565 else if(!aBoundary->_is_nil())
1566 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
1568 aStudyBuilder->CommitCommand();
1569 return aResultSO._retn();
1571 //=============================================================================
1572 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
1573 SALOMEDS::StudyBuilder_var aStudyBuilder,
1574 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
1576 MESSAGE("PublishCaseInStudy pour "<<theName);
1577 SALOMEDS::SObject_var aResultSO;
1578 SALOMEDS::GenericAttribute_var anAttr;
1580 if (CORBA::is_nil(theObject)) {
1581 MESSAGE("HOMARD_Gen_i.cxx::theObject->_is_nil()");
1582 return aResultSO._retn();
1584 if (theStudy->_is_nil()) {
1585 MESSAGE("HOMARD_Gen_i.cxx::theStudy->_is_nil()");
1586 return aResultSO._retn();
1589 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1590 if (theFatherHomard->_is_nil())
1592 MESSAGE("theFatherHomard->_is_nil()");
1593 return aResultSO._retn();
1596 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
1597 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
1598 _orb->object_to_string(theObject) ) ;
1599 return aResultSO._retn();
1602 //=============================================================================
1603 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
1604 SALOMEDS::StudyBuilder_var aStudyBuilder,
1605 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
1607 MESSAGE("PublishZoneStudy pour "<<theName);
1608 SALOMEDS::SObject_var aResultSO;
1609 SALOMEDS::GenericAttribute_var anAttr;
1611 if (CORBA::is_nil(theObject))
1613 MESSAGE("HOMARD_Gen_i.cxx::theObject->_is_nil()");
1614 return aResultSO._retn();
1616 if (theStudy->_is_nil())
1618 MESSAGE("HOMARD_Gen_i.cxx::theStudy->_is_nil()");
1619 return aResultSO._retn();
1621 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1622 if (theFatherHomard->_is_nil())
1624 MESSAGE("theFatherHomard->_is_nil()");
1625 return aResultSO._retn();
1628 // Caracteristique de la zone
1629 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
1630 CORBA::Long ZoneType = myZone->GetZoneType();
1632 // On ajoute la categorie des zones dans l etude si necessaire
1633 SALOMEDS::SObject_var aSOZone;
1634 if (!theFatherHomard->FindSubObject(100, aSOZone))
1636 MESSAGE("Ajout de la categorie des zones");
1637 aSOZone = aStudyBuilder->NewObjectToTag(theFatherHomard, 100);
1638 PublishInStudyAttr(aStudyBuilder, aSOZone, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
1640 else { MESSAGE("La categorie des zones existe deja."); }
1642 aResultSO = aStudyBuilder->NewObject(aSOZone);
1651 { icone = "boxdxy_2.png" ;
1655 { icone = "boxdxyz_2.png" ;
1663 { icone = "disk_2.png" ;
1667 { icone = "spherepoint_2.png" ;
1671 { icone = "cylinderpointvector_2.png" ;
1679 { icone = "diskwithhole_2.png" ;
1683 { icone = "pipe_2.png" ;
1687 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone, _orb->object_to_string(theObject) ) ;
1689 return aResultSO._retn();
1691 //=============================================================================
1692 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
1693 SALOMEDS::StudyBuilder_var aStudyBuilder,
1694 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
1696 MESSAGE("PublishBoundaryStudy pour "<<theName);
1697 SALOMEDS::SObject_var aResultSO;
1698 SALOMEDS::GenericAttribute_var anAttr;
1700 // Caracteristique de la Boundary
1701 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
1703 // On recupere le module pere dans l etude
1704 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1705 if (theFatherHomard->_is_nil())
1707 MESSAGE("theFatherHomard->_is_nil()");
1708 return aResultSO._retn();
1711 // On ajoute la categorie des boundarys dans l etude si necessaire
1712 SALOMEDS::SObject_var aSOBoundary;
1713 if (!theFatherHomard->FindSubObject(101, aSOBoundary))
1715 MESSAGE("Ajout de la categorie des boundarys");
1716 aSOBoundary = aStudyBuilder->NewObjectToTag(theFatherHomard, 101);
1717 PublishInStudyAttr(aStudyBuilder, aSOBoundary, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
1719 else { MESSAGE("La categorie des boundarys existe deja."); }
1721 aResultSO = aStudyBuilder->NewObject(aSOBoundary);
1722 CORBA::Long BoundaryType = myBoundary->GetBoundaryType();
1723 // MESSAGE("BoundaryType : "<<BoundaryType);
1726 switch (BoundaryType)
1729 { value = "BoundaryDiHomard" ;
1730 icone = "mesh_tree_mesh.png" ;
1734 { value = "BoundaryAnHomard" ;
1735 icone = "cylinderpointvector_2.png" ;
1739 { value = "BoundaryAnHomard" ;
1740 icone = "spherepoint_2.png" ;
1744 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value, icone, _orb->object_to_string(theObject));
1745 return aResultSO._retn();
1748 //=============================================================================
1749 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
1750 SALOMEDS::StudyBuilder_var aStudyBuilder,
1751 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
1753 MESSAGE("PublishHypotheseInStudy pour "<<theName);
1754 SALOMEDS::SObject_var aResultSO;
1755 SALOMEDS::GenericAttribute_var anAttr;
1757 // On recupere le module pere dans l etude
1758 // On ajoute la categorie des hypotheses dans l etude si necessaire
1759 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1760 if (theFatherHomard->_is_nil())
1762 MESSAGE("theFatherHomard->_is_nil()");
1763 return aResultSO._retn();
1765 SALOMEDS::SObject_var aSOHypothese;
1766 if (!theFatherHomard->FindSubObject(0, aSOHypothese))
1768 MESSAGE("Ajout de la categorie des hypotheses");
1769 aSOHypothese = aStudyBuilder->NewObjectToTag(theFatherHomard, 0);
1770 PublishInStudyAttr(aStudyBuilder, aSOHypothese, "Hypothesis", "HypoList","hypotheses.png", NULL);
1772 else { MESSAGE("La categorie des hypotheses existe deja."); }
1774 // Creation du resultat dans l'etude
1775 aResultSO = aStudyBuilder->NewObject(aSOHypothese);
1776 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
1778 return aResultSO._retn();
1780 //===========================================================================
1781 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
1782 SALOMEDS::SObject_var aResultSO,
1783 const char* name, const char* value, const char* icone, const char* ior)
1785 SALOMEDS::GenericAttribute_var anAttr ;
1789 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
1790 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
1791 aNameAttrib->SetValue(name);
1794 // Ajout du commentaire
1795 if ( value != NULL )
1797 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
1798 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
1799 aCommentAttrib->SetValue(value);
1803 if ( icone != NULL )
1805 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO,"AttributePixMap");
1806 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
1807 aPixmap->SetPixMap(icone);
1813 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
1814 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1815 anIOR->SetValue(ior);
1819 //=============================================================================
1820 HOMARD::listeCases* HOMARD_Gen_i::GetAllCases()
1822 MESSAGE("GetAllCases");
1825 HOMARD::listeCases_var ret = new HOMARD::listeCases;
1826 ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
1827 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
1829 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
1830 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
1832 ret[i++] = CORBA::string_dup((*it).first.c_str());
1838 //=============================================================================
1839 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypotheses()
1841 MESSAGE("GetAllHypotheses");
1844 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
1845 ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
1846 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
1848 for (it = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
1849 it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
1851 ret[i++] = CORBA::string_dup((*it).first.c_str());
1857 //=============================================================================
1858 HOMARD::listeZones* HOMARD_Gen_i::GetAllZones()
1860 MESSAGE("GetAllZones");
1863 HOMARD::listeZones_var ret = new HOMARD::listeZones;
1864 ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
1865 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
1867 for (it = myContextMap[GetCurrentStudyID()]._mesZones.begin();
1868 it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
1870 ret[i++] = CORBA::string_dup((*it).first.c_str());
1876 //=============================================================================
1877 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterations()
1879 MESSAGE("GetAllIterations");
1882 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
1883 ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
1884 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
1886 for (it = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
1887 it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
1889 ret[i++] = CORBA::string_dup((*it).first.c_str());
1894 //=============================================================================
1895 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarys()
1897 MESSAGE("GetAllBoundarys");
1900 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
1901 ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
1902 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
1904 for (it = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
1905 it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
1907 ret[i++] = CORBA::string_dup((*it).first.c_str());
1913 //=============================================================================
1914 char* HOMARD_Gen_i::GetCaseName(const char* nomIteration)
1916 if (CORBA::is_nil(myCurrentStudy))
1918 SALOME::ExceptionStruct es;
1919 es.type = SALOME::BAD_PARAM;
1920 es.text = "Invalid Study Context ";
1921 throw SALOME::SALOME_Exception(es);
1925 HOMARD::HOMARD_Iteration_var monIter = myContextMap[GetCurrentStudyID()]._mesIterations[nomIteration];
1926 ASSERT(!CORBA::is_nil(monIter));
1927 return CORBA::string_dup(monIter->GetCaseName());
1929 //=============================================================================
1930 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long IconeType)
1932 MESSAGE( "PublishResultInSmesh " << NomFich);
1933 if (CORBA::is_nil(myCurrentStudy))
1935 SALOME::ExceptionStruct es;
1936 es.type = SALOME::BAD_PARAM;
1937 es.text = "Invalid Study Context ";
1938 throw SALOME::SALOME_Exception(es);
1942 // Le module SMESH est-il actif ?
1943 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
1945 if (!CORBA::is_nil(aSmeshSO))
1947 // On verifie que le fichier n est pas deja publie
1948 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
1949 for (; aIter->More(); aIter->Next())
1951 SALOMEDS::SObject_var aSO = aIter->Value();
1952 SALOMEDS::GenericAttribute_var aGAttr;
1953 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
1955 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
1956 CORBA::String_var value=anAttr->Value();
1957 if (strcmp((const char*)value,NomFich) == 0)
1959 // GERALD -- QMESSAGE BOX
1960 std::cerr << "fichier : "<< NomFich << " deja publie "<< std::endl;
1968 // On enregistre le fichier
1969 MESSAGE( "Enregistrement du fichier");
1970 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
1971 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
1972 ASSERT(!CORBA::is_nil(aSmeshEngine));
1973 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
1974 SMESH::DriverMED_ReadStatus theStatus;
1975 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
1977 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
1978 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
1979 for (int i = 0; i < mesMaillages->length(); i++)
1981 MESSAGE( ". Mise a jour des attributs du maillage");
1982 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
1983 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
1984 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1985 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
1986 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
1987 anAttr->SetValue(NomFich);
1988 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
1989 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
1990 // IconeType = 0 : fichier issu d'une importation
1991 // IconeType = 1 : fichier issu d'une execution HOMARD
1993 if ( IconeType == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
1994 else { icone = "mesh_tree_mesh.png" ; }
1995 anAttr2->SetPixMap( icone );
1999 //=============================================================================
2000 void HOMARD_Gen_i::DeleteResultInSmesh(const char* NomFich, const char* MeshName)
2002 MESSAGE (" DeleteResultInSmesh pour "<< NomFich << "et le maillage "<< MeshName);
2003 if (CORBA::is_nil(myCurrentStudy))
2005 SALOME::ExceptionStruct es;
2006 es.type = SALOME::BAD_PARAM;
2007 es.text = "Invalid Study Context ";
2008 throw SALOME::SALOME_Exception(es);
2012 // Le module SMESH est-il actif ?
2013 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
2015 if (CORBA::is_nil(aSmeshSO))
2019 // On verifie que le fichier est deja publie
2020 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
2021 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
2022 for (; aIter->More(); aIter->Next())
2024 SALOMEDS::SObject_var aSO = aIter->Value();
2025 SALOMEDS::GenericAttribute_var aGAttr;
2026 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
2028 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2029 CORBA::String_var value=anAttr->Value();
2030 if (strcmp((const char*)value,NomFich) == 0)
2032 if (aSO->FindAttribute(aGAttr,"AttributeName"))
2034 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
2035 CORBA::String_var value2=anAttr2->Value();
2036 if (strcmp((const char*)value2,MeshName) == 0)
2038 myBuilder->RemoveObjectWithChildren( aSO ) ;
2046 //=============================================================================
2047 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
2049 if (CORBA::is_nil(myCurrentStudy))
2051 SALOME::ExceptionStruct es;
2052 es.type = SALOME::BAD_PARAM;
2053 es.text = "Invalid Study Context ";
2054 throw SALOME::SALOME_Exception(es);
2058 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
2059 if (CORBA::is_nil(myIteration))
2061 SALOME::ExceptionStruct es;
2062 es.type = SALOME::BAD_PARAM;
2063 es.text = "Invalid Iteration ";
2064 throw SALOME::SALOME_Exception(es);
2067 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
2068 if (CORBA::is_nil(myIteration))
2070 SALOME::ExceptionStruct es;
2071 es.type = SALOME::BAD_PARAM;
2072 es.text = "Invalid Iteration Study Object";
2073 throw SALOME::SALOME_Exception(es);
2077 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2079 aStudyBuilder->NewCommand();
2081 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
2082 // Pour les fichiers med, on affiche une icone de maillage
2083 // Pour les fichiers qui sont texte, on affiche une icone de fichier texte 'texte'
2084 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
2086 const char* ior = " " ;
2087 if ( Commentaire[0] == 'I' )
2088 { icone = "med.png" ; }
2090 { icone = "texte_2.png" ; }
2091 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone, ior ) ;
2093 aStudyBuilder->CommitCommand();
2096 //=====================================================================================
2097 void HOMARD_Gen_i::IsValidStudy( )
2098 //=====================================================================================
2100 MESSAGE( "IsValidStudy" );
2101 if (CORBA::is_nil(myCurrentStudy))
2103 SALOME::ExceptionStruct es;
2104 es.type = SALOME::BAD_PARAM;
2105 es.text = "Invalid Study Context";
2106 throw SALOME::SALOME_Exception(es);
2111 //===========================================================================
2113 // Next functions are inherited from SALOMEDS::Driver interface
2115 //===========================================================================
2117 //===========================================================================
2118 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
2122 MESSAGE (" Save pour theURL = "<< theURL);
2123 SALOMEDS::TMPFile_var aStreamFile;
2125 // get temporary directory name
2126 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2128 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2129 StudyContext& context = myContextMap[ aStudy->StudyId() ];
2131 // HOMARD data file name
2132 std::string aFileName = "";
2134 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2135 aFileName += "_HOMARD.dat";
2137 // initialize sequence of file names
2138 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
2139 aFileSeq->length(1);
2140 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
2142 // get full path to the data file
2143 aFileName = tmpDir + aFileName;
2147 std::ofstream f(aFileName.c_str());
2149 // clear temporary id map
2150 context._idmap.clear();
2155 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
2156 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
2157 HOMARD::HOMARD_Cas_var aCas = it_case->second;
2158 PortableServer::ServantBase_var aServant = GetServant(aCas);
2159 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2161 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
2162 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
2166 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2167 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
2168 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
2169 PortableServer::ServantBase_var aServant = GetServant(aZone);
2170 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2172 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
2173 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2176 // -> dump hypotheses
2177 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2178 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
2179 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
2180 PortableServer::ServantBase_var aServant = GetServant(aHypo);
2181 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2183 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
2184 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2187 // -> dump iterations
2188 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2189 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
2190 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
2191 PortableServer::ServantBase_var aServant = GetServant(aIter);
2192 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2194 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
2195 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2198 // -> dump boundaries
2199 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2200 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
2201 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
2202 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2203 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2204 if (aBoundaryServant) {
2205 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
2206 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2210 MESSAGE ("close file");
2213 // put temporary files to the stream
2214 MESSAGE ("put temporary files to the stream");
2215 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
2217 // remove temporary files
2218 MESSAGE ("remove temporary files");
2219 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2221 // return data stream
2222 MESSAGE ("return data stream");
2223 return aStreamFile._retn();
2226 //===========================================================================
2227 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
2231 // No specific ASCII persistence
2232 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
2233 return aStreamFile._retn();
2236 //===========================================================================
2237 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
2238 const SALOMEDS::TMPFile& theStream,
2242 MESSAGE (" Load pour theURL = "<< theURL);
2243 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2245 // set current study
2246 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
2247 SetCurrentStudy(aStudy);
2249 // get temporary directory name
2250 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2252 // Convert the stream into sequence of files to process
2253 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
2256 // HOMARD data file name
2257 std::string aFileName = "";
2259 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2260 aFileName = tmpDir + aFileName + "_HOMARD.dat";
2262 StudyContext& context = myContextMap[ aStudy->StudyId() ];
2266 std::ifstream f(aFileName.c_str());
2269 context._mesCas.clear();
2270 context._mesHypotheses.clear();
2271 context._mesIterations.clear();
2272 context._mesZones.clear();
2273 context._mesBoundarys.clear();
2274 context._idmap.clear();
2280 std::getline(f, line);
2281 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
2282 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
2283 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
2284 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
2285 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
2286 if (line.substr(0, caseSignature.size()) == caseSignature) {
2288 MESSAGE (" Recreation du cas" );
2289 HOMARD::HOMARD_Cas_var aCase = newCase();
2290 PortableServer::ServantBase_var aServant = GetServant(aCase);
2291 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2292 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
2293 context._mesCas[aCase->GetName()] = aCase;
2294 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
2297 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
2298 MESSAGE (" Recreation de la zone" );
2300 HOMARD::HOMARD_Zone_var aZone = newZone();
2301 PortableServer::ServantBase_var aServant = GetServant(aZone);
2302 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2303 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
2304 context._mesZones[aZone->GetName()] = aZone;
2305 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2308 else if (line.substr(0, iterSignature.size()) == iterSignature) {
2309 // re-create iteration
2310 MESSAGE (" Recreation de l iteration" );
2311 HOMARD::HOMARD_Iteration_var aIter = newIteration();
2312 PortableServer::ServantBase_var aServant = GetServant(aIter);
2313 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2314 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
2315 context._mesIterations[aIter->GetName()] = aIter;
2316 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2319 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
2320 // re-create hypothesis
2321 MESSAGE (" Recreation de l hypothese" );
2322 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
2323 PortableServer::ServantBase_var aServant = GetServant(aHypo);
2324 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2325 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
2326 context._mesHypotheses[aHypo->GetName()] = aHypo;
2327 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2330 else if (line.substr(0, bounSignature.size()) == bounSignature) {
2331 // re-create boundary
2332 MESSAGE (" Recreation de la frontiere" );
2333 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
2334 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2335 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2336 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
2337 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
2338 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2347 // Remove temporary files created from the stream
2349 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2354 //===========================================================================
2355 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
2356 const SALOMEDS::TMPFile& theStream,
2360 // No specific ASCII persistence
2361 return Load(theComponent, theStream, theURL, isMultiFile);
2364 //===========================================================================
2365 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
2367 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
2368 // clearing study context should be done here:
2369 // - destroy all servants and related CORBA objects
2371 // - remove context from myContextMap
2372 myContextMap.erase(theComponent->GetStudy()->StudyId());
2373 // - nullify myCurrentStudy
2374 myCurrentStudy = SALOMEDS::Study::_nil();
2378 //===========================================================================
2379 char* HOMARD_Gen_i::ComponentDataType()
2381 return CORBA::string_dup("HOMARD");
2384 //===========================================================================
2385 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
2386 const char* IORString,
2387 CORBA::Boolean isMultiFile,
2388 CORBA::Boolean isASCII)
2390 CORBA::String_var aString("");
2391 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
2392 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2393 CORBA::Object_var anObj = _orb->string_to_object(IORString);
2394 if (!CORBA::is_nil(anObj)) {
2395 PortableServer::ServantBase_var aServant = GetServant(anObj);
2396 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
2398 std::map<int, PortableServer::ServantBase*>::const_iterator it;
2399 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
2400 if (it->second == aStorable) {
2401 std::stringstream os;
2403 aString = CORBA::string_dup(os.str().c_str());
2409 return aString._retn();
2412 //===========================================================================
2413 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
2414 const char* aLocalPersistentID,
2415 CORBA::Boolean isMultiFile,
2416 CORBA::Boolean isASCII)
2418 CORBA::String_var aString("");
2419 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
2420 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2421 int id = atoi(aLocalPersistentID);
2422 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
2423 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
2424 if (!CORBA::is_nil(object)) {
2425 aString = _orb->object_to_string(object);
2429 return aString._retn();
2432 //===========================================================================
2433 bool HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
2435 if(CORBA::is_nil(myCurrentStudy))
2438 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
2439 if(!aCas->_is_nil())
2442 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
2443 if(!aHypo->_is_nil())
2446 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
2447 if(!aZone->_is_nil())
2450 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
2451 if(!aBoundary->_is_nil())
2454 /* Iteration is not published directly
2455 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
2456 if(!aIter->_is_nil())
2462 //===========================================================================
2463 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
2465 // No Copy/Paste support
2469 //===========================================================================
2470 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
2471 CORBA::Long& theObjectID)
2473 // No Copy/Paste support
2474 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
2475 return aStreamFile._retn();
2478 //===========================================================================
2479 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
2480 CORBA::Long theObjectID)
2482 // No Copy/Paste support
2486 //===========================================================================
2487 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
2488 CORBA::Long theObjectID,
2489 SALOMEDS::SObject_ptr theSObject)
2491 // No Copy/Paste support
2492 SALOMEDS::SObject_var aResultSO;
2493 return aResultSO._retn();
2496 //===========================================================================
2497 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
2499 PortableServer::Servant aServant = 0;
2500 if (!CORBA::is_nil(theObject)) {
2502 aServant = _poa->reference_to_servant(theObject);
2510 //===========================================================================
2511 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
2513 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2514 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
2515 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
2516 return aCase._retn();
2519 //===========================================================================
2520 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
2522 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2523 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
2524 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
2525 return aHypo._retn();
2528 //===========================================================================
2529 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
2531 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2532 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
2533 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
2534 return aIter._retn();
2537 //===========================================================================
2538 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
2540 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2541 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
2542 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
2543 return aBoundary._retn();
2545 //===========================================================================
2546 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
2548 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2549 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
2550 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
2551 return aZone._retn();
2553 //==========================================================================
2554 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
2555 CORBA::Boolean isPublished,
2556 CORBA::Boolean isMultiFile,
2557 CORBA::Boolean& isValidScript)
2559 MESSAGE ("Entree dans DumpPython");
2561 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
2562 if(CORBA::is_nil(aStudy))
2563 return new Engines::TMPFile(0);
2565 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
2566 if(CORBA::is_nil(aSO))
2567 return new Engines::TMPFile(0);
2569 std::string aScript = "\"\"\"\n";
2570 aScript += "Python script for HOMARD\n";
2571 aScript += "Copyright EDF-R&D 2010\n";
2572 aScript += "\"\"\"\n";
2573 aScript += "__revision__ = \"V1.2\"\n";
2574 aScript += "import HOMARD\n";
2576 aScript += "import salome\n";
2577 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
2579 aScript += "def RebuildData(theStudy):\n";
2580 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
2583 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
2586 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
2588 aScript += "#\n# Creation of the boundaries";
2589 aScript += "\n# ==========================";
2591 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2592 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
2593 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
2595 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
2596 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
2597 std::string dumpBoundary = dumpCorbaBoundary.in();
2598 aScript+=dumpBoundary;
2602 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
2604 aScript += "#\n# Creation of the zones";
2605 aScript += "\n# =====================";
2607 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2608 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
2609 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
2611 HOMARD::HOMARD_Zone_var maZone = (*it_zone).second;
2612 CORBA::String_var dumpCorbaZone = maZone->GetDumpPython();
2613 std::string dumpZone = dumpCorbaZone.in();
2618 aScript += "#\n# Creation of the hypotheses";
2619 aScript += "\n# ==========================";
2620 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2621 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
2622 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
2624 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
2625 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
2626 std::string dumpHypo = dumpCorbaHypo.in();
2631 aScript += "#\n# Creation of the cases";
2632 aScript += "\n# =====================";
2633 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
2634 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
2635 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
2637 std::string nomCas = (*it_cas).first;
2638 std::string dumpCas = std::string("\n# Creation of the case ") ;
2639 dumpCas += nomCas + std::string("\n");
2640 dumpCas += std::string("\t") + nomCas;
2641 dumpCas += std::string(" = homard.CreateCase('") + nomCas + std::string("', '");
2643 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
2644 CORBA::String_var cIter0= myCase->GetIter0Name();
2645 std::string iter0 = cIter0.in();
2647 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
2648 CORBA::String_var cMesh0= myIteration->GetMeshFile();
2649 std::string mesh0 = cMesh0.in();
2650 CORBA::String_var cMeshName0= myIteration->GetMeshName();
2651 std::string meshName0 = cMeshName0.in();
2652 dumpCas += meshName0 + std::string("', '")+ mesh0 + std::string("')\n");
2653 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
2654 std::string dumpCas2= dumpCorbaCase.in();
2656 aScript+=dumpCas + dumpCas2;
2660 aScript += "#\n# Creation of the iterations" ;
2661 aScript += "\n# ==========================";
2662 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2663 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
2664 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
2666 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
2667 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
2668 std::string dumpIter = dumpCorbaIter.in();
2673 aScript += "\n\tpass";
2676 if( !isMultiFile ) // remove unnecessary tabulation
2677 aScript = RemoveTabulation( aScript );
2679 const size_t aLen = strlen(aScript.c_str());
2680 char* aBuffer = new char[aLen+1];
2681 strcpy(aBuffer, aScript.c_str());
2683 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
2684 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
2686 return aStreamFile._retn();
2689 //=============================================================================
2692 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
2693 PortableServer::POA_ptr poa,
2694 PortableServer::ObjectId* contId,
2695 const char* instanceName,
2696 const char* interfaceName)
2698 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
2699 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
2700 return myHOMARD_Gen->getId();