Back to index

salome-med  6.5.0
MEDMEM_Field_i.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //=============================================================================
00024 // File      : MEDMEM_Field_i.cxx
00025 // Created   : mer fév 20 15:47:57 CET 2002
00026 // Author    : EDF
00027 // Project   : SALOME
00028 //=============================================================================
00029 
00030 #include "MEDMEM_Field_i.hxx"
00031 
00032 #include "SALOME_NamingService.hxx"
00033 #include "SALOME_LifeCycleCORBA.hxx"
00034 
00035 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
00036 #include CORBA_CLIENT_HEADER(MED_Gen)
00037 
00038 using namespace MEDMEM;
00039 using namespace MED_EN;
00040 
00041 map < int, ::FIELD_ * > FIELD_i::fieldMap ;
00042 int  FIELD_i::fieldIndex = 0;
00043 
00044 //=============================================================================
00048 //=============================================================================
00049 
00050 //FIELD_i::FIELD_i():_fieldTptr(FIELD_i::constructConstField())
00051 FIELD_i::FIELD_i():_fieldTptr(constructConstField()),_corbaIndex(FIELD_i::fieldIndex++)
00052 {
00053 }
00054 //=============================================================================
00058 //=============================================================================
00059 FIELD_i::~FIELD_i()
00060 {
00061   if ( _fieldTptr )
00062     _fieldTptr->removeReference();
00063   //if (_ownCppPtr) delete _fieldTptr;
00064 }
00065 //=============================================================================
00069 //=============================================================================
00070 FIELD_i::FIELD_i(::FIELD_ * const field, bool ownCppPtr):
00071   _ownCppPtr(ownCppPtr),
00072   _fieldTptr(field),
00073   _corbaIndex(FIELD_i::fieldIndex++),
00074   _FieldId("")
00075 {
00076   if ( _fieldTptr ) _fieldTptr->addReference();
00077   FIELD_i::fieldMap[_corbaIndex]=_fieldTptr;
00078 
00079   MESSAGE("FIELD_i::FIELD_i  Checking of pointeurs !!!");
00080 
00081   SCRUTE(_fieldTptr);
00082 }
00083 
00084 //=============================================================================
00088 //=============================================================================
00089 FIELD_i::FIELD_i( FIELD_i & f):_ownCppPtr(false), _fieldTptr(f._fieldTptr),
00090                                _corbaIndex(FIELD_i::fieldIndex++),
00091                                _FieldId("")
00092 {
00093   if ( _fieldTptr ) _fieldTptr->addReference();
00094   FIELD_i::fieldMap[_corbaIndex]=_fieldTptr;
00095 }
00096 //=============================================================================
00100 //=============================================================================
00101  ::FIELD_ * FIELD_i::constructConstField() const
00102 {
00103         ::FIELD_ * const ptrField =new ::FIELD_();
00104         return ptrField;
00105 }
00106 
00107 //=============================================================================
00111 //=============================================================================
00112 char * FIELD_i::getName()
00113 throw (SALOME::SALOME_Exception)
00114 {
00115         if (_fieldTptr==NULL)
00116                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00117                                              SALOME::INTERNAL_ERROR);
00118         try
00119         {
00120                 return CORBA::string_dup(_fieldTptr->getName().c_str());
00121         }
00122         catch (MEDEXCEPTION &ex)
00123         {
00124                 MESSAGE("Exception en accedant au nom");
00125                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00126         }
00127 }
00128 
00129 void FIELD_i::setName(const char* theName)
00130   throw (SALOME::SALOME_Exception)
00131 {
00132   if (_fieldTptr == NULL)
00133     THROW_SALOME_CORBA_EXCEPTION("No associated Field", SALOME::INTERNAL_ERROR);
00134 
00135   try {
00136     _fieldTptr->setName(theName);
00137   }
00138   catch (MEDEXCEPTION &ex) {
00139     MESSAGE("Exception en accedant au nom");
00140     THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00141   }
00142 }
00143 
00144 //=============================================================================
00148 //=============================================================================
00149 char * FIELD_i::getDescription()
00150 throw (SALOME::SALOME_Exception)
00151 {
00152         if (_fieldTptr==NULL)
00153                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00154                                              SALOME::INTERNAL_ERROR);
00155         try
00156         {
00157                 return CORBA::string_dup(_fieldTptr->getDescription().c_str());
00158         }
00159         catch (MEDEXCEPTION &ex)
00160         {
00161                 MESSAGE("Exception en accedant a la description");
00162                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00163         }
00164 }
00165 //=============================================================================
00169 //=============================================================================
00170 SALOME_MED::SUPPORT_ptr FIELD_i::getSupport()
00171   throw (SALOME::SALOME_Exception)
00172 {
00173   if (_fieldTptr==NULL)
00174     THROW_SALOME_CORBA_EXCEPTION("No associated Field",
00175                                  SALOME::INTERNAL_ERROR);
00176   
00177   SUPPORT_i* servant = new SUPPORT_i(_fieldTptr->getSupport());
00178 
00179   SALOME_MED::SUPPORT_ptr support=servant->_this();
00180 
00181   SCRUTE(_fieldTptr);
00182 
00183   return support ;
00184 }
00185 //=============================================================================
00189 //=============================================================================
00190 CORBA::Long FIELD_i::getNumberOfComponents()
00191 throw (SALOME::SALOME_Exception)
00192 {
00193         if (_fieldTptr==NULL)
00194                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00195                                              SALOME::INTERNAL_ERROR);
00196         try
00197         {
00198                 return _fieldTptr->getNumberOfComponents();
00199         }
00200         catch (MEDEXCEPTION &ex)
00201         {
00202                 MESSAGE("Exception en accedant au support");
00203                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00204         }
00205 }
00206 //=============================================================================
00210 //=============================================================================
00211 char * FIELD_i::getComponentName(CORBA::Long i)
00212 throw (SALOME::SALOME_Exception)
00213 {
00214         if (_fieldTptr==NULL)
00215                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00216                                              SALOME::INTERNAL_ERROR);
00217         try
00218         {
00219                 return CORBA::string_dup(_fieldTptr->getComponentName(i).c_str());
00220         }
00221         catch (MEDEXCEPTION &ex)
00222         {
00223                 MESSAGE("Exception en accedant au nom d un component");
00224                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00225         }
00226 }
00227 //=============================================================================
00231 //=============================================================================
00232 char * FIELD_i::getComponentUnit(CORBA::Long i)
00233 throw (SALOME::SALOME_Exception)
00234 {
00235         if (_fieldTptr==NULL)
00236                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00237                                              SALOME::INTERNAL_ERROR);
00238         try
00239         {
00240                 return CORBA::string_dup(_fieldTptr->getMEDComponentUnit(i).c_str());
00241         }
00242         catch (MEDEXCEPTION &ex)
00243         {
00244                 MESSAGE("Exception en accedant au nom d un component");
00245                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00246         }
00247 }
00248 //=============================================================================
00252 //=============================================================================
00253 char * FIELD_i::getComponentDescription(CORBA::Long i)
00254 throw (SALOME::SALOME_Exception)
00255 {
00256         if (_fieldTptr==NULL)
00257                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00258                                              SALOME::INTERNAL_ERROR);
00259         try
00260         {
00261                 return CORBA::string_dup(_fieldTptr->getComponentDescription(i).c_str());
00262         }
00263         catch (MEDEXCEPTION &ex)
00264         {
00265                 MESSAGE("Exception en accedant a la description d un component");
00266                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00267         }
00268 }
00269 //=============================================================================
00273 //=============================================================================
00274 CORBA::Long FIELD_i::getIterationNumber()
00275 throw (SALOME::SALOME_Exception)
00276 {
00277         if (_fieldTptr==NULL)
00278                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00279                                              SALOME::INTERNAL_ERROR);
00280         try
00281         {
00282                 return _fieldTptr->getIterationNumber();
00283         }
00284         catch (MEDEXCEPTION &ex)
00285         {
00286                 MESSAGE("Exception en accedant au champ");
00287                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00288         }
00289 }
00290 //=============================================================================
00294 //=============================================================================
00295 CORBA::Long FIELD_i::getCorbaIndex()
00296 throw (SALOME::SALOME_Exception)
00297 {
00298         if (_fieldTptr==NULL)
00299                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00300                                              SALOME::INTERNAL_ERROR);
00301         return _corbaIndex;
00302         
00303 }
00304 //=============================================================================
00308 //=============================================================================
00309 CORBA::Long FIELD_i::getOrderNumber()
00310 throw (SALOME::SALOME_Exception)
00311 {
00312         if (_fieldTptr==NULL)
00313                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00314                                              SALOME::INTERNAL_ERROR);
00315         try
00316         {
00317                 return _fieldTptr->getOrderNumber();
00318         }
00319         catch (MEDEXCEPTION &ex)
00320         {
00321                 MESSAGE("Exception en accedant au champ");
00322                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00323         }
00324 }
00325 //=============================================================================
00329 //=============================================================================
00330 CORBA::Boolean FIELD_i::getGaussPresence()
00331 {
00332        if (_fieldTptr==NULL)
00333                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00334                                              SALOME::INTERNAL_ERROR);
00335         try
00336         {
00337                 return _fieldTptr->getGaussPresence();
00338         }
00339         catch (MEDEXCEPTION &ex)
00340         {
00341                 MESSAGE("Exception en accedant au champ");
00342                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00343         }
00344 }
00345 //=============================================================================
00349 //=============================================================================
00350 CORBA::Double FIELD_i::getTime()
00351 throw (SALOME::SALOME_Exception)
00352 {
00353         if (_fieldTptr==NULL)
00354                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00355                                              SALOME::INTERNAL_ERROR);
00356         try
00357         {
00358                 return _fieldTptr->getTime();
00359         }
00360         catch (MEDEXCEPTION &ex)
00361         {
00362                 MESSAGE("Exception en accedant au champ");
00363                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00364         }
00365 }
00366 //=============================================================================
00370 //=============================================================================
00371 SALOME_TYPES::ListOfString * FIELD_i::getComponentsNames()
00372 throw (SALOME::SALOME_Exception)    
00373 {
00374         if (_fieldTptr==NULL)
00375                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00376                                              SALOME::INTERNAL_ERROR);
00377         SALOME_TYPES::ListOfString_var myseq = new SALOME_TYPES::ListOfString;
00378         try
00379         {
00380                 int nbcom = _fieldTptr->getNumberOfComponents();
00381                 myseq->length(nbcom);
00382                 const string * namecom=_fieldTptr->getComponentsNames();
00383                 for (int i=0;i<nbcom;i++)
00384                 {
00385                         myseq[i]=CORBA::string_dup(namecom[i].c_str());
00386                 }
00387         }
00388         catch (MEDEXCEPTION &ex)
00389         {
00390                 MESSAGE("Exception en accedant au champ");
00391                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00392         }
00393         return myseq._retn();
00394 }
00395 //=============================================================================
00399 //=============================================================================
00400 SALOME_TYPES::ListOfString * FIELD_i::getComponentsUnits()
00401 throw (SALOME::SALOME_Exception)
00402 {
00403         if (_fieldTptr==NULL)
00404                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00405                                              SALOME::INTERNAL_ERROR);
00406         SALOME_TYPES::ListOfString_var myseq = new SALOME_TYPES::ListOfString;
00407         try
00408         {
00409                 int nbcom = _fieldTptr->getNumberOfComponents();
00410                 myseq->length(nbcom);
00411                 const string * unitcom=_fieldTptr->getMEDComponentsUnits();
00412                 for (int i=0;i<nbcom;i++)
00413                 {
00414                         myseq[i]=CORBA::string_dup(unitcom[i].c_str());
00415                 }
00416         }
00417         catch (MEDEXCEPTION &ex)
00418         {
00419                 MESSAGE("Exception en accedant au champ");
00420                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00421         }
00422         return myseq._retn();
00423 }
00424 //=============================================================================
00428 //=============================================================================
00429 SALOME_TYPES::ListOfString * FIELD_i::getComponentsDescriptions()
00430 throw (SALOME::SALOME_Exception)    
00431 {
00432         if (_fieldTptr==NULL)
00433                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00434                                              SALOME::INTERNAL_ERROR);
00435         SALOME_TYPES::ListOfString_var myseq = new SALOME_TYPES::ListOfString;
00436         try
00437         {
00438                 int nbcom = _fieldTptr->getNumberOfComponents();
00439                 myseq->length(nbcom);
00440                 const string * namecom=_fieldTptr->getComponentsDescriptions();
00441                 for (int i=0;i<nbcom;i++)
00442                 {
00443                         myseq[i]=CORBA::string_dup(namecom[i].c_str());
00444                 }
00445         }
00446         catch (MEDEXCEPTION &ex)
00447         {
00448                 MESSAGE("Exception en accedant au champ");
00449                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00450         }
00451         return myseq._retn();
00452 }
00453 
00454 //=============================================================================
00458 //=============================================================================
00459 void FIELD_i::addInStudy (SALOMEDS::Study_ptr   myStudy, 
00460                           SALOME_MED::FIELD_ptr myIor)
00461   throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection)
00462 {
00463   SALOMEDS::SComponent_var aComponent = PublishMedComponent(myStudy);
00464   if (CORBA::is_nil(aComponent))
00465     THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'Med' not Found", SALOME::INTERNAL_ERROR);
00466   addInStudyToComponent(aComponent, myIor);
00467 }
00468 
00469 static SALOMEDS::SObject_ptr FindChildByName (SALOMEDS::SObject_ptr theFather,
00470                                               const string          theName)
00471 {
00472   SALOMEDS::SObject_var aChild;
00473   if (CORBA::is_nil(theFather))
00474     return aChild._retn();
00475 
00476   SALOMEDS::SObject_var aCurChild;
00477   SALOMEDS::ChildIterator_ptr anIter = theFather->GetStudy()->NewChildIterator(theFather);
00478   for (; anIter->More() && aChild->_is_nil(); anIter->Next()) {
00479     aCurChild = anIter->Value();
00480     string aCurName = aCurChild->GetName();
00481     if (aCurName == theName)
00482       aChild = aCurChild;
00483   }
00484   return aChild._retn();
00485 }
00486 
00487 void FIELD_i::addInStudyToComponent (SALOMEDS::SComponent_ptr myComponent,
00488                                      SALOME_MED::FIELD_ptr    myIor)
00489   throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection)
00490 {
00491         if (CORBA::is_nil(myComponent) || CORBA::is_nil(myIor))
00492           THROW_SALOME_CORBA_EXCEPTION("Null parameter", SALOME::BAD_PARAM);
00493 
00494         if (_fieldTptr == NULL)
00495           THROW_SALOME_CORBA_EXCEPTION("No associated Field", SALOME::INTERNAL_ERROR);
00496 
00497         if (_FieldId != "") {
00498           MESSAGE("Field already in Study");
00499           THROW_SALOME_CORBA_EXCEPTION("Field already in Study", SALOME::BAD_PARAM);
00500         }
00501 
00502         SALOMEDS::Study_var myStudy = myComponent->GetStudy();
00503         SALOMEDS::StudyBuilder_var aBuilder = myStudy->NewBuilder();
00504 
00505         SALOMEDS::GenericAttribute_var anAttr;
00506         SALOMEDS::AttributeName_var    aName;
00507         SALOMEDS::AttributeIOR_var     aIOR;
00508 
00509         // Create SObject labelled 'MEDFIELD' if it doesn't already exist
00510         SALOMEDS::Study::ListOfSObject_var aMEDFIELDs =
00511           myStudy->FindObjectByName("MEDFIELD", myComponent->ComponentDataType());
00512         int aLength = aMEDFIELDs->length();
00513         SALOMEDS::SObject_var medfieldfather;
00514         if (aLength > 0) {
00515           medfieldfather = aMEDFIELDs[0];
00516         }
00517         else {
00518           MESSAGE("Add Object 'MEDFIELD'");
00519           medfieldfather = aBuilder->NewObject(myComponent);
00520           anAttr = aBuilder->FindOrCreateAttribute(medfieldfather, "AttributeName");
00521           aName = SALOMEDS::AttributeName::_narrow(anAttr);
00522           aName->SetValue("MEDFIELD");
00523         }
00524 
00525         // Create SObject labelled 'FIELDNAME' if it doesn't already exit
00526         string fieldName = _fieldTptr->getName();
00527         SALOMEDS::SObject_var medfieldnamefather = FindChildByName(medfieldfather, fieldName);
00528         if ( CORBA::is_nil(medfieldnamefather) ) 
00529         {
00530           MESSAGE("Add Object "<<fieldName);
00531           medfieldnamefather = aBuilder->NewObject(medfieldfather);
00532           anAttr = aBuilder->FindOrCreateAttribute(medfieldnamefather, "AttributeName");
00533           aName = SALOMEDS::AttributeName::_narrow(anAttr);
00534           aName->SetValue(fieldName.c_str());
00535         }
00536 
00537         string fieldEntryPath = "/";
00538         //fieldEntryPath += "Med/";
00539         string componentName = myComponent->GetName();
00540         fieldEntryPath += componentName + "/MEDFIELD/" + fieldName + "/";
00541 
00542         int iterationNumber = _fieldTptr->getIterationNumber();
00543         SCRUTE(iterationNumber);
00544 
00545         int orderNumber = _fieldTptr->getOrderNumber();
00546         SCRUTE(orderNumber);
00547 
00548         ostringstream iterationName;
00549         iterationName<<"(" << iterationNumber << "," << orderNumber << ")";
00550         string supportName = (_fieldTptr->getSupport())->getName();
00551         string meshName = ((_fieldTptr->getSupport())->getMesh())->getName();
00552 
00553         SCRUTE(meshName);
00554         for (string::size_type pos=0; pos<meshName.size(); ++pos) {
00555           if (isspace(meshName[pos])) meshName[pos] = '_';
00556         }
00557 
00558         char * fieldEntryName;
00559         int lenName = strlen(iterationName.str().c_str()) + 4 +
00560           strlen(supportName.c_str()) + 4 + strlen(meshName.c_str()) + 1;
00561 
00562         fieldEntryName = new char[lenName];
00563         fieldEntryName = strcpy(fieldEntryName,iterationName.str().c_str());
00564         fieldEntryName = strcat(fieldEntryName,"_ON_");
00565         fieldEntryName = strcat(fieldEntryName,supportName.c_str());
00566         fieldEntryName = strcat(fieldEntryName,"_OF_");
00567         fieldEntryName = strcat(fieldEntryName,meshName.c_str());
00568 
00569         SCRUTE(fieldEntryName);
00570         fieldEntryPath += fieldEntryName;
00571 
00572         // Create object labelled according to Field's Name
00573 
00574         SALOMEDS::SObject_var fieldSO = myStudy->FindObjectByPath(fieldEntryPath.c_str());
00575         bool alreadyPublished = ! CORBA::is_nil(fieldSO);
00576         aBuilder->NewCommand();
00577         if ( !alreadyPublished )
00578         {
00579           MESSAGE("Add a Field Object under "<<fieldName);
00580           fieldSO = aBuilder->NewObject(medfieldnamefather);
00581           // check that this method and getEntryPath() build the same path,
00582           // though this is true only for MED component
00583           MESSAGE("fieldEntryPath: "<< fieldEntryPath);
00584           MESSAGE("getEntryPath(): "<< getEntryPath());
00585           if (componentName == "Med")
00586             ASSERT( getEntryPath() == fieldEntryPath );
00587         }
00588         anAttr = aBuilder->FindOrCreateAttribute(fieldSO, "AttributeName");
00589         aName = SALOMEDS::AttributeName::_narrow(anAttr);
00590         aName->SetValue(fieldEntryName);
00591 
00592         ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
00593         ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
00594         CORBA::ORB_var &orb = init(0,0);
00595         string iorStr = orb->object_to_string(myIor);
00596         anAttr = aBuilder->FindOrCreateAttribute(fieldSO, "AttributeIOR");
00597         aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
00598         aIOR->SetValue(iorStr.c_str());
00599         _FieldId = fieldSO->GetID();
00600 
00601         if ( !alreadyPublished )
00602         {
00603           MESSAGE("Computing path to Support");
00604 
00605           string supportEntryPath = SUPPORT_i::getEntryPath( _fieldTptr->getSupport() );
00606           SCRUTE(supportEntryPath);
00607 
00608           SALOMEDS::SObject_var supportObject =
00609             myStudy->FindObjectByPath(supportEntryPath.c_str());
00610 
00611           SCRUTE(supportObject);
00612 
00613           if ( CORBA::is_nil(supportObject) ) 
00614           {
00615             MESSAGE("supportObject is a nil corba object");
00616             MESSAGE("FIELD_i::addInStudy : SUPPORT not found") ;
00617           } 
00618           else 
00619           {
00620             MESSAGE("supportObject is OK and is now going to be referenced !");
00621             SALOMEDS::SObject_var newObjSupport = aBuilder->NewObject(fieldSO);
00622             aBuilder->Addreference(newObjSupport,supportObject);
00623             MESSAGE(" OUF !!!");
00624           }
00625         }
00626 
00627         aBuilder->CommitCommand();
00628 
00629         delete [] fieldEntryName;
00630 
00631         // register the Corba pointer: increase the referrence count
00632         MESSAGE("Registering of the Corba Field pointer");
00633         Register();
00634 
00635         MESSAGE("FIELD_i::addInStudy");
00636 
00637         //END_OF();
00638 }
00639 
00640 //=============================================================================
00644 //=============================================================================
00645 void FIELD_i::write (CORBA::Long i, const char* driverFieldName)
00646 throw (SALOME::SALOME_Exception)
00647 {
00648         if (_fieldTptr==NULL)
00649                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00650                                              SALOME::INTERNAL_ERROR);
00651         try
00652         {
00653                 _fieldTptr->write(i);
00654         }
00655         catch (MEDEXCEPTION &)
00656         {
00657                 MESSAGE("Exception en accedant au champ");
00658                 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Field C++ Object"\
00659                                                 ,SALOME::INTERNAL_ERROR);
00660         }
00661 }
00662 //=============================================================================
00666 //=============================================================================
00667 void FIELD_i::read (CORBA::Long i)
00668 throw (SALOME::SALOME_Exception)
00669 {
00670         if (_fieldTptr==NULL)
00671                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00672                                              SALOME::INTERNAL_ERROR);
00673         try
00674         {
00675                 _fieldTptr->read(i);
00676         }
00677         catch (MEDEXCEPTION &ex)
00678         {
00679                 MESSAGE("Exception en accedant au champ");
00680                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00681         }
00682 }
00683 //=============================================================================
00687 //=============================================================================
00688 void FIELD_i::rmDriver (CORBA::Long i)
00689 throw (SALOME::SALOME_Exception)
00690 {
00691         if (_fieldTptr==NULL)
00692                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00693                                              SALOME::INTERNAL_ERROR);
00694         try
00695         {
00696                 _fieldTptr->rmDriver(i);
00697         }
00698         catch (MEDEXCEPTION &ex)
00699         {
00700                 MESSAGE("Exception en accedant au champ");
00701                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00702         }
00703 }
00704 //=============================================================================
00708 //=============================================================================
00709 CORBA::Long FIELD_i::addDriver (SALOME_MED::medDriverTypes driverType, 
00710                         const char* fileName, const char* fieldName) throw (SALOME::SALOME_Exception)
00711 {
00712         if (_fieldTptr==NULL)
00713                 THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00714                                              SALOME::INTERNAL_ERROR);
00715         try
00716         {
00717                 int drivernum=_fieldTptr->addDriver(
00718                                         convertIdlDriverToMedDriver(driverType),
00719                                         fileName,
00720                                         fieldName);
00721                 return drivernum;
00722         }
00723         catch (MEDEXCEPTION &ex)
00724         {
00725                 MESSAGE("Exception en accedant au champ");
00726                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00727         }
00728 }
00729 
00730 //=============================================================================
00734 //=============================================================================
00735 
00736 SALOMEDS::SComponent_ptr FIELD_i::PublishMedComponent(SALOMEDS::Study_ptr theStudy)
00737 {
00738   if ( CORBA::is_nil(theStudy) )
00739     return SALOMEDS::SComponent::_nil();
00740 
00741   SALOMEDS::SComponent_var medfather = theStudy->FindComponent("MED");
00742   if ( !CORBA::is_nil(medfather) )
00743     return medfather._retn();
00744 
00745   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
00746   ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
00747   CORBA::ORB_var &orb = init(0,0);
00748 
00749   SALOME_NamingService* ns = SINGLETON_<SALOME_NamingService>::Instance();
00750   ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
00751   ns->init_orb( orb );
00752 
00753   SALOME_LifeCycleCORBA* lcc = new SALOME_LifeCycleCORBA( ns );
00754 
00755   SALOME_ModuleCatalog::ModuleCatalog_var aCatalog  = 
00756     SALOME_ModuleCatalog::ModuleCatalog::_narrow(ns->Resolve("/Kernel/ModulCatalog"));
00757   if ( CORBA::is_nil( aCatalog ) )
00758     return medfather._retn();
00759   SALOME_ModuleCatalog::Acomponent_var aComp = aCatalog->GetComponent( "MED" );
00760   if ( CORBA::is_nil( aComp ) )
00761     return medfather._retn();
00762   
00763   SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder();
00764   aBuilder->NewCommand();
00765   bool aLocked = theStudy->GetProperties()->IsLocked();
00766   if (aLocked) theStudy->GetProperties()->SetLocked(false);
00767   
00768   medfather = aBuilder->NewComponent("MED");
00769   SALOMEDS::GenericAttribute_var anAttr = aBuilder->FindOrCreateAttribute(medfather, "AttributeName");
00770   SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
00771   aName->SetValue( aComp->componentusername() );
00772   
00773   Engines::EngineComponent_var aMedComponent = lcc->FindOrLoad_Component("FactoryServer", "MED");
00774   SALOME_MED::MED_Gen_var aMedEngine = SALOME_MED::MED_Gen::_narrow( aMedComponent );
00775   aBuilder->DefineComponentInstance(medfather, aMedEngine);
00776   
00777   if (aLocked) theStudy->GetProperties()->SetLocked(true);
00778   aBuilder->CommitCommand();
00779   
00780   return medfather._retn();
00781 }
00782 
00783 //================================================================================
00788 //================================================================================
00789 
00790 string FIELD_i::getEntryPath ()
00791 {
00792   string path;
00793   if ( _fieldTptr &&
00794        _fieldTptr->getSupport() &&
00795        _fieldTptr->getSupport()->getMesh() )
00796   {
00797     string meshName = _fieldTptr->getSupport()->getMesh()->getName();
00798     for (string::size_type pos=0; pos<meshName.size(); ++pos)
00799     {
00800       if (isspace(meshName[pos])) meshName[pos] = '_';
00801     }
00802     ostringstream os ;
00803 
00804     os << "/Med/MEDFIELD/" << _fieldTptr->getName() << "/" 
00805        << "(" << _fieldTptr->getIterationNumber()
00806        << "," << _fieldTptr->getOrderNumber()
00807        << ")_ON_" << _fieldTptr->getSupport()->getName()
00808        << "_OF_" << meshName;
00809 
00810     path = os.str();
00811   }
00812   return path;
00813 }