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 CORBA::Long 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 CORBA::Boolean 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 // Recherche d'un nom pour l'iteration 0. Par defaut, on prend le nom
561 // du maillage du cas. Si ce nom existe deja, on incremente avec 0, 1, 2, etc.
563 std::string nomIter = std::string(MeshName) ;
564 while ((myContextMap[GetCurrentStudyID()]._mesIterations).find(nomIter) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()))
566 std::ostringstream nom;
567 nom << MeshName << monNum;
572 HOMARD::HOMARD_Iteration_var anIter = newIteration();
573 myContextMap[GetCurrentStudyID()]._mesIterations[nomIter] = anIter;
574 std::ostringstream DirName;
577 anIter->SetDirName(DirName.str().c_str());
578 anIter->SetName(nomIter.c_str());
579 anIter->SetMeshFile(MeshFile);
580 anIter->SetMeshName(MeshName);
581 anIter->SetNumber(0);
583 AssociateCaseIter (nomCas,nomIter.c_str(),"IterationHomard");
584 SetEtatIter(nomIter.c_str(),true);
586 PublishResultInSmesh(MeshFile, 0);
588 return HOMARD::HOMARD_Cas::_duplicate(myCase);
591 //=============================================================================
592 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCas(const char* nomCas)
595 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
596 if (CORBA::is_nil(myCase))
598 SALOME::ExceptionStruct es;
599 es.type = SALOME::BAD_PARAM;
600 es.text = "Invalid Case";
601 throw SALOME::SALOME_Exception(es);
604 return HOMARD::HOMARD_Cas::_duplicate(myCase);
607 //=============================================================================
608 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
611 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
612 ASSERT(!CORBA::is_nil(myZone));
613 return HOMARD::HOMARD_Zone::_duplicate(myZone);
616 //=============================================================================
617 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
619 MESSAGE ( "GetHypothesis : nomHypothesis = " << nomHypothesis );
621 MESSAGE ( "GetHypothesis : GetCurrentStudyID() = " << GetCurrentStudyID() );
622 HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
623 ASSERT(!CORBA::is_nil(myHypothesis));
624 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
627 //=============================================================================
628 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* nomIteration)
631 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIteration];
632 ASSERT(!CORBA::is_nil(myIteration));
633 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
635 //=============================================================================
636 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
640 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
641 ASSERT(!CORBA::is_nil(myBoundary));
642 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
645 //=============================================================================
646 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
648 MESSAGE ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
651 if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
653 SALOME::ExceptionStruct es;
654 es.type = SALOME::BAD_PARAM;
655 es.text = "This hypothesis is already defined.";
656 throw SALOME::SALOME_Exception(es);
660 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
661 myHypothesis->SetName(nomHypothesis);
662 myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
663 SALOMEDS::SObject_var aSO;
664 PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
666 // Valeurs par defaut des filtrages
667 myHypothesis->SetNivMax(-1);
668 myHypothesis->SetDiamMin(-1.0);
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 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
795 CORBA::Double Xaxis, CORBA::Double Yaxis, CORBA::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 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::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 CORBA::Double Xmini, CORBA::Double Xmaxi,
846 CORBA::Double Ymini, CORBA::Double Ymaxi,
847 CORBA::Double Zmini, CORBA::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 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::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 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
868 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
869 CORBA::Double Rayon, CORBA::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 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
880 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
881 CORBA::Double Rayon, CORBA::Double Haut, CORBA::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 CORBA::Double Umini, CORBA::Double Umaxi,
892 CORBA::Double Vmini, CORBA::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 CORBA::Double Ucentre, CORBA::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 CORBA::Double Ucentre, CORBA::Double Vcentre,
963 CORBA::Double Rayon, CORBA::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 // B. Les repertoires
1060 // B.1. Le repertoire du cas
1061 const char* nomDir = myCase->GetDirName();
1062 MESSAGE ( ". nomDir = " << nomDir );
1064 // B.2. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
1065 // B.2.1. Le nom du sous-repertoire
1066 const char* nomDirIt = myIteration->GetDirName();
1068 // B.2.2. Le nom complet du sous-repertoire
1069 std::stringstream DirCompute ;
1070 DirCompute << nomDir << "/" << nomDirIt;
1071 MESSAGE (". DirCompute = " << DirCompute.str() );
1073 // B.2.3. Si le sous-repertoire n'existe pas, on le cree
1074 // Si le sous-repertoire existe :
1075 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
1076 // etatMenage = 1 : on fait le menage du repertoire
1077 if (chdir(DirCompute.str().c_str()) != 0)
1079 // Creation du repertoire car il n'existe pas :
1080 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1082 // GERALD -- QMESSAGE BOX
1083 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
1084 ASSERT("Pb a la creation du repertoire" == 0);
1089 // Le repertoire existe et on fait le menage de son contenu :
1090 if (etatMenage != 0)
1092 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
1093 std::string commande= "rm -rf " + DirCompute.str()+"/*" ;
1094 int codret = system(commande.c_str());
1097 // GERALD -- QMESSAGE BOX
1098 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
1099 ASSERT("Pb au menage du repertoire de calcul" == 0);
1104 // Le repertoire existe et s'il n'est pas vide, on sort en erreur :
1106 struct dirent *dirp;
1107 dp = opendir(DirCompute.str().c_str());
1109 while ((dirp = readdir(dp)) != NULL && result )
1111 std::string file_name(dirp->d_name);
1112 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
1115 if ( result == false)
1117 SALOME::ExceptionStruct es;
1118 es.type = SALOME::BAD_PARAM;
1119 std::string text = "Directory : " + DirCompute.str() + "is not empty";
1120 es.text = CORBA::string_dup(text.c_str());
1121 throw SALOME::SALOME_Exception(es);
1127 // B.3. Le sous-repertoire de l'iteration precedente
1128 const char* nomDirItPa ;
1129 std::stringstream DirComputePa ;
1132 nomDirItPa = nomDirIt;
1133 DirComputePa << DirCompute.str();
1137 nomDirItPa = myIterationParent->GetDirName();
1138 DirComputePa << nomDir << "/" << nomDirItPa;
1140 MESSAGE( ". nomDirItPa = " << nomDirItPa);
1141 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
1143 // B.4. Le fichier des messages
1144 chdir(DirCompute.str().c_str()) ;
1145 std::string MessFile = DirCompute.str() + "/Liste." + siter + ".vers." + siterp1 ;
1146 MESSAGE (". MessFile = " << MessFile);
1147 myIteration->SetMessFile(MessFile.c_str());
1149 // C. On passe dans le repertoire de l'iteration a calculer
1150 chdir(DirCompute.str().c_str()) ;
1152 // D. Les donnees du calcul HOMARD
1153 // D.1. Le type de conformite
1154 int ConfType = myCase->GetConfType();
1155 MESSAGE ( ". ConfType = " << ConfType );
1157 // D.2. Le maillage n
1158 const char* NomMeshParent = myIterationParent->GetMeshName();
1159 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
1160 const char* MeshFileParent = myIterationParent->GetMeshFile();
1161 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
1163 // D.3. Le maillage n+1
1164 const char* NomMesh = myIteration->GetMeshName();
1165 MESSAGE ( ". NomMesh = " << NomMesh );
1166 const char* MeshFile = myIteration->GetMeshFile();
1167 MESSAGE ( ". MeshFile = " << MeshFile );
1168 FILE *file = fopen(MeshFile,"r");
1172 if (etatMenage == 0)
1174 SALOME::ExceptionStruct es;
1175 es.type = SALOME::BAD_PARAM;
1176 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
1177 es.text = CORBA::string_dup(text.c_str());
1178 throw SALOME::SALOME_Exception(es);
1183 std::string commande = "rm -f " + std::string(MeshFile);
1184 codret = system(commande.c_str());
1187 SALOME::ExceptionStruct es;
1188 es.type = SALOME::BAD_PARAM;
1189 std::string text = "PB with meshfile destruction ";
1190 es.text = CORBA::string_dup(text.c_str());
1191 throw SALOME::SALOME_Exception(es);
1202 // D.4. Les types de raffinement et de deraffinement
1203 // Les appels corba sont lourds, il vaut mieux les grouper
1204 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
1205 ASSERT(ListTypes->length() == 3);
1206 int TypeAdap = (*ListTypes)[0];
1207 int TypeRaff = (*ListTypes)[1];
1208 int TypeDera = (*ListTypes)[2];
1210 // D.6. L'option d'interpolation des champs
1211 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
1213 // E. Texte du fichier de configuration
1214 // E.1. Incontournables du texte
1215 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
1216 myDriver->TexteInit(DirCompute.str(), DirComputePa.str(),MessFile);
1217 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
1218 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
1219 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
1221 // E.2. Ajout des informations liees aux zones eventuelles
1224 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
1225 int numberOfZones = ListZone->length();
1227 for (int NumZone = 0; NumZone< numberOfZones; NumZone++)
1229 std::string ZoneName = std::string((*ListZone)[NumZone]);
1230 MESSAGE ( "... ZoneName = " << ZoneName);
1231 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1232 ASSERT(!CORBA::is_nil(myZone));
1234 int ZoneType = myZone->GetZoneType();
1235 MESSAGE ( "... ZoneType = " << ZoneType);
1236 HOMARD::double_array* zone = myZone->GetCoords();
1237 if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
1239 myDriver->TexteZone(NumZone+1, ZoneType, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.);
1241 else if ( ZoneType == 4 ) // Cas d une sphere
1243 myDriver->TexteZone(NumZone+1, ZoneType, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.);
1245 else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
1247 myDriver->TexteZone(NumZone+1, ZoneType, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.);
1249 else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
1251 myDriver->TexteZone(NumZone+1, ZoneType, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]);
1253 else { ASSERT("ZoneType est incorrect." == 0) ; }
1256 // E.3. Ajout des informations liees aux champs eventuels
1259 // Le fichier du champ
1260 char* FieldFile = myIteration->GetFieldFile();
1261 MESSAGE ( ". FieldFile = " << FieldFile );
1262 if (strlen(FieldFile) == 0)
1264 // GERALD -- QMESSAGE BOX
1265 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1266 ASSERT("The file for the field is not given." == 0);
1268 // Les caracteristiques d'instants
1269 int TimeStep = myIteration->GetTimeStep();
1270 MESSAGE( ". TimeStep = " << TimeStep );
1271 int Rank = myIteration->GetRank();
1272 MESSAGE( ". Rank = " << Rank );
1273 // Les informations sur les champ
1274 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
1276 const char* FieldName = aInfosHypo->FieldName;
1278 int TypeThR = aInfosHypo->TypeThR;
1279 double ThreshR = aInfosHypo->ThreshR;
1280 int TypeThC = aInfosHypo->TypeThC;
1281 double ThreshC = aInfosHypo->ThreshC;
1282 // Saut entre mailles ou non ?
1283 int UsField = aInfosHypo->UsField;
1284 MESSAGE( ". UsField = " << UsField );
1285 // L'usage des composantes
1286 int UsCmpI = aInfosHypo->UsCmpI;
1287 MESSAGE( ". UsCmpI = " << UsCmpI );
1289 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
1292 HOMARD::listeComposantsHypo* mescompo = myHypo->GetListComp();
1293 int numberOfCompos = mescompo->length();
1294 MESSAGE( ". numberOfCompos = " << numberOfCompos );
1295 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
1297 std::string nomCompo = std::string((*mescompo)[NumeComp]);
1298 MESSAGE( "... nomCompo = " << nomCompo );
1299 myDriver->TexteCompo(NumeComp, nomCompo);
1302 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
1303 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
1304 int numberOfGroups = listeGroupes->length();
1305 MESSAGE( ". numberOfGroups = " << numberOfGroups );
1306 if (numberOfGroups > 0)
1309 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
1311 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
1312 MESSAGE( "... GroupName = " << GroupName );
1313 myDriver->TexteGroup(GroupName);
1317 // E.5. Ajout des informations liees a l'eventuel suivi de frontiere
1318 // On ecrit d'abord la definition des frontieres, puis les liens avec les groupes
1319 std::list<std::string> ListeBoundaryTraitees ;
1320 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
1321 int numberOfitems = ListBoundaryGroupType->length();
1322 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
1323 int BoundaryOption = 1 ;
1324 int NumBoundaryAnalytical = 0 ;
1325 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1327 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1328 MESSAGE ( "... BoundaryName = " << BoundaryName);
1330 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
1331 while (it != ListeBoundaryTraitees.end())
1333 MESSAGE ( "... BoundaryNameTraitee = " << *it);
1334 if ( BoundaryName == *it ) { A_faire = 0 ; }
1339 // Caracteristiques de la frontiere
1340 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1341 ASSERT(!CORBA::is_nil(myBoundary));
1342 int BoundaryType = myBoundary->GetBoundaryType();
1343 MESSAGE ( "... BoundaryType = " << BoundaryType );
1344 // Ecriture selon le type
1345 if (BoundaryType == 0) // Cas d une frontiere discrete
1347 const char* MeshName = myBoundary->GetMeshName() ;
1348 const char* MeshFile = myBoundary->GetMeshFile() ;
1349 myDriver->TexteBoundaryDi( MeshName, MeshFile);
1350 BoundaryOption = BoundaryOption*2 ;
1352 else // Cas d une frontiere analytique
1354 NumBoundaryAnalytical++ ;
1355 HOMARD::double_array* coor = myBoundary->GetCoords();
1356 if (BoundaryType == 1) // Cas d un cylindre
1358 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6]);
1359 BoundaryOption = BoundaryOption*3 ;
1361 else if (BoundaryType == 2) // Cas d une sphere
1363 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0.);
1364 BoundaryOption = BoundaryOption*3 ;
1367 // Memorisation du traitement
1368 ListeBoundaryTraitees.push_back( BoundaryName );
1371 NumBoundaryAnalytical = 0 ;
1372 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1374 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1375 MESSAGE ( "... BoundaryName = " << BoundaryName);
1376 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1377 ASSERT(!CORBA::is_nil(myBoundary));
1378 int BoundaryType = myBoundary->GetBoundaryType();
1379 MESSAGE ( "... BoundaryType = " << BoundaryType );
1380 // Recuperation du nom du groupe
1381 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
1382 MESSAGE ( "... GroupName = " << GroupName);
1383 if (BoundaryType == 0) // Cas d une frontiere discrete
1385 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
1387 else // Cas d une frontiere analytique
1389 NumBoundaryAnalytical++ ;
1390 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
1393 myDriver->TexteBoundaryOption(BoundaryOption);
1395 // E.6. Ajout des informations liees a l'eventuelle interpolation des champs
1396 MESSAGE( "... TypeFieldInterp = " << TypeFieldInterp );
1397 if (TypeFieldInterp != 0)
1399 // Le fichier des champs
1400 char* FieldFile = myIteration->GetFieldFile();
1401 MESSAGE ( ". FieldFile = " << FieldFile );
1402 if (strlen(FieldFile) == 0)
1404 // GERALD -- QMESSAGE BOX
1405 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1406 ASSERT("The file for the field is not given." == 0);
1408 // Les caracteristiques d'instants
1409 int TimeStep = myIteration->GetTimeStep();
1410 MESSAGE( ". TimeStep = " << TimeStep );
1411 int Rank = myIteration->GetRank();
1412 MESSAGE( ". Rank = " << Rank );
1414 myDriver->TexteFieldInterp(TypeFieldInterp, FieldFile, MeshFile, TimeStep, Rank);
1416 if (TypeFieldInterp == 2)
1418 HOMARD::listFieldInterpHypo* meschamps = myHypo->GetListFieldInterp();
1419 int numberOfFields = meschamps->length();
1420 MESSAGE( ". numberOfFields = " << numberOfFields );
1421 for (int NumeChamp = 0; NumeChamp< numberOfFields; NumeChamp++)
1423 std::string nomChamp = std::string((*meschamps)[NumeChamp]);
1424 MESSAGE( "... nomChamp = " << nomChamp );
1425 myDriver->TexteFieldInterpName(NumeChamp, nomChamp);
1429 // E.7. Ajout des options avancees
1430 int NivMax = myHypo->GetNivMax();
1431 MESSAGE ( ". NivMax = " << NivMax );
1434 double DiamMin = myHypo->GetDiamMin();
1435 MESSAGE ( ". DiamMin = " << DiamMin );
1436 myDriver->TexteAdvanced(NivMax, DiamMin);
1439 // F. Ecriture du texte dans le fichier
1442 myDriver->CreeFichier();
1447 int codretexec = 1 ;
1450 codretexec = myDriver->ExecuteHomard();
1452 if (codretexec == 0)
1454 SetEtatIter(nomIteration,true);
1458 // GERALD -- QMESSAGE BOX
1459 SetEtatIter(nomIteration,false);
1463 // H. Gestion des resultats
1466 // H.1. Le fichier des messages, dans tous les cas
1467 std::stringstream saux1 ;
1468 saux1 << "Mess " << NumeIter ;
1469 PublishFileUnderIteration(nomIteration, MessFile.c_str(), saux1.str().c_str());
1471 // H.2. Si tout s'est bien passe :
1472 if (codretexec == 0)
1474 // H.2.1. Le fichier de bilan
1475 std::stringstream saux2 ;
1476 saux2 << "Summary " << NumeIter ;
1477 std::string SummaryFile = DirCompute.str() + "/apad." + siterp1 + ".bilan" ;
1478 PublishFileUnderIteration(nomIteration, SummaryFile.c_str(), saux2.str().c_str());
1479 // H.2.2. Le fichier de maillage obtenu
1480 std::stringstream saux0 ;
1481 saux0 <<"Iteration " << NumeIter ;
1482 PublishFileUnderIteration(nomIteration, MeshFile, saux0.str().c_str());
1483 PublishResultInSmesh(MeshFile, 1);
1485 // H.3 Message d'erreur en cas de probleme
1488 SALOME::ExceptionStruct es;
1489 es.type = SALOME::BAD_PARAM;
1490 std::string text = "Error during the adaptation.\n" ;
1493 ifstream fichier(MessFile.c_str(), ios::in);
1495 while(getline(fichier, ligne) and (ligne != "===== HOMARD ===== STOP ====="));
1496 while (getline(fichier, ligne)) { text += ligne+ "\n";};
1499 text += "no log file ....";
1501 es.text = CORBA::string_dup(text.c_str());
1502 throw SALOME::SALOME_Exception(es);
1512 if (codret == 0) { return true; }
1513 else { return false; }
1516 //===========================================================================
1517 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
1518 SALOMEDS::SObject_ptr theSObject,
1519 CORBA::Object_ptr theObject,
1520 const char* theName)
1522 MESSAGE("PublishInStudy pour " << theName);
1523 SALOMEDS::SObject_var aResultSO;
1524 if (CORBA::is_nil(theStudy))
1526 SALOME::ExceptionStruct es;
1527 es.type = SALOME::BAD_PARAM;
1528 es.text = "Invalid Study Context ";
1529 throw SALOME::SALOME_Exception(es);
1533 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
1534 // Rq : Iteration est publiee ailleurs
1535 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
1536 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
1537 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
1538 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
1540 addInStudy(theStudy);
1542 // Controle de la non publication d'un objet de meme nom
1543 if ((!aHypo->_is_nil()) or (!aZone->_is_nil()) or (!aBoundary->_is_nil()))
1545 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
1546 if (listSO->length() >= 1)
1548 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
1549 std::cerr <<"This name "<<theName<<" is already used "<<listSO->length()<<" time(s)" << std::endl;
1550 aResultSO = listSO[0];
1551 return aResultSO._retn();
1555 // Caracteristiques de l'etude
1556 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1557 aStudyBuilder->NewCommand();
1558 if(!aCase->_is_nil())
1559 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
1560 else if(!aHypo->_is_nil())
1561 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
1562 else if(!aZone->_is_nil())
1563 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
1564 else if(!aBoundary->_is_nil())
1565 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
1567 aStudyBuilder->CommitCommand();
1568 return aResultSO._retn();
1570 //=============================================================================
1571 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
1572 SALOMEDS::StudyBuilder_var aStudyBuilder,
1573 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
1575 MESSAGE("PublishCaseInStudy pour "<<theName);
1576 SALOMEDS::SObject_var aResultSO;
1577 SALOMEDS::GenericAttribute_var anAttr;
1579 if (CORBA::is_nil(theObject)) {
1580 MESSAGE("HOMARD_Gen_i.cxx::theObject->_is_nil()");
1581 return aResultSO._retn();
1583 if (theStudy->_is_nil()) {
1584 MESSAGE("HOMARD_Gen_i.cxx::theStudy->_is_nil()");
1585 return aResultSO._retn();
1588 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1589 if (theFatherHomard->_is_nil())
1591 MESSAGE("theFatherHomard->_is_nil()");
1592 return aResultSO._retn();
1595 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
1596 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
1597 _orb->object_to_string(theObject) ) ;
1598 return aResultSO._retn();
1601 //=============================================================================
1602 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
1603 SALOMEDS::StudyBuilder_var aStudyBuilder,
1604 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
1606 MESSAGE("PublishZoneStudy pour "<<theName);
1607 SALOMEDS::SObject_var aResultSO;
1608 SALOMEDS::GenericAttribute_var anAttr;
1610 if (CORBA::is_nil(theObject))
1612 MESSAGE("HOMARD_Gen_i.cxx::theObject->_is_nil()");
1613 return aResultSO._retn();
1615 if (theStudy->_is_nil())
1617 MESSAGE("HOMARD_Gen_i.cxx::theStudy->_is_nil()");
1618 return aResultSO._retn();
1620 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1621 if (theFatherHomard->_is_nil())
1623 MESSAGE("theFatherHomard->_is_nil()");
1624 return aResultSO._retn();
1627 // Caracteristique de la zone
1628 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
1629 CORBA::Long ZoneType = myZone->GetZoneType();
1631 // On ajoute la categorie des zones dans l etude si necessaire
1632 SALOMEDS::SObject_var aSOZone;
1633 if (!theFatherHomard->FindSubObject(100, aSOZone))
1635 MESSAGE("Ajout de la categorie des zones");
1636 aSOZone = aStudyBuilder->NewObjectToTag(theFatherHomard, 100);
1637 PublishInStudyAttr(aStudyBuilder, aSOZone, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
1639 else { MESSAGE("La categorie des zones existe deja."); }
1641 aResultSO = aStudyBuilder->NewObject(aSOZone);
1650 { icone = "boxdxy_2.png" ;
1654 { icone = "boxdxyz_2.png" ;
1662 { icone = "disk_2.png" ;
1666 { icone = "spherepoint_2.png" ;
1670 { icone = "cylinderpointvector_2.png" ;
1678 { icone = "diskwithhole_2.png" ;
1682 { icone = "pipe_2.png" ;
1686 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone, _orb->object_to_string(theObject) ) ;
1688 return aResultSO._retn();
1690 //=============================================================================
1691 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
1692 SALOMEDS::StudyBuilder_var aStudyBuilder,
1693 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
1695 MESSAGE("PublishBoundaryStudy pour "<<theName);
1696 SALOMEDS::SObject_var aResultSO;
1697 SALOMEDS::GenericAttribute_var anAttr;
1699 // Caracteristique de la Boundary
1700 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
1702 // On recupere le module pere dans l etude
1703 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1704 if (theFatherHomard->_is_nil())
1706 MESSAGE("theFatherHomard->_is_nil()");
1707 return aResultSO._retn();
1710 // On ajoute la categorie des boundarys dans l etude si necessaire
1711 SALOMEDS::SObject_var aSOBoundary;
1712 if (!theFatherHomard->FindSubObject(101, aSOBoundary))
1714 MESSAGE("Ajout de la categorie des boundarys");
1715 aSOBoundary = aStudyBuilder->NewObjectToTag(theFatherHomard, 101);
1716 PublishInStudyAttr(aStudyBuilder, aSOBoundary, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
1718 else { MESSAGE("La categorie des boundarys existe deja."); }
1720 aResultSO = aStudyBuilder->NewObject(aSOBoundary);
1721 CORBA::Long BoundaryType = myBoundary->GetBoundaryType();
1722 // MESSAGE("BoundaryType : "<<BoundaryType);
1725 switch (BoundaryType)
1728 { value = "BoundaryDiHomard" ;
1729 icone = "mesh_tree_mesh.png" ;
1733 { value = "BoundaryAnHomard" ;
1734 icone = "cylinderpointvector_2.png" ;
1738 { value = "BoundaryAnHomard" ;
1739 icone = "spherepoint_2.png" ;
1743 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value, icone, _orb->object_to_string(theObject));
1744 return aResultSO._retn();
1747 //=============================================================================
1748 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
1749 SALOMEDS::StudyBuilder_var aStudyBuilder,
1750 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
1752 MESSAGE("PublishHypotheseInStudy pour "<<theName);
1753 SALOMEDS::SObject_var aResultSO;
1754 SALOMEDS::GenericAttribute_var anAttr;
1756 // On recupere le module pere dans l etude
1757 // On ajoute la categorie des hypotheses dans l etude si necessaire
1758 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1759 if (theFatherHomard->_is_nil())
1761 MESSAGE("theFatherHomard->_is_nil()");
1762 return aResultSO._retn();
1764 SALOMEDS::SObject_var aSOHypothese;
1765 if (!theFatherHomard->FindSubObject(0, aSOHypothese))
1767 MESSAGE("Ajout de la categorie des hypotheses");
1768 aSOHypothese = aStudyBuilder->NewObjectToTag(theFatherHomard, 0);
1769 PublishInStudyAttr(aStudyBuilder, aSOHypothese, "Hypothesis", "HypoList","hypotheses.png", NULL);
1771 else { MESSAGE("La categorie des hypotheses existe deja."); }
1773 // Creation du resultat dans l'etude
1774 aResultSO = aStudyBuilder->NewObject(aSOHypothese);
1775 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
1777 return aResultSO._retn();
1779 //===========================================================================
1780 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
1781 SALOMEDS::SObject_var aResultSO,
1782 const char* name, const char* value, const char* icone, const char* ior)
1784 SALOMEDS::GenericAttribute_var anAttr ;
1788 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
1789 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
1790 aNameAttrib->SetValue(name);
1793 // Ajout du commentaire
1794 if ( value != NULL )
1796 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
1797 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
1798 aCommentAttrib->SetValue(value);
1802 if ( icone != NULL )
1804 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO,"AttributePixMap");
1805 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
1806 aPixmap->SetPixMap(icone);
1812 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
1813 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1814 anIOR->SetValue(ior);
1818 //=============================================================================
1819 HOMARD::listeCases* HOMARD_Gen_i::GetAllCases()
1821 MESSAGE("GetAllCases");
1824 HOMARD::listeCases_var ret = new HOMARD::listeCases;
1825 ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
1826 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
1828 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
1829 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
1831 ret[i++] = CORBA::string_dup((*it).first.c_str());
1837 //=============================================================================
1838 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypotheses()
1840 MESSAGE("GetAllHypotheses");
1843 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
1844 ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
1845 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
1847 for (it = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
1848 it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
1850 ret[i++] = CORBA::string_dup((*it).first.c_str());
1856 //=============================================================================
1857 HOMARD::listeZones* HOMARD_Gen_i::GetAllZones()
1859 MESSAGE("GetAllZones");
1862 HOMARD::listeZones_var ret = new HOMARD::listeZones;
1863 ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
1864 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
1866 for (it = myContextMap[GetCurrentStudyID()]._mesZones.begin();
1867 it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
1869 ret[i++] = CORBA::string_dup((*it).first.c_str());
1875 //=============================================================================
1876 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterations()
1878 MESSAGE("GetAllIterations");
1881 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
1882 ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
1883 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
1885 for (it = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
1886 it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
1888 ret[i++] = CORBA::string_dup((*it).first.c_str());
1893 //=============================================================================
1894 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarys()
1896 MESSAGE("GetAllBoundarys");
1899 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
1900 ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
1901 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
1903 for (it = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
1904 it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
1906 ret[i++] = CORBA::string_dup((*it).first.c_str());
1912 //=============================================================================
1913 char* HOMARD_Gen_i::GetCaseName(const char* nomIteration)
1915 if (CORBA::is_nil(myCurrentStudy))
1917 SALOME::ExceptionStruct es;
1918 es.type = SALOME::BAD_PARAM;
1919 es.text = "Invalid Study Context ";
1920 throw SALOME::SALOME_Exception(es);
1924 HOMARD::HOMARD_Iteration_var monIter = myContextMap[GetCurrentStudyID()]._mesIterations[nomIteration];
1925 ASSERT(!CORBA::is_nil(monIter));
1926 return CORBA::string_dup(monIter->GetCaseName());
1928 //=============================================================================
1929 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long IconeType)
1931 MESSAGE( "PublishResultInSmesh " << NomFich);
1932 if (CORBA::is_nil(myCurrentStudy))
1934 SALOME::ExceptionStruct es;
1935 es.type = SALOME::BAD_PARAM;
1936 es.text = "Invalid Study Context ";
1937 throw SALOME::SALOME_Exception(es);
1941 // Le module SMESH est-il actif ?
1942 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
1944 if (!CORBA::is_nil(aSmeshSO))
1946 // On verifie que le fichier n est pas deja publie
1947 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
1948 for (; aIter->More(); aIter->Next())
1950 SALOMEDS::SObject_var aSO = aIter->Value();
1951 SALOMEDS::GenericAttribute_var aGAttr;
1952 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
1954 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
1955 CORBA::String_var value=anAttr->Value();
1956 if (strcmp((const char*)value,NomFich) == 0)
1958 // GERALD -- QMESSAGE BOX
1959 std::cerr << "fichier : "<< NomFich << " deja publie "<< std::endl;
1967 // On enregistre le fichier
1968 MESSAGE( "Enregistrement du fichier");
1969 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
1970 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
1971 ASSERT(!CORBA::is_nil(aSmeshEngine));
1972 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
1973 SMESH::DriverMED_ReadStatus theStatus;
1974 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
1976 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
1977 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
1978 for (int i = 0; i < mesMaillages->length(); i++)
1980 MESSAGE( ". Mise a jour des attributs du maillage");
1981 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
1982 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
1983 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1984 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
1985 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
1986 anAttr->SetValue(NomFich);
1987 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
1988 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
1989 // IconeType = 0 : fichier issu d'une importation
1990 // IconeType = 1 : fichier issu d'une execution HOMARD
1992 if ( IconeType == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
1993 else { icone = "mesh_tree_mesh.png" ; }
1994 anAttr2->SetPixMap( icone );
1998 //=============================================================================
1999 void HOMARD_Gen_i::DeleteResultInSmesh(const char* NomFich, const char* MeshName)
2001 MESSAGE (" DeleteResultInSmesh pour "<< NomFich << "et le maillage "<< MeshName);
2002 if (CORBA::is_nil(myCurrentStudy))
2004 SALOME::ExceptionStruct es;
2005 es.type = SALOME::BAD_PARAM;
2006 es.text = "Invalid Study Context ";
2007 throw SALOME::SALOME_Exception(es);
2011 // Le module SMESH est-il actif ?
2012 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
2014 if (CORBA::is_nil(aSmeshSO))
2018 // On verifie que le fichier est deja publie
2019 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
2020 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
2021 for (; aIter->More(); aIter->Next())
2023 SALOMEDS::SObject_var aSO = aIter->Value();
2024 SALOMEDS::GenericAttribute_var aGAttr;
2025 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
2027 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2028 CORBA::String_var value=anAttr->Value();
2029 if (strcmp((const char*)value,NomFich) == 0)
2031 if (aSO->FindAttribute(aGAttr,"AttributeName"))
2033 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
2034 CORBA::String_var value2=anAttr2->Value();
2035 if (strcmp((const char*)value2,MeshName) == 0)
2037 myBuilder->RemoveObjectWithChildren( aSO ) ;
2045 //=============================================================================
2046 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
2048 if (CORBA::is_nil(myCurrentStudy))
2050 SALOME::ExceptionStruct es;
2051 es.type = SALOME::BAD_PARAM;
2052 es.text = "Invalid Study Context ";
2053 throw SALOME::SALOME_Exception(es);
2057 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
2058 if (CORBA::is_nil(myIteration))
2060 SALOME::ExceptionStruct es;
2061 es.type = SALOME::BAD_PARAM;
2062 es.text = "Invalid Iteration ";
2063 throw SALOME::SALOME_Exception(es);
2066 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
2067 if (CORBA::is_nil(myIteration))
2069 SALOME::ExceptionStruct es;
2070 es.type = SALOME::BAD_PARAM;
2071 es.text = "Invalid Iteration Study Object";
2072 throw SALOME::SALOME_Exception(es);
2076 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2078 aStudyBuilder->NewCommand();
2080 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
2081 // Pour les fichiers med, on affiche une icone de maillage
2082 // Pour les fichiers qui sont texte, on affiche une icone de fichier texte 'texte'
2083 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
2085 const char* ior = " " ;
2086 if ( Commentaire[0] == 'I' )
2087 { icone = "med.png" ; }
2089 { icone = "texte_2.png" ; }
2090 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone, ior ) ;
2092 aStudyBuilder->CommitCommand();
2095 //=====================================================================================
2096 void HOMARD_Gen_i::IsValidStudy( )
2097 //=====================================================================================
2099 MESSAGE( "IsValidStudy" );
2100 if (CORBA::is_nil(myCurrentStudy))
2102 SALOME::ExceptionStruct es;
2103 es.type = SALOME::BAD_PARAM;
2104 es.text = "Invalid Study Context";
2105 throw SALOME::SALOME_Exception(es);
2110 //===========================================================================
2112 // Next functions are inherited from SALOMEDS::Driver interface
2114 //===========================================================================
2116 //===========================================================================
2117 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
2119 CORBA::Boolean isMultiFile)
2121 MESSAGE (" Save pour theURL = "<< theURL);
2122 SALOMEDS::TMPFile_var aStreamFile;
2124 // get temporary directory name
2125 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2127 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2128 StudyContext& context = myContextMap[ aStudy->StudyId() ];
2130 // HOMARD data file name
2131 std::string aFileName = "";
2133 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2134 aFileName += "_HOMARD.dat";
2136 // initialize sequence of file names
2137 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
2138 aFileSeq->length(1);
2139 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
2141 // get full path to the data file
2142 aFileName = tmpDir + aFileName;
2146 std::ofstream f(aFileName.c_str());
2148 // clear temporary id map
2149 context._idmap.clear();
2154 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
2155 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
2156 HOMARD::HOMARD_Cas_var aCas = it_case->second;
2157 PortableServer::ServantBase_var aServant = GetServant(aCas);
2158 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2160 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
2161 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
2165 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2166 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
2167 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
2168 PortableServer::ServantBase_var aServant = GetServant(aZone);
2169 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2171 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
2172 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2175 // -> dump hypotheses
2176 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2177 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
2178 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
2179 PortableServer::ServantBase_var aServant = GetServant(aHypo);
2180 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2182 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
2183 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2186 // -> dump iterations
2187 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2188 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
2189 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
2190 PortableServer::ServantBase_var aServant = GetServant(aIter);
2191 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2193 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
2194 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2197 // -> dump boundaries
2198 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2199 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
2200 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
2201 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2202 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2203 if (aBoundaryServant) {
2204 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
2205 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2209 MESSAGE ("close file");
2212 // put temporary files to the stream
2213 MESSAGE ("put temporary files to the stream");
2214 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
2216 // remove temporary files
2217 MESSAGE ("remove temporary files");
2218 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2220 // return data stream
2221 MESSAGE ("return data stream");
2222 return aStreamFile._retn();
2225 //===========================================================================
2226 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
2228 CORBA::Boolean isMultiFile)
2230 // No specific ASCII persistence
2231 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
2232 return aStreamFile._retn();
2235 //===========================================================================
2236 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
2237 const SALOMEDS::TMPFile& theStream,
2239 CORBA::Boolean isMultiFile)
2241 MESSAGE (" Load pour theURL = "<< theURL);
2242 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2244 // set current study
2245 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
2246 SetCurrentStudy(aStudy);
2248 // get temporary directory name
2249 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2251 // Convert the stream into sequence of files to process
2252 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
2255 // HOMARD data file name
2256 std::string aFileName = "";
2258 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2259 aFileName = tmpDir + aFileName + "_HOMARD.dat";
2261 StudyContext& context = myContextMap[ aStudy->StudyId() ];
2265 std::ifstream f(aFileName.c_str());
2268 context._mesCas.clear();
2269 context._mesHypotheses.clear();
2270 context._mesIterations.clear();
2271 context._mesZones.clear();
2272 context._mesBoundarys.clear();
2273 context._idmap.clear();
2279 std::getline(f, line);
2280 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
2281 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
2282 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
2283 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
2284 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
2285 if (line.substr(0, caseSignature.size()) == caseSignature) {
2287 MESSAGE (" Recreation du cas" );
2288 HOMARD::HOMARD_Cas_var aCase = newCase();
2289 PortableServer::ServantBase_var aServant = GetServant(aCase);
2290 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2291 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
2292 context._mesCas[aCase->GetName()] = aCase;
2293 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
2296 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
2297 MESSAGE (" Recreation de la zone" );
2299 HOMARD::HOMARD_Zone_var aZone = newZone();
2300 PortableServer::ServantBase_var aServant = GetServant(aZone);
2301 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2302 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
2303 context._mesZones[aZone->GetName()] = aZone;
2304 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2307 else if (line.substr(0, iterSignature.size()) == iterSignature) {
2308 // re-create iteration
2309 MESSAGE (" Recreation de l iteration" );
2310 HOMARD::HOMARD_Iteration_var aIter = newIteration();
2311 PortableServer::ServantBase_var aServant = GetServant(aIter);
2312 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2313 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
2314 context._mesIterations[aIter->GetName()] = aIter;
2315 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2318 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
2319 // re-create hypothesis
2320 MESSAGE (" Recreation de l hypothese" );
2321 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
2322 PortableServer::ServantBase_var aServant = GetServant(aHypo);
2323 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2324 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
2325 context._mesHypotheses[aHypo->GetName()] = aHypo;
2326 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2329 else if (line.substr(0, bounSignature.size()) == bounSignature) {
2330 // re-create boundary
2331 MESSAGE (" Recreation de la frontiere" );
2332 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
2333 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2334 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2335 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
2336 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
2337 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2346 // Remove temporary files created from the stream
2348 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2353 //===========================================================================
2354 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
2355 const SALOMEDS::TMPFile& theStream,
2357 CORBA::Boolean isMultiFile)
2359 // No specific ASCII persistence
2360 return Load(theComponent, theStream, theURL, isMultiFile);
2363 //===========================================================================
2364 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
2366 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
2367 // clearing study context should be done here:
2368 // - destroy all servants and related CORBA objects
2370 // - remove context from myContextMap
2371 myContextMap.erase(theComponent->GetStudy()->StudyId());
2372 // - nullify myCurrentStudy
2373 myCurrentStudy = SALOMEDS::Study::_nil();
2377 //===========================================================================
2378 char* HOMARD_Gen_i::ComponentDataType()
2380 return CORBA::string_dup("HOMARD");
2383 //===========================================================================
2384 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
2385 const char* IORString,
2386 CORBA::Boolean isMultiFile,
2387 CORBA::Boolean isASCII)
2389 CORBA::String_var aString("");
2390 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
2391 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2392 CORBA::Object_var anObj = _orb->string_to_object(IORString);
2393 if (!CORBA::is_nil(anObj)) {
2394 PortableServer::ServantBase_var aServant = GetServant(anObj);
2395 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
2397 std::map<int, PortableServer::ServantBase*>::const_iterator it;
2398 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
2399 if (it->second == aStorable) {
2400 std::stringstream os;
2402 aString = CORBA::string_dup(os.str().c_str());
2408 return aString._retn();
2411 //===========================================================================
2412 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
2413 const char* aLocalPersistentID,
2414 CORBA::Boolean isMultiFile,
2415 CORBA::Boolean isASCII)
2417 CORBA::String_var aString("");
2418 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
2419 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2420 int id = atoi(aLocalPersistentID);
2421 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
2422 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
2423 if (!CORBA::is_nil(object)) {
2424 aString = _orb->object_to_string(object);
2428 return aString._retn();
2431 //===========================================================================
2432 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
2434 if(CORBA::is_nil(myCurrentStudy))
2437 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
2438 if(!aCas->_is_nil())
2441 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
2442 if(!aHypo->_is_nil())
2445 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
2446 if(!aZone->_is_nil())
2449 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
2450 if(!aBoundary->_is_nil())
2453 /* Iteration is not published directly
2454 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
2455 if(!aIter->_is_nil())
2461 //===========================================================================
2462 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
2464 // No Copy/Paste support
2468 //===========================================================================
2469 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
2470 CORBA::Long& theObjectID)
2472 // No Copy/Paste support
2473 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
2474 return aStreamFile._retn();
2477 //===========================================================================
2478 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
2479 CORBA::Long theObjectID)
2481 // No Copy/Paste support
2485 //===========================================================================
2486 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
2487 CORBA::Long theObjectID,
2488 SALOMEDS::SObject_ptr theSObject)
2490 // No Copy/Paste support
2491 SALOMEDS::SObject_var aResultSO;
2492 return aResultSO._retn();
2495 //===========================================================================
2496 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
2498 PortableServer::Servant aServant = 0;
2499 if (!CORBA::is_nil(theObject)) {
2501 aServant = _poa->reference_to_servant(theObject);
2509 //===========================================================================
2510 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
2512 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2513 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
2514 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
2515 return aCase._retn();
2518 //===========================================================================
2519 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
2521 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2522 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
2523 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
2524 return aHypo._retn();
2527 //===========================================================================
2528 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
2530 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2531 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
2532 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
2533 return aIter._retn();
2536 //===========================================================================
2537 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
2539 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2540 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
2541 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
2542 return aBoundary._retn();
2544 //===========================================================================
2545 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
2547 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2548 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
2549 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
2550 return aZone._retn();
2552 //==========================================================================
2553 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
2554 CORBA::Boolean isPublished,
2555 CORBA::Boolean isMultiFile,
2556 CORBA::Boolean& isValidScript)
2558 MESSAGE ("Entree dans DumpPython");
2560 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
2561 if(CORBA::is_nil(aStudy))
2562 return new Engines::TMPFile(0);
2564 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
2565 if(CORBA::is_nil(aSO))
2566 return new Engines::TMPFile(0);
2568 std::string aScript = "\"\"\"\n";
2569 aScript += "Python script for HOMARD\n";
2570 aScript += "Copyright EDF-R&D 2010\n";
2571 aScript += "\"\"\"\n";
2572 aScript += "__revision__ = \"V1.2\"\n";
2573 aScript += "import HOMARD\n";
2575 aScript += "import salome\n";
2576 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
2578 aScript += "def RebuildData(theStudy):\n";
2579 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
2582 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
2585 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
2587 aScript += "#\n# Creation of the boundaries";
2588 aScript += "\n# ==========================";
2590 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2591 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
2592 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
2594 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
2595 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
2596 std::string dumpBoundary = dumpCorbaBoundary.in();
2597 aScript+=dumpBoundary;
2601 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
2603 aScript += "#\n# Creation of the zones";
2604 aScript += "\n# =====================";
2606 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2607 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
2608 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
2610 HOMARD::HOMARD_Zone_var maZone = (*it_zone).second;
2611 CORBA::String_var dumpCorbaZone = maZone->GetDumpPython();
2612 std::string dumpZone = dumpCorbaZone.in();
2617 aScript += "#\n# Creation of the hypotheses";
2618 aScript += "\n# ==========================";
2619 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2620 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
2621 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
2623 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
2624 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
2625 std::string dumpHypo = dumpCorbaHypo.in();
2630 aScript += "#\n# Creation of the cases";
2631 aScript += "\n# =====================";
2632 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
2633 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
2634 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
2636 std::string nomCas = (*it_cas).first;
2637 std::string dumpCas = std::string("\n# Creation of the case ") ;
2638 dumpCas += nomCas + std::string("\n");
2639 dumpCas += std::string("\t") + nomCas;
2640 dumpCas += std::string(" = homard.CreateCase('") + nomCas + std::string("', '");
2642 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
2643 CORBA::String_var cIter0= myCase->GetIter0Name();
2644 std::string iter0 = cIter0.in();
2646 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
2647 CORBA::String_var cMesh0= myIteration->GetMeshFile();
2648 std::string mesh0 = cMesh0.in();
2649 CORBA::String_var cMeshName0= myIteration->GetMeshName();
2650 std::string meshName0 = cMeshName0.in();
2651 dumpCas += meshName0 + std::string("', '")+ mesh0 + std::string("')\n");
2652 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
2653 std::string dumpCas2= dumpCorbaCase.in();
2655 aScript+=dumpCas + dumpCas2;
2659 aScript += "#\n# Creation of the iterations" ;
2660 aScript += "\n# ==========================";
2661 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2662 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
2663 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
2665 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
2666 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
2667 std::string dumpIter = dumpCorbaIter.in();
2672 aScript += "\n\tpass";
2675 if( !isMultiFile ) // remove unnecessary tabulation
2676 aScript = RemoveTabulation( aScript );
2678 const size_t aLen = strlen(aScript.c_str());
2679 char* aBuffer = new char[aLen+1];
2680 strcpy(aBuffer, aScript.c_str());
2682 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
2683 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
2685 return aStreamFile._retn();
2688 //=============================================================================
2691 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
2692 PortableServer::POA_ptr poa,
2693 PortableServer::ObjectId* contId,
2694 const char* instanceName,
2695 const char* interfaceName)
2697 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
2698 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
2699 return myHOMARD_Gen->getId();