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 // Valeurs par defaut des filtrages
591 return HOMARD::HOMARD_Cas::_duplicate(myCase);
594 //=============================================================================
595 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCas(const char* nomCas)
598 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
599 if (CORBA::is_nil(myCase))
601 SALOME::ExceptionStruct es;
602 es.type = SALOME::BAD_PARAM;
603 es.text = "Invalid Case";
604 throw SALOME::SALOME_Exception(es);
608 return HOMARD::HOMARD_Cas::_duplicate(myCase);
611 //=============================================================================
612 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
615 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
616 ASSERT(!CORBA::is_nil(myZone));
617 return HOMARD::HOMARD_Zone::_duplicate(myZone);
620 //=============================================================================
621 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
623 MESSAGE ( "GetHypothesis : nomHypothesis = " << nomHypothesis );
625 MESSAGE ( "GetHypothesis : GetCurrentStudyID() = " << GetCurrentStudyID() );
626 HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
627 ASSERT(!CORBA::is_nil(myHypothesis));
628 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
631 //=============================================================================
632 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(const char* nomIteration)
635 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIteration];
636 ASSERT(!CORBA::is_nil(myIteration));
637 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
639 //=============================================================================
640 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
644 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
645 ASSERT(!CORBA::is_nil(myBoundary));
646 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
649 //=============================================================================
650 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
652 MESSAGE ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
655 if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
657 SALOME::ExceptionStruct es;
658 es.type = SALOME::BAD_PARAM;
659 es.text = "This hypothesis is already defined.";
660 throw SALOME::SALOME_Exception(es);
664 HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
665 myHypothesis->SetName(nomHypothesis);
666 myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
667 SALOMEDS::SObject_var aSO;
668 PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
670 // Valeurs par defaut des filtrages
671 myHypothesis->SetNivMax(-1);
672 myHypothesis->SetDiamMin(-1.0);
674 return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
677 //============================================================================================================
678 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* nomIteration, const char* nomIterParent)
679 //============================================================================================================
681 MESSAGE ("CreateIteration : nomIteration = " << nomIteration << "nomIterParent = " << nomIterParent);
684 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
685 if (CORBA::is_nil(myIterationParent))
687 SALOME::ExceptionStruct es;
688 es.type = SALOME::BAD_PARAM;
689 es.text = "The parent iteration is not defined.";
690 throw SALOME::SALOME_Exception(es);
694 const char* nomCas = GetCaseName(nomIterParent);
695 MESSAGE ("CreateIteration : nomCas = " << nomCas);
696 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
697 if (CORBA::is_nil(myCase))
699 SALOME::ExceptionStruct es;
700 es.type = SALOME::BAD_PARAM;
701 es.text = "Invalid Case Context ";
702 throw SALOME::SALOME_Exception(es);
706 if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(nomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
708 SALOME::ExceptionStruct es;
709 es.type = SALOME::BAD_PARAM;
710 es.text = "This iteration is already defined. ";
711 throw SALOME::SALOME_Exception(es);
715 HOMARD::HOMARD_Iteration_var myIteration = newIteration();
716 if (CORBA::is_nil(myIteration))
718 SALOME::ExceptionStruct es;
719 es.type = SALOME::BAD_PARAM;
720 es.text = "Unable to create Iteration ";
721 throw SALOME::SALOME_Exception(es);
724 myContextMap[GetCurrentStudyID()]._mesIterations[std::string(nomIteration)] = myIteration;
725 myIteration->SetName(nomIteration);
726 myIteration->SetMeshName(nomIteration);
728 int numero = myIterationParent->GetNumber() + 1;
729 myIteration->SetNumber(numero);
731 // Nombre d'iterations deja connues pour le cas, permettant
732 // la creation d'un sous-repertoire unique
733 int nbitercase = myCase->GetNumber();
734 std::ostringstream iaux ;
735 iaux << std::setw(2) << std::setfill('0') << nbitercase ;
736 std::stringstream DirName;
737 DirName << "I" << iaux.str();
738 myIteration->SetDirName(DirName.str().c_str());
740 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
741 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
742 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est le
743 // cas le plus frequent.
744 // Si on a plusieurs branches, donc des iterations a meme niveau d'adaptation, utiliser
745 // le nombre d'iterations du cas permet d'eviter les collisions.
746 std::stringstream MeshFile;
747 const char* nomDir = myCase->GetDirName();
748 MeshFile << nomDir << "/maill." << iaux.str() << ".med";
749 myIteration->SetMeshFile(MeshFile.str().c_str());
751 // Association avec le cas et l'iteration precedente
752 std::string label = "IterationHomard_" + std::string(nomIterParent);
753 AssociateCaseIter(nomCas, nomIteration, label.c_str());
754 AssociateIterIter (nomIterParent,nomIteration);
756 return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
760 //=============================================================================
761 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
763 MESSAGE ("CreateBoundary : BoundaryName = " << BoundaryName << ", BoundaryType = " << BoundaryType);
766 if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
768 SALOME::ExceptionStruct es;
769 es.type = SALOME::BAD_PARAM;
770 es.text = "This boundary has already been defined";
771 throw SALOME::SALOME_Exception(es);
775 HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
776 myBoundary->SetName(BoundaryName);
777 myBoundary->SetBoundaryType(BoundaryType);
779 myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
781 SALOMEDS::SObject_var aSO;
782 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
784 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
786 //=============================================================================
787 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
789 MESSAGE ("CreateBoundaryDi : BoundaryName = " << BoundaryName << "MeshName = " << MeshName );
790 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
791 myBoundary->SetMeshFile( MeshFile ) ;
792 myBoundary->SetMeshName( MeshName ) ;
794 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
796 //=============================================================================
797 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
798 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
799 CORBA::Double Xaxis, CORBA::Double Yaxis, CORBA::Double Zaxis,
802 MESSAGE ("CreateBoundaryCylinder : BoundaryName = " << BoundaryName ) ;
803 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
804 myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxis, Yaxis, Zaxis, Rayon ) ;
806 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
808 //=============================================================================
809 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
810 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
813 MESSAGE ("CreateBoundarySphere : BoundaryName = " << BoundaryName ) ;
814 HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
815 myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
817 return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
821 //=============================================================================
822 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
824 MESSAGE ("CreateZone : ZoneName = " << ZoneName << ", ZoneType = " << ZoneType);
827 if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
829 SALOME::ExceptionStruct es;
830 es.type = SALOME::BAD_PARAM;
831 es.text = "This zone has already been defined";
832 throw SALOME::SALOME_Exception(es);
836 HOMARD::HOMARD_Zone_var myZone = newZone();
837 myZone->SetName(ZoneName);
838 myZone->SetZoneType(ZoneType);
840 myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
842 SALOMEDS::SObject_var aSO;
843 SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
845 return HOMARD::HOMARD_Zone::_duplicate(myZone);
847 //=============================================================================
848 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
849 CORBA::Double Xmini, CORBA::Double Xmaxi,
850 CORBA::Double Ymini, CORBA::Double Ymaxi,
851 CORBA::Double Zmini, CORBA::Double Zmaxi)
853 MESSAGE ("CreateZoneBox : ZoneName = " << ZoneName ) ;
854 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
855 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
857 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
859 //=============================================================================
860 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
861 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
863 MESSAGE ("CreateZoneSphere : ZoneName = " << ZoneName ) ;
864 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
865 myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
867 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
869 //=============================================================================
870 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
871 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
872 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
873 CORBA::Double Rayon, CORBA::Double Haut)
875 MESSAGE ("CreateZoneCylinder : ZoneName = " << ZoneName ) ;
876 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
877 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
879 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
881 //=============================================================================
882 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
883 CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
884 CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
885 CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
887 MESSAGE ("CreateZonePipe : ZoneName = " << ZoneName ) ;
888 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
889 myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
891 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
893 //=============================================================================
894 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
895 CORBA::Double Umini, CORBA::Double Umaxi,
896 CORBA::Double Vmini, CORBA::Double Vmaxi,
899 MESSAGE ("CreateZoneBox2D : ZoneName = " << ZoneName ) ;
900 // MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
901 // MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
902 // MESSAGE ("Orient = " << Orient ) ;
904 double Xmini, Xmaxi ;
905 double Ymini, Ymaxi ;
906 double Zmini, Zmaxi ;
914 else if ( Orient == 2 )
921 else if ( Orient == 3 )
928 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
930 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
931 myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
933 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
935 //=============================================================================
936 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
937 CORBA::Double Ucentre, CORBA::Double Vcentre,
941 MESSAGE ("CreateZoneDisk : ZoneName = " << ZoneName ) ;
946 { Xcentre = Ucentre ;
949 else if ( Orient == 2 )
952 Zcentre = Vcentre ; }
953 else if ( Orient == 3 )
954 { Xcentre = Vcentre ;
956 Zcentre = Ucentre ; }
957 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
959 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
960 myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
962 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
964 //=============================================================================
965 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
966 CORBA::Double Ucentre, CORBA::Double Vcentre,
967 CORBA::Double Rayon, CORBA::Double Rayonint,
970 MESSAGE ("CreateZoneDiskWithHole : ZoneName = " << ZoneName ) ;
975 { Xcentre = Ucentre ;
978 else if ( Orient == 2 )
981 Zcentre = Vcentre ; }
982 else if ( Orient == 3 )
983 { Xcentre = Vcentre ;
985 Zcentre = Ucentre ; }
986 else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
988 HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
989 myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
991 return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
997 //=============================================================================
998 CORBA::Long HOMARD_Gen_i::Compute(const char* nomIteration, CORBA::Long etatMenage)
1000 MESSAGE ( "Compute : calcul de " << nomIteration );
1003 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIteration];
1004 ASSERT(!CORBA::is_nil(myIteration));
1006 // on ne calcule pas l iteration 0
1007 int NumeIter = myIteration->GetNumber();
1008 if ( NumeIter == 0 )
1010 SALOME::ExceptionStruct es;
1011 es.type = SALOME::BAD_PARAM;
1012 es.text = "This iteration is the first of the case and cannot be computed.";
1013 throw SALOME::SALOME_Exception(es);
1017 // on verifie qu il y a une hypothese (erreur improbable);
1018 const char* nomHypo = myIteration->GetHypoName();
1019 if (std::string(nomHypo) == std::string(""))
1021 SALOME::ExceptionStruct es;
1022 es.type = SALOME::BAD_PARAM;
1023 es.text= "This iteration does not have any associated hypothesis.";
1024 throw SALOME::SALOME_Exception(es);
1027 HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
1028 ASSERT(!CORBA::is_nil(myHypo));
1031 // A.4. L'iteration parent
1032 const char* nomIterationParent = myIteration->GetIterParent();
1033 HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
1034 ASSERT(!CORBA::is_nil(myIterationParent));
1035 if ( ! myIterationParent->GetEtat() )
1038 SALOME::ExceptionStruct es;
1039 es.type = SALOME::BAD_PARAM;
1040 std::string text = "The iteration cannot be computed because the previous iteration " + std::string(nomIterationParent) + " is not valid.";
1041 es.text = CORBA::string_dup(text.c_str());
1042 throw SALOME::SALOME_Exception(es);
1045 int codret = Compute(nomIterationParent, etatMenage);
1048 // GERALD -- QMESSAGE BOX
1049 ASSERT("Pb au calcul de l'iteration precedente" == 0);
1053 const char* nomCas = myIteration->GetCaseName();
1054 HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1055 ASSERT(!CORBA::is_nil(myCase));
1058 std::stringstream saux0 ;
1059 saux0 << NumeIter - 1 ;
1060 std::string siter = saux0.str() ;
1061 if (NumeIter < 11) { siter = "0" + siter ; }
1063 std::stringstream saux1 ;
1065 std::string siterp1 = saux1.str() ;
1066 if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
1068 // B. Les repertoires
1069 // B.1. Le repertoire du cas
1070 const char* nomDir = myCase->GetDirName();
1071 MESSAGE ( ". nomDir = " << nomDir );
1073 // B.2. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
1074 // B.2.1. Le nom du sous-repertoire
1075 const char* nomDirIt = myIteration->GetDirName();
1077 // B.2.2. Le nom complet du sous-repertoire
1078 std::stringstream DirCompute ;
1079 DirCompute << nomDir << "/" << nomDirIt;
1080 MESSAGE (". DirCompute = " << DirCompute.str() );
1082 // B.2.3. Si le sous-repertoire n'existe pas, on le cree
1083 // Si le sous-repertoire existe :
1084 // etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
1085 // etatMenage = 1 : on fait le menage du repertoire
1086 if (chdir(DirCompute.str().c_str()) != 0)
1088 // Creation du repertoire car il n'existe pas :
1089 if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1091 // GERALD -- QMESSAGE BOX
1092 std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
1093 ASSERT("Pb a la creation du repertoire" == 0);
1098 // Le repertoire existe et on fait le menage de son contenu :
1099 if (etatMenage != 0)
1101 MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
1102 std::string commande= "rm -rf " + DirCompute.str()+"/*" ;
1103 int codret = system(commande.c_str());
1106 // GERALD -- QMESSAGE BOX
1107 std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
1108 ASSERT("Pb au menage du repertoire de calcul" == 0);
1113 // Le repertoire existe et s'il n'est pas vide, on sort en erreur :
1115 struct dirent *dirp;
1116 dp = opendir(DirCompute.str().c_str());
1118 while ((dirp = readdir(dp)) != NULL && result )
1120 std::string file_name(dirp->d_name);
1121 result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
1124 if ( result == false)
1126 SALOME::ExceptionStruct es;
1127 es.type = SALOME::BAD_PARAM;
1128 std::string text = "Directory : " + DirCompute.str() + "is not empty";
1129 es.text = CORBA::string_dup(text.c_str());
1130 throw SALOME::SALOME_Exception(es);
1136 // B.3. Le sous-repertoire de l'iteration precedente
1137 const char* nomDirItPa ;
1138 std::stringstream DirComputePa ;
1141 nomDirItPa = nomDirIt;
1142 DirComputePa << DirCompute.str();
1146 nomDirItPa = myIterationParent->GetDirName();
1147 DirComputePa << nomDir << "/" << nomDirItPa;
1149 MESSAGE( ". nomDirItPa = " << nomDirItPa);
1150 MESSAGE( ". DirComputePa = " << DirComputePa.str() );
1152 // B.4. Le fichier des messages
1153 chdir(DirCompute.str().c_str()) ;
1154 std::string MessFile = DirCompute.str() + "/Liste." + siter + ".vers." + siterp1 ;
1155 MESSAGE (". MessFile = " << MessFile);
1156 myIteration->SetMessFile(MessFile.c_str());
1158 // C. On passe dans le repertoire de l'iteration a calculer
1159 chdir(DirCompute.str().c_str()) ;
1161 // D. Les donnees du calcul HOMARD
1162 // D.1. Le type de conformite
1163 int ConfType = myCase->GetConfType();
1164 MESSAGE ( ". ConfType = " << ConfType );
1166 // D.2. Le maillage n
1167 const char* NomMeshParent = myIterationParent->GetMeshName();
1168 MESSAGE ( ". NomMeshParent = " << NomMeshParent );
1169 const char* MeshFileParent = myIterationParent->GetMeshFile();
1170 MESSAGE ( ". MeshFileParent = " << MeshFileParent );
1172 // D.3. Le maillage n+1
1173 const char* NomMesh = myIteration->GetMeshName();
1174 MESSAGE ( ". NomMesh = " << NomMesh );
1175 const char* MeshFile = myIteration->GetMeshFile();
1176 MESSAGE ( ". MeshFile = " << MeshFile );
1177 FILE *file = fopen(MeshFile,"r");
1181 if (etatMenage == 0)
1183 SALOME::ExceptionStruct es;
1184 es.type = SALOME::BAD_PARAM;
1185 std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
1186 es.text = CORBA::string_dup(text.c_str());
1187 throw SALOME::SALOME_Exception(es);
1192 std::string commande = "rm -f " + std::string(MeshFile);
1193 codret = system(commande.c_str());
1196 SALOME::ExceptionStruct es;
1197 es.type = SALOME::BAD_PARAM;
1198 std::string text = "PB with meshfile destruction ";
1199 es.text = CORBA::string_dup(text.c_str());
1200 throw SALOME::SALOME_Exception(es);
1211 // D.4. Les types de raffinement et de deraffinement
1212 // Les appels corba sont lourds, il vaut mieux les grouper
1213 HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
1214 ASSERT(ListTypes->length() == 3);
1215 int TypeAdap = (*ListTypes)[0];
1216 int TypeRaff = (*ListTypes)[1];
1217 int TypeDera = (*ListTypes)[2];
1219 // D.6. L'option d'interpolation des champs
1220 int TypeFieldInterp = myHypo->GetTypeFieldInterp();
1222 // E. Texte du fichier de configuration
1223 // E.1. Incontournables du texte
1224 HomardDriver* myDriver = new HomardDriver(siter, siterp1);
1225 myDriver->TexteInit(DirCompute.str(), DirComputePa.str(),MessFile);
1226 myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
1227 myDriver->TexteMaillage(NomMesh, MeshFile, 1);
1228 myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
1230 // E.2. Ajout des informations liees aux zones eventuelles
1233 HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
1234 int numberOfZones = ListZone->length();
1236 for (int NumZone = 0; NumZone< numberOfZones; NumZone++)
1238 std::string ZoneName = std::string((*ListZone)[NumZone]);
1239 MESSAGE ( "... ZoneName = " << ZoneName);
1240 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1241 ASSERT(!CORBA::is_nil(myZone));
1243 int ZoneType = myZone->GetZoneType();
1244 MESSAGE ( "... ZoneType = " << ZoneType);
1245 HOMARD::double_array* zone = myZone->GetCoords();
1246 if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
1248 myDriver->TexteZone(NumZone+1, ZoneType, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.);
1250 else if ( ZoneType == 4 ) // Cas d une sphere
1252 myDriver->TexteZone(NumZone+1, ZoneType, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.);
1254 else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
1256 myDriver->TexteZone(NumZone+1, ZoneType, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.);
1258 else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
1260 myDriver->TexteZone(NumZone+1, ZoneType, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]);
1262 else { ASSERT("ZoneType est incorrect." == 0) ; }
1265 // E.3. Ajout des informations liees aux champs eventuels
1268 // Le fichier du champ
1269 char* FieldFile = myIteration->GetFieldFile();
1270 MESSAGE ( ". FieldFile = " << FieldFile );
1271 if (strlen(FieldFile) == 0)
1273 // GERALD -- QMESSAGE BOX
1274 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1275 ASSERT("The file for the field is not given." == 0);
1277 // Les caracteristiques d'instants
1278 int TimeStep = myIteration->GetTimeStep();
1279 MESSAGE( ". TimeStep = " << TimeStep );
1280 int Rank = myIteration->GetRank();
1281 MESSAGE( ". Rank = " << Rank );
1282 // Les informations sur les champ
1283 HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
1285 const char* FieldName = aInfosHypo->FieldName;
1287 int TypeThR = aInfosHypo->TypeThR;
1288 double ThreshR = aInfosHypo->ThreshR;
1289 int TypeThC = aInfosHypo->TypeThC;
1290 double ThreshC = aInfosHypo->ThreshC;
1291 // Saut entre mailles ou non ?
1292 int UsField = aInfosHypo->UsField;
1293 MESSAGE( ". UsField = " << UsField );
1294 // L'usage des composantes
1295 int UsCmpI = aInfosHypo->UsCmpI;
1296 MESSAGE( ". UsCmpI = " << UsCmpI );
1298 myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
1301 HOMARD::listeComposantsHypo* mescompo = myHypo->GetListComp();
1302 int numberOfCompos = mescompo->length();
1303 MESSAGE( ". numberOfCompos = " << numberOfCompos );
1304 for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
1306 std::string nomCompo = std::string((*mescompo)[NumeComp]);
1307 MESSAGE( "... nomCompo = " << nomCompo );
1308 myDriver->TexteCompo(NumeComp, nomCompo);
1311 // E.4. Ajout des informations liees au filtrage eventuel par les groupes
1312 HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
1313 int numberOfGroups = listeGroupes->length();
1314 MESSAGE( ". numberOfGroups = " << numberOfGroups );
1315 if (numberOfGroups > 0)
1318 for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
1320 std::string GroupName = std::string((*listeGroupes)[NumGroup]);
1321 MESSAGE( "... GroupName = " << GroupName );
1322 myDriver->TexteGroup(GroupName);
1326 // E.5. Ajout des informations liees a l'eventuel suivi de frontiere
1327 // On ecrit d'abord la definition des frontieres, puis les liens avec les groupes
1328 std::list<std::string> ListeBoundaryTraitees ;
1329 HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
1330 int numberOfitems = ListBoundaryGroupType->length();
1331 MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
1332 int BoundaryOption = 1 ;
1333 int NumBoundaryAnalytical = 0 ;
1334 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1336 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1337 MESSAGE ( "... BoundaryName = " << BoundaryName);
1339 std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
1340 while (it != ListeBoundaryTraitees.end())
1342 MESSAGE ( "... BoundaryNameTraitee = " << *it);
1343 if ( BoundaryName == *it ) { A_faire = 0 ; }
1348 // Caracteristiques de la frontiere
1349 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1350 ASSERT(!CORBA::is_nil(myBoundary));
1351 int BoundaryType = myBoundary->GetBoundaryType();
1352 MESSAGE ( "... BoundaryType = " << BoundaryType );
1353 // Ecriture selon le type
1354 if (BoundaryType == 0) // Cas d une frontiere discrete
1356 const char* MeshName = myBoundary->GetMeshName() ;
1357 const char* MeshFile = myBoundary->GetMeshFile() ;
1358 myDriver->TexteBoundaryDi( MeshName, MeshFile);
1359 BoundaryOption = BoundaryOption*2 ;
1361 else // Cas d une frontiere analytique
1363 NumBoundaryAnalytical++ ;
1364 HOMARD::double_array* coor = myBoundary->GetCoords();
1365 if (BoundaryType == 1) // Cas d un cylindre
1367 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6]);
1368 BoundaryOption = BoundaryOption*3 ;
1370 else if (BoundaryType == 2) // Cas d une sphere
1372 myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0.);
1373 BoundaryOption = BoundaryOption*3 ;
1376 // Memorisation du traitement
1377 ListeBoundaryTraitees.push_back( BoundaryName );
1380 NumBoundaryAnalytical = 0 ;
1381 for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1383 std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1384 MESSAGE ( "... BoundaryName = " << BoundaryName);
1385 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1386 ASSERT(!CORBA::is_nil(myBoundary));
1387 int BoundaryType = myBoundary->GetBoundaryType();
1388 MESSAGE ( "... BoundaryType = " << BoundaryType );
1389 // Recuperation du nom du groupe
1390 std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
1391 MESSAGE ( "... GroupName = " << GroupName);
1392 if (BoundaryType == 0) // Cas d une frontiere discrete
1394 if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
1396 else // Cas d une frontiere analytique
1398 NumBoundaryAnalytical++ ;
1399 myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
1402 myDriver->TexteBoundaryOption(BoundaryOption);
1404 // E.6. Ajout des informations liees a l'eventuelle interpolation des champs
1405 MESSAGE( "... TypeFieldInterp = " << TypeFieldInterp );
1406 if (TypeFieldInterp != 0)
1408 // Le fichier des champs
1409 char* FieldFile = myIteration->GetFieldFile();
1410 MESSAGE ( ". FieldFile = " << FieldFile );
1411 if (strlen(FieldFile) == 0)
1413 // GERALD -- QMESSAGE BOX
1414 std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1415 ASSERT("The file for the field is not given." == 0);
1417 // Les caracteristiques d'instants
1418 int TimeStep = myIteration->GetTimeStep();
1419 MESSAGE( ". TimeStep = " << TimeStep );
1420 int Rank = myIteration->GetRank();
1421 MESSAGE( ". Rank = " << Rank );
1423 myDriver->TexteFieldInterp(TypeFieldInterp, FieldFile, MeshFile, TimeStep, Rank);
1425 if (TypeFieldInterp == 2)
1427 HOMARD::listFieldInterpHypo* meschamps = myHypo->GetListFieldInterp();
1428 int numberOfFields = meschamps->length();
1429 MESSAGE( ". numberOfFields = " << numberOfFields );
1430 for (int NumeChamp = 0; NumeChamp< numberOfFields; NumeChamp++)
1432 std::string nomChamp = std::string((*meschamps)[NumeChamp]);
1433 MESSAGE( "... nomChamp = " << nomChamp );
1434 myDriver->TexteFieldInterpName(NumeChamp, nomChamp);
1438 // E.7. Ajout des options avancees
1439 int Pyram = myCase->GetPyram();
1440 MESSAGE ( ". Pyram = " << Pyram );
1441 int NivMax = myHypo->GetNivMax();
1442 MESSAGE ( ". NivMax = " << NivMax );
1443 double DiamMin = myHypo->GetDiamMin() ;
1444 MESSAGE ( ". DiamMin = " << DiamMin );
1445 myDriver->TexteAdvanced(Pyram, NivMax, DiamMin);
1447 // F. Ecriture du texte dans le fichier
1450 myDriver->CreeFichier();
1455 int codretexec = 12 ;
1458 codretexec = myDriver->ExecuteHomard();
1460 MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
1461 if (codretexec == 0)
1463 SetEtatIter(nomIteration,true);
1467 // GERALD -- QMESSAGE BOX
1468 SetEtatIter(nomIteration,false);
1472 // H. Gestion des resultats
1475 // H.1. Le fichier des messages, dans tous les cas
1476 std::stringstream saux1 ;
1477 saux1 << "Mess " << NumeIter ;
1478 PublishFileUnderIteration(nomIteration, MessFile.c_str(), saux1.str().c_str());
1480 // H.2. Si tout s'est bien passe :
1481 if (codretexec == 0)
1483 // H.2.1. Le fichier de bilan
1484 std::stringstream saux2 ;
1485 saux2 << "Summary " << NumeIter ;
1486 std::string SummaryFile = DirCompute.str() + "/apad." + siterp1 + ".bilan" ;
1487 PublishFileUnderIteration(nomIteration, SummaryFile.c_str(), saux2.str().c_str());
1488 // H.2.2. Le fichier de maillage obtenu
1489 std::stringstream saux0 ;
1490 saux0 <<"Iteration " << NumeIter ;
1491 PublishFileUnderIteration(nomIteration, MeshFile, saux0.str().c_str());
1492 PublishResultInSmesh(MeshFile, 1);
1494 // H.3 Message d'erreur en cas de probleme
1497 SALOME::ExceptionStruct es;
1498 es.type = SALOME::BAD_PARAM;
1499 std::string text = "Error during the adaptation.\n" ;
1502 ifstream fichier(MessFile.c_str(), ios::in);
1504 while(getline(fichier, ligne) and (ligne != "===== HOMARD ===== STOP ====="));
1505 while (getline(fichier, ligne)) { text += ligne+ "\n";};
1508 text += "no log file ....";
1510 es.text = CORBA::string_dup(text.c_str());
1511 throw SALOME::SALOME_Exception(es);
1524 //===========================================================================
1525 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
1526 SALOMEDS::SObject_ptr theSObject,
1527 CORBA::Object_ptr theObject,
1528 const char* theName)
1530 MESSAGE("PublishInStudy pour " << theName);
1531 SALOMEDS::SObject_var aResultSO;
1532 if (CORBA::is_nil(theStudy))
1534 SALOME::ExceptionStruct es;
1535 es.type = SALOME::BAD_PARAM;
1536 es.text = "Invalid Study Context ";
1537 throw SALOME::SALOME_Exception(es);
1541 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
1542 // Rq : Iteration est publiee ailleurs
1543 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(theObject);
1544 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
1545 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
1546 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
1548 addInStudy(theStudy);
1550 // Controle de la non publication d'un objet de meme nom
1551 if ((!aHypo->_is_nil()) or (!aZone->_is_nil()) or (!aBoundary->_is_nil()))
1553 SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
1554 if (listSO->length() >= 1)
1556 MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
1557 std::cerr <<"This name "<<theName<<" is already used "<<listSO->length()<<" time(s)" << std::endl;
1558 aResultSO = listSO[0];
1559 return aResultSO._retn();
1563 // Caracteristiques de l'etude
1564 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1565 aStudyBuilder->NewCommand();
1566 if(!aCase->_is_nil())
1567 aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
1568 else if(!aHypo->_is_nil())
1569 aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
1570 else if(!aZone->_is_nil())
1571 aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
1572 else if(!aBoundary->_is_nil())
1573 aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
1575 aStudyBuilder->CommitCommand();
1576 return aResultSO._retn();
1578 //=============================================================================
1579 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
1580 SALOMEDS::StudyBuilder_var aStudyBuilder,
1581 HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
1583 MESSAGE("PublishCaseInStudy pour "<<theName);
1584 SALOMEDS::SObject_var aResultSO;
1585 SALOMEDS::GenericAttribute_var anAttr;
1587 if (CORBA::is_nil(theObject)) {
1588 MESSAGE("HOMARD_Gen_i.cxx::theObject->_is_nil()");
1589 return aResultSO._retn();
1591 if (theStudy->_is_nil()) {
1592 MESSAGE("HOMARD_Gen_i.cxx::theStudy->_is_nil()");
1593 return aResultSO._retn();
1596 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1597 if (theFatherHomard->_is_nil())
1599 MESSAGE("theFatherHomard->_is_nil()");
1600 return aResultSO._retn();
1603 aResultSO = aStudyBuilder->NewObject(theFatherHomard);
1604 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
1605 _orb->object_to_string(theObject) ) ;
1606 return aResultSO._retn();
1609 //=============================================================================
1610 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
1611 SALOMEDS::StudyBuilder_var aStudyBuilder,
1612 HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
1614 MESSAGE("PublishZoneStudy pour "<<theName);
1615 SALOMEDS::SObject_var aResultSO;
1616 SALOMEDS::GenericAttribute_var anAttr;
1618 if (CORBA::is_nil(theObject))
1620 MESSAGE("HOMARD_Gen_i.cxx::theObject->_is_nil()");
1621 return aResultSO._retn();
1623 if (theStudy->_is_nil())
1625 MESSAGE("HOMARD_Gen_i.cxx::theStudy->_is_nil()");
1626 return aResultSO._retn();
1628 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1629 if (theFatherHomard->_is_nil())
1631 MESSAGE("theFatherHomard->_is_nil()");
1632 return aResultSO._retn();
1635 // Caracteristique de la zone
1636 HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
1637 CORBA::Long ZoneType = myZone->GetZoneType();
1639 // On ajoute la categorie des zones dans l etude si necessaire
1640 SALOMEDS::SObject_var aSOZone;
1641 if (!theFatherHomard->FindSubObject(100, aSOZone))
1643 MESSAGE("Ajout de la categorie des zones");
1644 aSOZone = aStudyBuilder->NewObjectToTag(theFatherHomard, 100);
1645 PublishInStudyAttr(aStudyBuilder, aSOZone, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
1647 else { MESSAGE("La categorie des zones existe deja."); }
1649 aResultSO = aStudyBuilder->NewObject(aSOZone);
1658 { icone = "boxdxy_2.png" ;
1662 { icone = "boxdxyz_2.png" ;
1670 { icone = "disk_2.png" ;
1674 { icone = "spherepoint_2.png" ;
1678 { icone = "cylinderpointvector_2.png" ;
1686 { icone = "diskwithhole_2.png" ;
1690 { icone = "pipe_2.png" ;
1694 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone, _orb->object_to_string(theObject) ) ;
1696 return aResultSO._retn();
1698 //=============================================================================
1699 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
1700 SALOMEDS::StudyBuilder_var aStudyBuilder,
1701 HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
1703 MESSAGE("PublishBoundaryStudy pour "<<theName);
1704 SALOMEDS::SObject_var aResultSO;
1705 SALOMEDS::GenericAttribute_var anAttr;
1707 // Caracteristique de la Boundary
1708 HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
1710 // On recupere le module pere dans l etude
1711 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1712 if (theFatherHomard->_is_nil())
1714 MESSAGE("theFatherHomard->_is_nil()");
1715 return aResultSO._retn();
1718 // On ajoute la categorie des boundarys dans l etude si necessaire
1719 SALOMEDS::SObject_var aSOBoundary;
1720 if (!theFatherHomard->FindSubObject(101, aSOBoundary))
1722 MESSAGE("Ajout de la categorie des boundarys");
1723 aSOBoundary = aStudyBuilder->NewObjectToTag(theFatherHomard, 101);
1724 PublishInStudyAttr(aStudyBuilder, aSOBoundary, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
1726 else { MESSAGE("La categorie des boundarys existe deja."); }
1728 aResultSO = aStudyBuilder->NewObject(aSOBoundary);
1729 CORBA::Long BoundaryType = myBoundary->GetBoundaryType();
1730 // MESSAGE("BoundaryType : "<<BoundaryType);
1733 switch (BoundaryType)
1736 { value = "BoundaryDiHomard" ;
1737 icone = "mesh_tree_mesh.png" ;
1741 { value = "BoundaryAnHomard" ;
1742 icone = "cylinderpointvector_2.png" ;
1746 { value = "BoundaryAnHomard" ;
1747 icone = "spherepoint_2.png" ;
1751 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value, icone, _orb->object_to_string(theObject));
1752 return aResultSO._retn();
1755 //=============================================================================
1756 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
1757 SALOMEDS::StudyBuilder_var aStudyBuilder,
1758 HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
1760 MESSAGE("PublishHypotheseInStudy pour "<<theName);
1761 SALOMEDS::SObject_var aResultSO;
1762 SALOMEDS::GenericAttribute_var anAttr;
1764 // On recupere le module pere dans l etude
1765 // On ajoute la categorie des hypotheses dans l etude si necessaire
1766 SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1767 if (theFatherHomard->_is_nil())
1769 MESSAGE("theFatherHomard->_is_nil()");
1770 return aResultSO._retn();
1772 SALOMEDS::SObject_var aSOHypothese;
1773 if (!theFatherHomard->FindSubObject(0, aSOHypothese))
1775 MESSAGE("Ajout de la categorie des hypotheses");
1776 aSOHypothese = aStudyBuilder->NewObjectToTag(theFatherHomard, 0);
1777 PublishInStudyAttr(aStudyBuilder, aSOHypothese, "Hypothesis", "HypoList","hypotheses.png", NULL);
1779 else { MESSAGE("La categorie des hypotheses existe deja."); }
1781 // Creation du resultat dans l'etude
1782 aResultSO = aStudyBuilder->NewObject(aSOHypothese);
1783 PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
1785 return aResultSO._retn();
1787 //===========================================================================
1788 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
1789 SALOMEDS::SObject_var aResultSO,
1790 const char* name, const char* value, const char* icone, const char* ior)
1792 SALOMEDS::GenericAttribute_var anAttr ;
1796 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
1797 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
1798 aNameAttrib->SetValue(name);
1801 // Ajout du commentaire
1802 if ( value != NULL )
1804 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
1805 SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
1806 aCommentAttrib->SetValue(value);
1810 if ( icone != NULL )
1812 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO,"AttributePixMap");
1813 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
1814 aPixmap->SetPixMap(icone);
1820 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
1821 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1822 anIOR->SetValue(ior);
1826 //=============================================================================
1827 HOMARD::listeCases* HOMARD_Gen_i::GetAllCases()
1829 MESSAGE("GetAllCases");
1832 HOMARD::listeCases_var ret = new HOMARD::listeCases;
1833 ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
1834 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
1836 for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
1837 it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
1839 ret[i++] = CORBA::string_dup((*it).first.c_str());
1845 //=============================================================================
1846 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypotheses()
1848 MESSAGE("GetAllHypotheses");
1851 HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
1852 ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
1853 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
1855 for (it = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
1856 it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
1858 ret[i++] = CORBA::string_dup((*it).first.c_str());
1864 //=============================================================================
1865 HOMARD::listeZones* HOMARD_Gen_i::GetAllZones()
1867 MESSAGE("GetAllZones");
1870 HOMARD::listeZones_var ret = new HOMARD::listeZones;
1871 ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
1872 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
1874 for (it = myContextMap[GetCurrentStudyID()]._mesZones.begin();
1875 it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
1877 ret[i++] = CORBA::string_dup((*it).first.c_str());
1883 //=============================================================================
1884 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterations()
1886 MESSAGE("GetAllIterations");
1889 HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
1890 ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
1891 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
1893 for (it = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
1894 it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
1896 ret[i++] = CORBA::string_dup((*it).first.c_str());
1901 //=============================================================================
1902 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarys()
1904 MESSAGE("GetAllBoundarys");
1907 HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
1908 ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
1909 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
1911 for (it = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
1912 it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
1914 ret[i++] = CORBA::string_dup((*it).first.c_str());
1920 //=============================================================================
1921 char* HOMARD_Gen_i::GetCaseName(const char* nomIteration)
1923 if (CORBA::is_nil(myCurrentStudy))
1925 SALOME::ExceptionStruct es;
1926 es.type = SALOME::BAD_PARAM;
1927 es.text = "Invalid Study Context ";
1928 throw SALOME::SALOME_Exception(es);
1932 HOMARD::HOMARD_Iteration_var monIter = myContextMap[GetCurrentStudyID()]._mesIterations[nomIteration];
1933 ASSERT(!CORBA::is_nil(monIter));
1934 return CORBA::string_dup(monIter->GetCaseName());
1936 //=============================================================================
1937 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long IconeType)
1939 MESSAGE( "PublishResultInSmesh " << NomFich);
1940 if (CORBA::is_nil(myCurrentStudy))
1942 SALOME::ExceptionStruct es;
1943 es.type = SALOME::BAD_PARAM;
1944 es.text = "Invalid Study Context ";
1945 throw SALOME::SALOME_Exception(es);
1949 // Le module SMESH est-il actif ?
1950 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
1952 if (!CORBA::is_nil(aSmeshSO))
1954 // On verifie que le fichier n est pas deja publie
1955 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
1956 for (; aIter->More(); aIter->Next())
1958 SALOMEDS::SObject_var aSO = aIter->Value();
1959 SALOMEDS::GenericAttribute_var aGAttr;
1960 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
1962 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
1963 CORBA::String_var value=anAttr->Value();
1964 if (strcmp((const char*)value,NomFich) == 0)
1966 // GERALD -- QMESSAGE BOX
1967 std::cerr << "fichier : "<< NomFich << " deja publie "<< std::endl;
1975 // On enregistre le fichier
1976 MESSAGE( "Enregistrement du fichier");
1977 SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
1978 SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
1979 ASSERT(!CORBA::is_nil(aSmeshEngine));
1980 aSmeshEngine->SetCurrentStudy(myCurrentStudy);
1981 SMESH::DriverMED_ReadStatus theStatus;
1982 //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
1984 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
1985 SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
1986 for (int i = 0; i < mesMaillages->length(); i++)
1988 MESSAGE( ". Mise a jour des attributs du maillage");
1989 SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
1990 SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
1991 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1992 SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
1993 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
1994 anAttr->SetValue(NomFich);
1995 SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
1996 SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
1997 // IconeType = 0 : fichier issu d'une importation
1998 // IconeType = 1 : fichier issu d'une execution HOMARD
2000 if ( IconeType == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
2001 else { icone = "mesh_tree_mesh.png" ; }
2002 anAttr2->SetPixMap( icone );
2006 //=============================================================================
2007 void HOMARD_Gen_i::DeleteResultInSmesh(const char* NomFich, const char* MeshName)
2009 MESSAGE (" DeleteResultInSmesh pour "<< NomFich << "et le maillage "<< MeshName);
2010 if (CORBA::is_nil(myCurrentStudy))
2012 SALOME::ExceptionStruct es;
2013 es.type = SALOME::BAD_PARAM;
2014 es.text = "Invalid Study Context ";
2015 throw SALOME::SALOME_Exception(es);
2019 // Le module SMESH est-il actif ?
2020 SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
2022 if (CORBA::is_nil(aSmeshSO))
2026 // On verifie que le fichier est deja publie
2027 SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
2028 SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
2029 for (; aIter->More(); aIter->Next())
2031 SALOMEDS::SObject_var aSO = aIter->Value();
2032 SALOMEDS::GenericAttribute_var aGAttr;
2033 if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
2035 SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2036 CORBA::String_var value=anAttr->Value();
2037 if (strcmp((const char*)value,NomFich) == 0)
2039 if (aSO->FindAttribute(aGAttr,"AttributeName"))
2041 SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
2042 CORBA::String_var value2=anAttr2->Value();
2043 if (strcmp((const char*)value2,MeshName) == 0)
2045 myBuilder->RemoveObjectWithChildren( aSO ) ;
2053 //=============================================================================
2054 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
2056 if (CORBA::is_nil(myCurrentStudy))
2058 SALOME::ExceptionStruct es;
2059 es.type = SALOME::BAD_PARAM;
2060 es.text = "Invalid Study Context ";
2061 throw SALOME::SALOME_Exception(es);
2065 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
2066 if (CORBA::is_nil(myIteration))
2068 SALOME::ExceptionStruct es;
2069 es.type = SALOME::BAD_PARAM;
2070 es.text = "Invalid Iteration ";
2071 throw SALOME::SALOME_Exception(es);
2074 SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
2075 if (CORBA::is_nil(myIteration))
2077 SALOME::ExceptionStruct es;
2078 es.type = SALOME::BAD_PARAM;
2079 es.text = "Invalid Iteration Study Object";
2080 throw SALOME::SALOME_Exception(es);
2084 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2086 aStudyBuilder->NewCommand();
2088 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
2089 // Pour les fichiers med, on affiche une icone de maillage
2090 // Pour les fichiers qui sont texte, on affiche une icone de fichier texte 'texte'
2091 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
2093 const char* ior = " " ;
2094 if ( Commentaire[0] == 'I' )
2095 { icone = "med.png" ; }
2097 { icone = "texte_2.png" ; }
2098 PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone, ior ) ;
2100 aStudyBuilder->CommitCommand();
2103 //=====================================================================================
2104 void HOMARD_Gen_i::IsValidStudy( )
2105 //=====================================================================================
2107 MESSAGE( "IsValidStudy" );
2108 if (CORBA::is_nil(myCurrentStudy))
2110 SALOME::ExceptionStruct es;
2111 es.type = SALOME::BAD_PARAM;
2112 es.text = "Invalid Study Context";
2113 throw SALOME::SALOME_Exception(es);
2118 //===========================================================================
2120 // Next functions are inherited from SALOMEDS::Driver interface
2122 //===========================================================================
2124 //===========================================================================
2125 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
2127 CORBA::Boolean isMultiFile)
2129 MESSAGE (" Save pour theURL = "<< theURL);
2130 SALOMEDS::TMPFile_var aStreamFile;
2132 // get temporary directory name
2133 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2135 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2136 StudyContext& context = myContextMap[ aStudy->StudyId() ];
2138 // HOMARD data file name
2139 std::string aFileName = "";
2141 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2142 aFileName += "_HOMARD.dat";
2144 // initialize sequence of file names
2145 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
2146 aFileSeq->length(1);
2147 aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
2149 // get full path to the data file
2150 aFileName = tmpDir + aFileName;
2154 std::ofstream f(aFileName.c_str());
2156 // clear temporary id map
2157 context._idmap.clear();
2162 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
2163 for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
2164 HOMARD::HOMARD_Cas_var aCas = it_case->second;
2165 PortableServer::ServantBase_var aServant = GetServant(aCas);
2166 HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2168 f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
2169 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
2173 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2174 for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
2175 HOMARD::HOMARD_Zone_var aZone = it_zone->second;
2176 PortableServer::ServantBase_var aServant = GetServant(aZone);
2177 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2179 f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
2180 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2183 // -> dump hypotheses
2184 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2185 for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
2186 HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
2187 PortableServer::ServantBase_var aServant = GetServant(aHypo);
2188 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2190 f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
2191 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2194 // -> dump iterations
2195 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2196 for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
2197 HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
2198 PortableServer::ServantBase_var aServant = GetServant(aIter);
2199 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2201 f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
2202 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2205 // -> dump boundaries
2206 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2207 for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
2208 HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
2209 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2210 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2211 if (aBoundaryServant) {
2212 f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
2213 context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2217 MESSAGE ("close file");
2220 // put temporary files to the stream
2221 MESSAGE ("put temporary files to the stream");
2222 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
2224 // remove temporary files
2225 MESSAGE ("remove temporary files");
2226 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2228 // return data stream
2229 MESSAGE ("return data stream");
2230 return aStreamFile._retn();
2233 //===========================================================================
2234 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
2236 CORBA::Boolean isMultiFile)
2238 // No specific ASCII persistence
2239 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
2240 return aStreamFile._retn();
2243 //===========================================================================
2244 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
2245 const SALOMEDS::TMPFile& theStream,
2247 CORBA::Boolean isMultiFile)
2249 MESSAGE (" Load pour theURL = "<< theURL);
2250 SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2252 // set current study
2253 if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
2254 SetCurrentStudy(aStudy);
2256 // get temporary directory name
2257 std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2259 // Convert the stream into sequence of files to process
2260 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
2263 // HOMARD data file name
2264 std::string aFileName = "";
2266 aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2267 aFileName = tmpDir + aFileName + "_HOMARD.dat";
2269 StudyContext& context = myContextMap[ aStudy->StudyId() ];
2273 std::ifstream f(aFileName.c_str());
2276 context._mesCas.clear();
2277 context._mesHypotheses.clear();
2278 context._mesIterations.clear();
2279 context._mesZones.clear();
2280 context._mesBoundarys.clear();
2281 context._idmap.clear();
2287 std::getline(f, line);
2288 std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
2289 std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
2290 std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
2291 std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
2292 std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
2293 if (line.substr(0, caseSignature.size()) == caseSignature) {
2295 MESSAGE (" Recreation du cas" );
2296 HOMARD::HOMARD_Cas_var aCase = newCase();
2297 PortableServer::ServantBase_var aServant = GetServant(aCase);
2298 HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2299 if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
2300 context._mesCas[aCase->GetName()] = aCase;
2301 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
2304 else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
2305 MESSAGE (" Recreation de la zone" );
2307 HOMARD::HOMARD_Zone_var aZone = newZone();
2308 PortableServer::ServantBase_var aServant = GetServant(aZone);
2309 HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2310 if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
2311 context._mesZones[aZone->GetName()] = aZone;
2312 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2315 else if (line.substr(0, iterSignature.size()) == iterSignature) {
2316 // re-create iteration
2317 MESSAGE (" Recreation de l iteration" );
2318 HOMARD::HOMARD_Iteration_var aIter = newIteration();
2319 PortableServer::ServantBase_var aServant = GetServant(aIter);
2320 HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2321 if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
2322 context._mesIterations[aIter->GetName()] = aIter;
2323 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2326 else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
2327 // re-create hypothesis
2328 MESSAGE (" Recreation de l hypothese" );
2329 HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
2330 PortableServer::ServantBase_var aServant = GetServant(aHypo);
2331 HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2332 if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
2333 context._mesHypotheses[aHypo->GetName()] = aHypo;
2334 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2337 else if (line.substr(0, bounSignature.size()) == bounSignature) {
2338 // re-create boundary
2339 MESSAGE (" Recreation de la frontiere" );
2340 HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
2341 PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2342 HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2343 if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
2344 context._mesBoundarys[aBoundary->GetName()] = aBoundary;
2345 context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2354 // Remove temporary files created from the stream
2356 SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2361 //===========================================================================
2362 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
2363 const SALOMEDS::TMPFile& theStream,
2365 CORBA::Boolean isMultiFile)
2367 // No specific ASCII persistence
2368 return Load(theComponent, theStream, theURL, isMultiFile);
2371 //===========================================================================
2372 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
2374 if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
2375 // clearing study context should be done here:
2376 // - destroy all servants and related CORBA objects
2378 // - remove context from myContextMap
2379 myContextMap.erase(theComponent->GetStudy()->StudyId());
2380 // - nullify myCurrentStudy
2381 myCurrentStudy = SALOMEDS::Study::_nil();
2385 //===========================================================================
2386 char* HOMARD_Gen_i::ComponentDataType()
2388 return CORBA::string_dup("HOMARD");
2391 //===========================================================================
2392 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
2393 const char* IORString,
2394 CORBA::Boolean isMultiFile,
2395 CORBA::Boolean isASCII)
2397 CORBA::String_var aString("");
2398 if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
2399 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2400 CORBA::Object_var anObj = _orb->string_to_object(IORString);
2401 if (!CORBA::is_nil(anObj)) {
2402 PortableServer::ServantBase_var aServant = GetServant(anObj);
2403 PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
2405 std::map<int, PortableServer::ServantBase*>::const_iterator it;
2406 for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
2407 if (it->second == aStorable) {
2408 std::stringstream os;
2410 aString = CORBA::string_dup(os.str().c_str());
2416 return aString._retn();
2419 //===========================================================================
2420 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
2421 const char* aLocalPersistentID,
2422 CORBA::Boolean isMultiFile,
2423 CORBA::Boolean isASCII)
2425 CORBA::String_var aString("");
2426 if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
2427 StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2428 int id = atoi(aLocalPersistentID);
2429 if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
2430 CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
2431 if (!CORBA::is_nil(object)) {
2432 aString = _orb->object_to_string(object);
2436 return aString._retn();
2439 //===========================================================================
2440 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
2442 if(CORBA::is_nil(myCurrentStudy))
2445 HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
2446 if(!aCas->_is_nil())
2449 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
2450 if(!aHypo->_is_nil())
2453 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
2454 if(!aZone->_is_nil())
2457 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
2458 if(!aBoundary->_is_nil())
2461 /* Iteration is not published directly
2462 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
2463 if(!aIter->_is_nil())
2469 //===========================================================================
2470 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
2472 // No Copy/Paste support
2476 //===========================================================================
2477 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
2478 CORBA::Long& theObjectID)
2480 // No Copy/Paste support
2481 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
2482 return aStreamFile._retn();
2485 //===========================================================================
2486 CORBA::Boolean HOMARD_Gen_i::CanPaste(const char *theComponentName,
2487 CORBA::Long theObjectID)
2489 // No Copy/Paste support
2493 //===========================================================================
2494 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
2495 CORBA::Long theObjectID,
2496 SALOMEDS::SObject_ptr theSObject)
2498 // No Copy/Paste support
2499 SALOMEDS::SObject_var aResultSO;
2500 return aResultSO._retn();
2503 //===========================================================================
2504 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
2506 PortableServer::Servant aServant = 0;
2507 if (!CORBA::is_nil(theObject)) {
2509 aServant = _poa->reference_to_servant(theObject);
2517 //===========================================================================
2518 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
2520 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2521 HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
2522 HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
2523 return aCase._retn();
2526 //===========================================================================
2527 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
2529 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2530 HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
2531 HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
2532 return aHypo._retn();
2535 //===========================================================================
2536 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
2538 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2539 HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
2540 HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
2541 return aIter._retn();
2544 //===========================================================================
2545 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
2547 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2548 HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
2549 HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
2550 return aBoundary._retn();
2552 //===========================================================================
2553 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
2555 HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2556 HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
2557 HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
2558 return aZone._retn();
2560 //==========================================================================
2561 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
2562 CORBA::Boolean isPublished,
2563 CORBA::Boolean isMultiFile,
2564 CORBA::Boolean& isValidScript)
2566 MESSAGE ("Entree dans DumpPython");
2568 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
2569 if(CORBA::is_nil(aStudy))
2570 return new Engines::TMPFile(0);
2572 SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
2573 if(CORBA::is_nil(aSO))
2574 return new Engines::TMPFile(0);
2576 std::string aScript = "\"\"\"\n";
2577 aScript += "Python script for HOMARD\n";
2578 aScript += "Copyright EDF-R&D 2010\n";
2579 aScript += "\"\"\"\n";
2580 aScript += "__revision__ = \"V1.2\"\n";
2581 aScript += "import HOMARD\n";
2583 aScript += "import salome\n";
2584 aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
2586 aScript += "def RebuildData(theStudy):\n";
2587 aScript += "\thomard.SetCurrentStudy(theStudy)\n";
2590 aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
2593 if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
2595 aScript += "#\n# Creation of the boundaries";
2596 aScript += "\n# ==========================";
2598 std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2599 for (it_boundary = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
2600 it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
2602 HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
2603 CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
2604 std::string dumpBoundary = dumpCorbaBoundary.in();
2605 aScript+=dumpBoundary;
2609 if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
2611 aScript += "#\n# Creation of the zones";
2612 aScript += "\n# =====================";
2614 std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2615 for ( it_zone = myContextMap[GetCurrentStudyID()]._mesZones.begin();
2616 it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
2618 HOMARD::HOMARD_Zone_var maZone = (*it_zone).second;
2619 CORBA::String_var dumpCorbaZone = maZone->GetDumpPython();
2620 std::string dumpZone = dumpCorbaZone.in();
2625 aScript += "#\n# Creation of the hypotheses";
2626 aScript += "\n# ==========================";
2627 std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2628 for ( it_hypo = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
2629 it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
2631 HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
2632 CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
2633 std::string dumpHypo = dumpCorbaHypo.in();
2638 aScript += "#\n# Creation of the cases";
2639 aScript += "\n# =====================";
2640 std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
2641 for (it_cas = myContextMap[GetCurrentStudyID()]._mesCas.begin();
2642 it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
2644 std::string nomCas = (*it_cas).first;
2645 std::string dumpCas = std::string("\n# Creation of the case ") ;
2646 dumpCas += nomCas + std::string("\n");
2647 dumpCas += std::string("\t") + nomCas;
2648 dumpCas += std::string(" = homard.CreateCase('") + nomCas + std::string("', '");
2650 HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
2651 CORBA::String_var cIter0= myCase->GetIter0Name();
2652 std::string iter0 = cIter0.in();
2654 HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
2655 CORBA::String_var cMesh0= myIteration->GetMeshFile();
2656 std::string mesh0 = cMesh0.in();
2657 CORBA::String_var cMeshName0= myIteration->GetMeshName();
2658 std::string meshName0 = cMeshName0.in();
2659 dumpCas += meshName0 + std::string("', '")+ mesh0 + std::string("')\n");
2660 CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
2661 std::string dumpCas2= dumpCorbaCase.in();
2663 aScript+=dumpCas + dumpCas2;
2667 aScript += "#\n# Creation of the iterations" ;
2668 aScript += "\n# ==========================";
2669 std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2670 for (it_iter = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
2671 it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
2673 HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
2674 CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
2675 std::string dumpIter = dumpCorbaIter.in();
2680 aScript += "\n\tpass";
2683 if( !isMultiFile ) // remove unnecessary tabulation
2684 aScript = RemoveTabulation( aScript );
2686 const size_t aLen = strlen(aScript.c_str());
2687 char* aBuffer = new char[aLen+1];
2688 strcpy(aBuffer, aScript.c_str());
2690 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
2691 Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
2693 return aStreamFile._retn();
2696 //=============================================================================
2699 PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
2700 PortableServer::POA_ptr poa,
2701 PortableServer::ObjectId* contId,
2702 const char* instanceName,
2703 const char* interfaceName)
2705 MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
2706 HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
2707 return myHOMARD_Gen->getId();