From: nadir Date: Fri, 2 Dec 2005 17:04:20 +0000 (+0000) Subject: update due to OCC work on Med file persistency (merge from the branch X-Git-Tag: ForV3_1_0b1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8932800d022fe88e2f22aae832c3b35d5064b296;p=modules%2Fmed.git update due to OCC work on Med file persistency (merge from the branch BR_OCC_For_3_1_0b1). --- diff --git a/src/MED/Med_Gen_i.cxx b/src/MED/Med_Gen_i.cxx index 880ee5e57..b585d4448 100755 --- a/src/MED/Med_Gen_i.cxx +++ b/src/MED/Med_Gen_i.cxx @@ -99,6 +99,8 @@ Med_Gen_i:: Med_Gen_i(CORBA::ORB_ptr orb, _NS = SINGLETON_::Instance() ; ASSERT(SINGLETON_::IsAlreadyExisting()) ; _NS->init_orb( _orb ) ; + + _myMedI = 0; } //============================================================================= /*! @@ -478,7 +480,7 @@ throw (SALOME::SALOME_Exception) } } - + return SALOME_MED::FIELD::_nil(); } @@ -530,6 +532,13 @@ SALOMEDS::TMPFile* Med_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent, aName += myMesh->getName(); aName += ".med"; MESSAGE("Save mesh with name "<length(1); + aSeq[0]=CORBA::string_dup( aName.ToCString() ); + SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); + aSeq->length(0); + } long driverId = myMesh->addDriver(SALOME_MED::MED_DRIVER,(aTmpDir+aName).ToCString(),myMesh->getName()); myMesh->write(driverId,""); aFileNames.Append(aName); @@ -538,6 +547,10 @@ SALOMEDS::TMPFile* Med_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent, } } + // temporary: until info that mesh is distant is written + MED_EN::medFileVersion curVersion = DRIVERFACTORY::getMedFileVersionForWriting(); + DRIVERFACTORY::setMedFileVersionForWriting( MED_EN::V21 ); + SALOMEDS::SObject_var aMedFieldFather = theComponent->GetStudy()->FindObject("MEDFIELD"); if (!CORBA::is_nil(aMedFieldFather)) { SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedFieldFather); @@ -561,7 +574,14 @@ SALOMEDS::TMPFile* Med_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent, aName += "_ITER_"; aName += (char*)(b.str().c_str()); aName += ".med"; - MESSAGE("Save mesh with name "<length(1); + aSeq[0]=CORBA::string_dup( aName.ToCString() ); + SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); + aSeq->length(0); + } + MESSAGE("Save field with name "<addDriver(SALOME_MED::MED_DRIVER,(aTmpDir+aName).ToCString(),myField->getName()); myField->write(driverId,""); aFileNames.Append(aName); @@ -569,10 +589,12 @@ SALOMEDS::TMPFile* Med_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent, } } } + DRIVERFACTORY::setMedFileVersionForWriting( curVersion ); int i; aSeq->length(aFileNames.Length()); - for(i = aFileNames.Length(); i > 0; i--) aSeq[i-1] = CORBA::string_dup(aFileNames.Value(i).ToCString()); + for(i = aFileNames.Length(); i > 0; i--) + aSeq[i-1] = CORBA::string_dup(aFileNames.Value(i).ToCString()); // Conver a file to the byte stream aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile); // Remove the created file and tmp directory @@ -582,7 +604,6 @@ SALOMEDS::TMPFile* Med_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent, END_OF(LOC); } - SALOMEDS::TMPFile* Med_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent, const char* theURL, bool isMultiFile) { @@ -615,6 +636,13 @@ SALOMEDS::TMPFile* Med_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent, aName += myMesh->getName(); aName += ".med"; MESSAGE("Save mesh with name "<length(1); + aSeq[0]=CORBA::string_dup( aName.ToCString() ); + SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); + aSeq->length(0); + } long driverId = myMesh->addDriver(SALOME_MED::MED_DRIVER,(aTmpDir+aName).ToCString(),myMesh->getName()); myMesh->write(driverId,""); HDFascii::ConvertFromHDFToASCII((aTmpDir+aName).ToCString(), true); @@ -624,6 +652,10 @@ SALOMEDS::TMPFile* Med_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent, } } + // temporary: until info that mesh is distant is written + MED_EN::medFileVersion curVersion = DRIVERFACTORY::getMedFileVersionForWriting(); + DRIVERFACTORY::setMedFileVersionForWriting( MED_EN::V21 ); + SALOMEDS::SObject_var aMedFieldFather = theComponent->GetStudy()->FindObject("MEDFIELD"); if (!CORBA::is_nil(aMedFieldFather)) { SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedFieldFather); @@ -647,7 +679,14 @@ SALOMEDS::TMPFile* Med_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent, aName += "_ITER_"; aName += (char*)(b.str().c_str()); aName += ".med"; - MESSAGE("Save mesh with name "<length(1); + aSeq[0]=CORBA::string_dup( aName.ToCString() ); + SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); + aSeq->length(0); + } long driverId = myField->addDriver(SALOME_MED::MED_DRIVER,(aTmpDir+aName).ToCString(),myField->getName()); myField->write(driverId,""); HDFascii::ConvertFromHDFToASCII((aTmpDir+aName).ToCString(), true); @@ -656,11 +695,13 @@ SALOMEDS::TMPFile* Med_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent, } } } + DRIVERFACTORY::setMedFileVersionForWriting( curVersion ); int i; aSeq->length(aFileNames.Length()); - for(i = aFileNames.Length(); i > 0; i--) aSeq[i-1] = CORBA::string_dup(aFileNames.Value(i).ToCString()); - // Conver a file to the byte stream + for(i = aFileNames.Length(); i > 0; i--) + aSeq[i-1] = CORBA::string_dup(aFileNames.Value(i).ToCString()); + // Convert a file to the byte stream aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile); // Remove the created file and tmp directory if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); @@ -809,6 +850,43 @@ char* Med_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, return CORBA::string_dup("_MED"); } +//======================================================================= +//function : getFieldNameAndDtIt +//purpose : +//======================================================================= + +static void getFieldNameAndDtIt( const char* aLocalPersistentID, + string & aFieldName, + CORBA::Long & aNumOrdre, + CORBA::Long & anIterNumber) +{ + // aLocalPersistentID(("_MEDFIELD_"+ myField->getName() + + // "_ORDRE_"+a.str()+ + // "_ITER_"+b.str()+".med" + int aLPIdLen = strlen(aLocalPersistentID); + const int _MEDFIELD_Len = strlen("_MEDFIELD_"); + const int _ORDRE_Len = strlen("_ORDRE_"); + const int _ITER_Len = strlen("_ITER_"); + + // Get field name: look for _ORDRE_ in aLocalPersistentID + int aFieldNameLen = 0, aFieldNameBeg = _MEDFIELD_Len, _ORDRE_Beg; + for ( _ORDRE_Beg = aFieldNameBeg; _ORDRE_Beg < aLPIdLen; ++aFieldNameLen,++_ORDRE_Beg ) + if ( strncmp( &aLocalPersistentID[ _ORDRE_Beg ], "_ORDRE_", _ORDRE_Len ) == 0 ) + break; + aFieldName = string( &(aLocalPersistentID[aFieldNameBeg]), aFieldNameLen); + + // Get orderNumber + int anOrderNumberBeg = _ORDRE_Beg + _ORDRE_Len; + aNumOrdre = atoi( & aLocalPersistentID[ anOrderNumberBeg ]); + + // Get iterationNumber: look for _ITER_ in aLocalPersistentID + int _ITER_Beg = anOrderNumberBeg; + for ( ; _ITER_Beg < aLPIdLen; ++_ITER_Beg ) + if ( strncmp( &aLocalPersistentID[ _ITER_Beg ], "_ITER_", _ITER_Len ) == 0 ) + break; + anIterNumber = atoi( & aLocalPersistentID[ _ITER_Beg + _ITER_Len ]); +} + //============================================================================= /*! * CORBA: give a transient reference (when loading an object, opening study) @@ -823,72 +901,127 @@ char* Med_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, { const char * LOC = "Med_Gen_i::LocalPersistentIDToIOR" ; BEGIN_OF(LOC) ; - TCollection_AsciiString aTmpDir((char*)(_saveFileName.c_str())); + bool isMesh, isField; + isMesh = isField = false; + + if (strcmp(aLocalPersistentID, "_MED Objet Med + /OBJ_MED/") == 0) { // MED + _myMedI = new MED_i(); + SALOME_MED::MED_ptr myMedIOR = _myMedI->_this(); + return(CORBA::string_dup(_orb->object_to_string(myMedIOR))); + } + else if (strncmp(aLocalPersistentID, "_MEDMESH_",9) == 0) // MESH + isMesh = true; + else if (strncmp(aLocalPersistentID, "_MED/FAS/",9) == 0) // SUPPORT + return (CORBA::string_dup( theSObject->GetIOR() )); // is loaded along with MESH + else if (strncmp(aLocalPersistentID, "_MEDFIELD_",10) == 0) // FIELD + isField = true; + else + return CORBA::string_dup(""); + + // Get file name + char* aFileName; + TCollection_AsciiString aTmpDir((char*)(_saveFileName.c_str())); TCollection_AsciiString aSaveStudyName(""); - if (isMultiFile) aSaveStudyName = (char*)SALOMEDS_Tool::GetNameFromPath(theSObject->GetStudy()->URL()).c_str(); + if (isMultiFile) + aSaveStudyName = (char*)SALOMEDS_Tool::GetNameFromPath(theSObject->GetStudy()->URL()).c_str(); + if (isASCII) + { + char* aResultPath = HDFascii::ConvertFromASCIIToHDF((aTmpDir + aSaveStudyName + (char*)aLocalPersistentID).ToCString()); + aFileName = new char[strlen(aResultPath) + 19]; + sprintf(aFileName, "%shdf_from_ascii.hdf", aResultPath); + delete(aResultPath); + } + else + aFileName = CORBA::string_dup((aTmpDir + aSaveStudyName + (char*)aLocalPersistentID).ToCString()); + + // Read file structure + try + { + ASSERT( _myMedI ); + CORBA::Long drvId = _myMedI->addDriver( SALOME_MED::MED_DRIVER, aFileName ); + _myMedI->readFileStruct( drvId ); + } + catch (const std::exception & ex) + { + MESSAGE("Exception Interceptee : "); + SCRUTE(ex.what()); + THROW_SALOME_CORBA_EXCEPTION("Unable to read a hdf file",SALOME::BAD_PARAM); + }; - if (strcmp(aLocalPersistentID, "Objet Med + /OBJ_MED/") == 0) return CORBA::string_dup(""); // MED + CORBA::Object_ptr anIOR; - if (strncmp(aLocalPersistentID, "_MEDMESH_",9) == 0) {// MESH - MESH * myMesh= new MESH() ; + if ( isMesh ) {// MESH + // Get mesh name int aMeshNameLen = strlen(aLocalPersistentID) - 12; - char* aMeshName = new char[aMeshNameLen]; - strncpy(aMeshName, &(aLocalPersistentID[9]), aMeshNameLen-1); + string aMeshName( &(aLocalPersistentID[9]), aMeshNameLen); aMeshName[aMeshNameLen-1] = 0; - myMesh->setName(aMeshName); - - char* aFileName; - if (isASCII) { - char* aResultPath = HDFascii::ConvertFromASCIIToHDF((aTmpDir + aSaveStudyName + (char*)aLocalPersistentID).ToCString()); - aFileName = new char[strlen(aResultPath) + 19]; - sprintf(aFileName, "%shdf_from_ascii.hdf", aResultPath); - delete(aResultPath); - } else aFileName = CORBA::string_dup((aTmpDir + aSaveStudyName + (char*)aLocalPersistentID).ToCString()); - MED_MESH_RDONLY_DRIVER myMeshDriver(aFileName,myMesh); + + // Read mesh + SALOME_MED::MESH_ptr mesh; try - { - myMeshDriver.setMeshName(aMeshName); - myMeshDriver.open(); - } + { + mesh = _myMedI->getMeshByName( aMeshName.c_str() ); + mesh->read( 0 ); + _myMedI->updateSupportIORs( theSObject->GetStudy(), aMeshName.c_str() ); + } catch (const std::exception & ex) - { - MESSAGE("Exception Interceptee : "); - SCRUTE(ex.what()); - THROW_SALOME_CORBA_EXCEPTION("Unable to find this mesh in this file",SALOME::BAD_PARAM); - }; + { + MESSAGE("Exception Interceptee : "); + SCRUTE(ex.what()); + THROW_SALOME_CORBA_EXCEPTION("Unable to read this mesh in this file", + SALOME::INTERNAL_ERROR); + } + + anIOR = mesh; + } + + if ( isField ) { // FIELD + + // Field Name + string aFieldName; + CORBA::Long aNumOrdre, anIterNumber; + getFieldNameAndDtIt( aLocalPersistentID, aFieldName, aNumOrdre, anIterNumber ); + + // Read field + SALOME_MED::FIELD_ptr field; try - { - myMeshDriver.read(); - MESSAGE("apres read"); - myMeshDriver.close(); - } + { + field = _myMedI->getField( aFieldName.c_str(), anIterNumber, aNumOrdre ); + field->read( 0 ); + } catch (const std::exception & ex) - { - MESSAGE("Exception Interceptee : "); - SCRUTE(ex.what()); - THROW_SALOME_CORBA_EXCEPTION("Unable to read this mesh in this file",SALOME::BAD_PARAM); - } - MESH_i * meshi = new MESH_i(myMesh); - //SALOME_MED::MESH_var mesh = SALOME_MED::MESH::_narrow(meshi->_this()); - SALOME_MED::MESH_ptr mesh = meshi->_this(); - SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; - aSeq->length(1); - aSeq[0]=CORBA::string_dup(aLocalPersistentID); - if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); - if (isASCII) { - SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames; - aFilesToRemove->length(1); - aFilesToRemove[0] = CORBA::string_dup(&(aFileName[strlen(SALOMEDS_Tool::GetDirFromPath(aFileName).c_str())])); - SALOMEDS_Tool::RemoveTemporaryFiles(SALOMEDS_Tool::GetDirFromPath(aFileName).c_str(), aFilesToRemove, true); + { + MESSAGE("Exception Interceptee : "); + SCRUTE(ex.what()); + THROW_SALOME_CORBA_EXCEPTION("Unable to read this field in this file", + SALOME::INTERNAL_ERROR); } - delete(aFileName); - return(CORBA::string_dup(_orb->object_to_string(mesh))); - } else if (strncmp(aLocalPersistentID, "_MEDFIELD_",14) == 0) { // FIELD - return(CORBA::string_dup("")); // not implemented yet + + anIOR = field; + + } + + // Remove tmp files + SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; + aSeq->length(1); + aSeq[0]=CORBA::string_dup(aLocalPersistentID); + if (!isMultiFile) + SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); + if (isASCII) + { + SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames; + aFilesToRemove->length(1); + aFilesToRemove[0] = CORBA::string_dup(&(aFileName[strlen(SALOMEDS_Tool::GetDirFromPath(aFileName).c_str())])); + SALOMEDS_Tool::RemoveTemporaryFiles(SALOMEDS_Tool::GetDirFromPath(aFileName).c_str(), aFilesToRemove, true); } - return CORBA::string_dup(""); + delete(aFileName); + + if ( CORBA::is_nil( anIOR )) + return CORBA::string_dup(""); + + return(CORBA::string_dup(_orb->object_to_string( anIOR ))); } //============================================================================= @@ -898,7 +1031,15 @@ char* Med_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, //============================================================================= bool Med_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) { SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(theIOR); - return !(aMesh->_is_nil()); + if ( !aMesh->_is_nil()) + return true; + SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow(theIOR); + if ( !aField->_is_nil()) + return true; +// SALOME_MED::SUPPORT_var aSupport = SALOME_MED::SUPPORT::_narrow(theIOR); +// if ( !aSupport->_is_nil()) +// return true; + return false; } //============================================================================= @@ -940,11 +1081,18 @@ SALOMEDS::SObject_ptr Med_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, if (CORBA::is_nil(theSObject)) { SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(theObject); - aMesh->addInStudy(theStudy, aMesh); - SALOMEDS::SObject_var aResultSO = theStudy->FindObjectIOR(_orb->object_to_string(theObject)); + if ( !aMesh->_is_nil() ) + aMesh->addInStudy(theStudy, aMesh); + SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow(theObject); + if ( !aField->_is_nil()) + aField->addInStudy(theStudy, aField); +// SALOME_MED::SUPPORT_var aSupport = SALOME_MED::SUPPORT::_narrow(theObject); +// if ( !aSupport->_is_nil()) +// aSupport->addInStudy(theStudy, aSupport); + aResultSO = theStudy->FindObjectIOR(_orb->object_to_string(theObject)); } else { - if (!theSObject->ReferencedObject(aResultSO)) - THROW_SALOME_CORBA_EXCEPTION("Publish in study MED object error",SALOME::BAD_PARAM); +// if (!theSObject->ReferencedObject(aResultSO)) +// THROW_SALOME_CORBA_EXCEPTION("Publish in study MED object error",SALOME::BAD_PARAM); } // aBuilder->Addreference(theObject, aResultSO); return aResultSO._retn(); @@ -996,6 +1144,7 @@ SALOMEDS::TMPFile* Med_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::L char* aFullName = new char[strlen(aTmpDir)+strlen(aSeq[0])+1]; strcpy(aFullName, aTmpDir); strcpy(aFullName+strlen(aTmpDir), aSeq[0]); + long driverId = aMesh->addDriver(SALOME_MED::MED_DRIVER,aFullName , aMesh->getName()); aMesh->write(driverId,""); @@ -1063,7 +1212,7 @@ SALOMEDS::SObject_ptr Med_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream, }; try { myMeshDriver.read(); - ("apres read"); + MESSAGE("apres read"); myMeshDriver.close(); } catch (const std::exception & ex) { MESSAGE("Exception Interceptee : "); diff --git a/src/MED/Med_Gen_i.hxx b/src/MED/Med_Gen_i.hxx index d656bc888..2cf3719c9 100644 --- a/src/MED/Med_Gen_i.hxx +++ b/src/MED/Med_Gen_i.hxx @@ -40,6 +40,10 @@ #include CORBA_SERVER_HEADER(SALOMEDS_Attributes) +namespace MEDMEM { + class MED_i; +} + class Med_Gen_i: public POA_SALOME_MED::MED_Gen, public Engines_Component_i @@ -140,7 +144,7 @@ public: int myCounter; SALOME_NamingService *_NS; - + MEDMEM::MED_i* _myMedI; // used while loading a study }; #endif diff --git a/src/MEDMEM_I/MEDMEM_Field_i.cxx b/src/MEDMEM_I/MEDMEM_Field_i.cxx index 71fb67476..0a6f4efae 100644 --- a/src/MEDMEM_I/MEDMEM_Field_i.cxx +++ b/src/MEDMEM_I/MEDMEM_Field_i.cxx @@ -509,21 +509,14 @@ void FIELD_i::addInStudy(SALOMEDS::Study_ptr myStudy, MESSAGE("Computing path to Support"); - char * supportEntryPath; - lenName = 28 + 15 + strlen(meshName.c_str()) + 1 + - strlen(supportName.c_str()) + 1; - supportEntryPath = new char[lenName]; - supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/MEDSUPPORTS_OF_"); - supportEntryPath = strcat(supportEntryPath,meshNameStudy.c_str()); - supportEntryPath = strcat(supportEntryPath,"/"); - supportEntryPath = strcat(supportEntryPath,supportName.c_str()); - + string supportEntryPath = SUPPORT_i::getEntryPath( meshNameStudy, + _fieldTptr->getSupport() ); SCRUTE(supportEntryPath); - MESSAGE("supportEntryPath in field " << supportEntryPath << " length " << lenName); + MESSAGE("supportEntryPath in field " << supportEntryPath /*<< " length " << lenName*/); // SALOMEDS::SObject_var supportObject = myStudy->FindObject(supportName.c_str()); - SALOMEDS::SObject_var supportObject = myStudy->FindObjectByPath(supportEntryPath); + SALOMEDS::SObject_var supportObject = myStudy->FindObjectByPath(supportEntryPath.c_str()); SCRUTE(supportObject); @@ -542,7 +535,7 @@ void FIELD_i::addInStudy(SALOMEDS::Study_ptr myStudy, myBuilder->CommitCommand(); - delete [] supportEntryPath; + //delete [] supportEntryPath; delete [] fieldEntryName; // register the Corba pointer: increase the referrence count diff --git a/src/MEDMEM_I/MEDMEM_Med_i.cxx b/src/MEDMEM_I/MEDMEM_Med_i.cxx index 3ae43045f..4f1d7774a 100644 --- a/src/MEDMEM_I/MEDMEM_Med_i.cxx +++ b/src/MEDMEM_I/MEDMEM_Med_i.cxx @@ -18,6 +18,8 @@ #include "MEDMEM_Family_i.hxx" #include "MEDMEM_Group_i.hxx" #include "MEDMEM_convert.hxx" +#include "MEDMEM_Family.hxx" +#include "MEDMEM_Group.hxx" #include "MEDMEM_DriversDef.hxx" #include "utilities.h" @@ -34,6 +36,7 @@ using namespace MEDMEM; MED_i::MED_i():_med((::MED*)NULL) { BEGIN_OF("Default Constructor MED_i"); + _med = new ::MED(); END_OF("Default Constructor MED_i"); } //============================================================================= @@ -47,7 +50,9 @@ void MED_i::init(SALOMEDS::Study_ptr myStudy,driverTypes driverType, const strin BEGIN_OF(LOC); // we create all IOR from _med - _med = new ::MED(driverType,fileName); + if ( _med ) + delete _med; + _med = new ::MED(driverType,fileName); // MESHES : deque meshesNames = _med->getMeshNames(); @@ -210,7 +215,9 @@ void MED_i::initWithFieldType(SALOMEDS::Study_ptr myStudy,driverTypes driverType SCRUTE(driverType); SCRUTE(fileName) - _med = new ::MED(driverType,fileName); + if ( _med ) + delete _med; + _med = new ::MED(driverType,fileName); int numberOfMeshes = _med->getNumberOfMeshes(); SCRUTE(numberOfMeshes); @@ -665,7 +672,87 @@ void MED_i::initWithFieldType(SALOMEDS::Study_ptr myStudy,driverTypes driverType //============================================================================= MED_i::~MED_i() { + //delete _med; } + +//======================================================================= +//function : updateSupportIORs +//purpose : +//======================================================================= + +void MED_i::updateSupportIORs(SALOMEDS::Study_ptr myStudy, const char* meshName) +{ + vector familyVector; + vector::iterator familyVectorIt; + vector groupVector; + vector::iterator groupVectorIt; + string supportEntryPath; + + ::MESH * ptrMesh = _med->getMesh(meshName); + + MED_EN::MESH_ENTITIES::const_iterator currentEntity; + + for (currentEntity = MED_EN::meshEntities.begin(); + currentEntity != MED_EN::meshEntities.end(); + currentEntity++) + { + // family : + familyVector = ptrMesh->getFamilies((MED_EN::medEntityMesh)(*currentEntity).first); + int nb = familyVector.size(); + for (familyVectorIt = familyVector.begin(); + familyVectorIt != familyVector.end(); + familyVectorIt++) + { + supportEntryPath = SUPPORT_i::getEntryPath( meshName, *familyVectorIt ); + SALOMEDS::SObject_var familyEntry = myStudy->FindObjectByPath(supportEntryPath.c_str()); + if ( !familyEntry->_is_nil() || CORBA::is_nil( familyEntry->GetObject() )) + { + FAMILY_i * myFamilyI = new FAMILY_i(*familyVectorIt); + SALOME_MED::FAMILY_ptr myFamilyIOR = myFamilyI->POA_SALOME_MED::FAMILY::_this(); + myFamilyI->addInStudy(myStudy,myFamilyIOR); + } + } + + // group : + groupVector = ptrMesh->getGroups((MED_EN::medEntityMesh)(*currentEntity).first); + nb = groupVector.size(); + for (groupVectorIt = groupVector.begin(); + groupVectorIt != groupVector.end(); + groupVectorIt++) + { + supportEntryPath = SUPPORT_i::getEntryPath( meshName, *groupVectorIt ); + SALOMEDS::SObject_var groupEntry = myStudy->FindObjectByPath(supportEntryPath.c_str()); + if ( !groupEntry->_is_nil() || CORBA::is_nil( groupEntry->GetObject() )) + { + GROUP_i * myGroupI = new GROUP_i(*groupVectorIt); + SALOME_MED::GROUP_ptr myGroupIOR = myGroupI->POA_SALOME_MED::GROUP::_this(); + myGroupI->addInStudy(myStudy,myGroupIOR); + } + } + } + + _med->updateSupport(); + + // supports + map mySupports = _med->getSupports(meshName); + map::const_iterator itSupport; + map & + mySupportsIOR = _supports[meshName]; + for (itSupport=mySupports.begin(); itSupport!=mySupports.end(); itSupport++ ) + { + supportEntryPath = SUPPORT_i::getEntryPath( meshName, itSupport->second); + SALOMEDS::SObject_var supportEntry = myStudy->FindObjectByPath(supportEntryPath.c_str()); + if ( !supportEntry->_is_nil() || CORBA::is_nil( supportEntry->GetObject() )) + { + SUPPORT_i * mySupportI = new SUPPORT_i((*itSupport).second); + SALOME_MED::SUPPORT_ptr mySupportIOR = mySupportI->_this(); + mySupportsIOR[(*itSupport).first]= mySupportIOR; + mySupportI->addInStudy(myStudy,mySupportIOR); + } + } +} + + //============================================================================= /*! * CORBA: Accessor for Number of meshes @@ -781,18 +868,27 @@ throw (SALOME::SALOME_Exception) if (_med==NULL) THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\ SALOME::INTERNAL_ERROR); + SALOME_MED::MESH_ptr meshIOR; try { + map::const_iterator name_meshIOR = + _meshes.find( meshName ); + if ( name_meshIOR == _meshes.end() ) { MESH * mesh=_med->getMesh(meshName); MESH_i * m1 = new MESH_i(mesh); - return m1->POA_SALOME_MED::MESH::_this(); + meshIOR = m1->POA_SALOME_MED::MESH::_this(); + _meshes[ meshName ] = meshIOR; + } + else { + meshIOR = name_meshIOR->second; + } } catch (MEDEXCEPTION &ex) { MESSAGE("Unable to get the specified mesh"); THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR); } - + return meshIOR; } //============================================================================= /*! @@ -820,7 +916,7 @@ throw (SALOME::SALOME_Exception) ASSERT(FIELD_i::fieldMap.find(ind)!=FIELD_i::fieldMap.end()); ::FIELD * fdouble = (::FIELD *)FIELD_i::fieldMap[ind]; - MESH * mesh=_med->getMesh(fdouble); + mesh=_med->getMesh(fdouble); } else { @@ -828,7 +924,7 @@ throw (SALOME::SALOME_Exception) ASSERT(FIELD_i::fieldMap.find(ind)!=FIELD_i::fieldMap.end()); ::FIELD * fint = (::FIELD *)FIELD_i::fieldMap[ind]; - MESH * mesh=_med->getMesh(fint); + mesh=_med->getMesh(fint); } MESH_i * meshi = new MESH_i(mesh); return meshi->POA_SALOME_MED::MESH::_this(); @@ -941,6 +1037,11 @@ throw (SALOME::SALOME_Exception) { const char * LOC="MED_i::getField(const char*,CORBA::Long,CORBA::Long) "; BEGIN_OF(LOC); + if (_med==NULL) + THROW_SALOME_CORBA_EXCEPTION("No associated Med object",\ + SALOME::INTERNAL_ERROR); + + SALOME_MED::FIELD_ptr myFieldIOR = SALOME_MED::FIELD::_nil(); DT_IT_ dtIt; @@ -948,19 +1049,47 @@ throw (SALOME::SALOME_Exception) dtIt.it= (int)numOrdre; map::const_iterator itFields = _fields.find(fieldName); + if ( itFields != _fields.end() ) + { + const MAP_IOR_DT_IT_ & map_dtIt = (*itFields).second; + MAP_IOR_DT_IT_::const_iterator itMap_dtIt = map_dtIt.find(dtIt); + if ( itMap_dtIt != map_dtIt.end() ) + myFieldIOR = (*itMap_dtIt).second; + } - if ( itFields == _fields.end() ) - THROW_SALOME_CORBA_EXCEPTION("Field not found !", SALOME::INTERNAL_ERROR); - - const MAP_IOR_DT_IT_ & map_dtIt = (*itFields).second; - MAP_IOR_DT_IT_::const_iterator itMap_dtIt = map_dtIt.find(dtIt); - - if ( itMap_dtIt == map_dtIt.end() ) - THROW_SALOME_CORBA_EXCEPTION("Iteration not found !", SALOME::INTERNAL_ERROR); - - END_OF(LOC); - return (*itMap_dtIt).second; + if ( CORBA::is_nil( myFieldIOR )) + { + try + { + ::FIELD_* myField = _med->getField( fieldName, pasTemps, numOrdre); + + switch ( myField->getValueType() ) { + case MED_EN::MED_INT32 : { + FIELDINT_i * myFieldIntI = new FIELDINT_i((FIELD*)myField); + myFieldIOR = myFieldIntI->_this(); + break; + } + + case MED_EN::MED_REEL64: { + FIELDDOUBLE_i * myFieldDoubleI = new FIELDDOUBLE_i((FIELD*)myField); + myFieldIOR = myFieldDoubleI->_this(); + break; + } + default: + THROW_SALOME_CORBA_EXCEPTION ("Wrong field type", SALOME::INTERNAL_ERROR); + } + } + catch (const std::exception & ex) + { + MESSAGE("Exception Interceptee : "); + SCRUTE(ex.what()); + THROW_SALOME_CORBA_EXCEPTION("Field not found !", SALOME::INTERNAL_ERROR); + } + _fields[fieldName][dtIt] = myFieldIOR; + } + END_OF(LOC); + return myFieldIOR; } //============================================================================= /*! diff --git a/src/MEDMEM_I/MEDMEM_Med_i.hxx b/src/MEDMEM_I/MEDMEM_Med_i.hxx index cfc71c664..c988e4e7c 100644 --- a/src/MEDMEM_I/MEDMEM_Med_i.hxx +++ b/src/MEDMEM_I/MEDMEM_Med_i.hxx @@ -56,6 +56,9 @@ public: const char * medObjName) throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection); + void updateSupportIORs(SALOMEDS::Study_ptr myStudy, const char* meshName); + + // IDL Methods CORBA::Long getNumberOfMeshes() throw (SALOME::SALOME_Exception); CORBA::Long getNumberOfFields() throw (SALOME::SALOME_Exception); diff --git a/src/MEDMEM_I/MEDMEM_Support_i.cxx b/src/MEDMEM_I/MEDMEM_Support_i.cxx index 035095f50..dc406f212 100644 --- a/src/MEDMEM_I/MEDMEM_Support_i.cxx +++ b/src/MEDMEM_I/MEDMEM_Support_i.cxx @@ -17,6 +17,7 @@ #include "MEDMEM_define.hxx" #include "MEDMEM_Support.hxx" +#include "MEDMEM_Mesh.hxx" #include "MEDMEM_Support_i.hxx" #include "MEDMEM_Mesh_i.hxx" @@ -433,7 +434,7 @@ throw (SALOME::SALOME_Exception) SALOME_MED::long_array_var myseq= new SALOME_MED::long_array; try { - MESSAGE ("Nombre d'elements mis de façon stupide a MED_ALL_ELEMENTS"); + MESSAGE ("Nombre d'elements mis de façon stupide a MED_ALL_ELEMENTS"); int nbelements=_support->getNumberOfElements(::MED_ALL_ELEMENTS); myseq->length(nbelements); const int * numbers=_support->getNumberIndex(); @@ -465,7 +466,7 @@ SALOME::SenderInt_ptr SUPPORT_i::getSenderForNumberIndex() SALOME::SenderInt_ptr ret; try { - MESSAGE ("Nombre d'elements mis de façon stupide a MED_ALL_ELEMENTS"); + MESSAGE ("Nombre d'elements mis de façon stupide a MED_ALL_ELEMENTS"); int nbelements=_support->getNumberOfElements(::MED_ALL_ELEMENTS); const int * numbers=_support->getNumberIndex(); ret=SenderFactory::buildSender(*this,numbers,nbelements); @@ -604,7 +605,7 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr } MESSAGE(LOC << " Find SObject MESH (represent mesh in support)"); - string meshName = getMesh()->getName() ; + string meshName = _support->getMesh()->getName() ; string meshNameStudy = meshName; for (string::size_type pos=0; posNewCommand(); - string supportName = _support->getName(); - - SCRUTE(supportName); - - SCRUTE(meshNameStudy); - - char * supportEntryPath; - lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str())+1; - supportEntryPath = new char[lenName]; - supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/"); - supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_"); - supportEntryPath = strcat(supportEntryPath,meshNameStudy.c_str()); - supportEntryPath = strcat(supportEntryPath,"/"); - supportEntryPath = strcat(supportEntryPath,supportName.c_str()); - + string supportEntryPath = getEntryPath( meshName, _support ); //SCRUTE(supportEntryPath); - MESSAGE("supportEntryPath in support " << supportEntryPath << " length " << lenName); + MESSAGE("supportEntryPath in support " << supportEntryPath/* << " length " << lenName*/); -// SALOMEDS::SObject_var supportEntry = myStudy->FindObject(_support->getName().c_str()); - // c'est pas bon, car il faut rechercher uniquement sous le bon MESH !!! - SALOMEDS::SObject_var supportEntry = myStudy->FindObjectByPath(supportEntryPath); + SALOMEDS::SObject_var supportEntry = myStudy->FindObjectByPath(supportEntryPath.c_str()); if ( CORBA::is_nil(supportEntry) ) { @@ -694,7 +679,7 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr } myBuilder->CommitCommand(); - SALOMEDS::SObject_var supportEntryBis = myStudy->FindObjectByPath(supportEntryPath); + SALOMEDS::SObject_var supportEntryBis = myStudy->FindObjectByPath(supportEntryPath.c_str()); MESSAGE("Just for checking, reuse of the corba pointer"); @@ -708,7 +693,6 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr } delete [] medsupfatherName; - delete [] supportEntryPath; // register the Corba pointer: increase the referrence count MESSAGE("Registering of the Corba Support pointer"); @@ -716,3 +700,23 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr END_OF(LOC); } + +//======================================================================= +//function : getEntryPath +//purpose : +//======================================================================= + +string SUPPORT_i::getEntryPath(const string& aMeshName, const ::MEDMEM::SUPPORT * aSupport) +{ + string meshNameStudy( aMeshName.c_str(), strlen( aMeshName.c_str() )); + for (string::size_type pos=0; posgetName(); + string supportNameStudy( supportName.c_str(), strlen( supportName.c_str() )); + string supportEntryPath = + "/Med/MEDMESH/MEDSUPPORTS_OF_" + meshNameStudy + "/" + supportNameStudy; + SCRUTE( supportEntryPath ); + + return supportEntryPath; +} diff --git a/src/MEDMEM_I/MEDMEM_Support_i.hxx b/src/MEDMEM_I/MEDMEM_Support_i.hxx index 5e19805af..cc73701c0 100644 --- a/src/MEDMEM_I/MEDMEM_Support_i.hxx +++ b/src/MEDMEM_I/MEDMEM_Support_i.hxx @@ -81,6 +81,9 @@ public: SALOME_MED::SUPPORT_ptr myIor) throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection); + static std::string getEntryPath (const std::string& aMeshName, + const ::MEDMEM::SUPPORT * aSupport); + void release(); // Cuisine interne CORBA::Long getCorbaIndex() throw (SALOME::SALOME_Exception); diff --git a/src/MedCorba_Swig/batchmode_medcorba_test1.py b/src/MedCorba_Swig/batchmode_medcorba_test1.py index 4a852ddb7..30a576b9a 100644 --- a/src/MedCorba_Swig/batchmode_medcorba_test1.py +++ b/src/MedCorba_Swig/batchmode_medcorba_test1.py @@ -119,14 +119,43 @@ def getFieldIntObjectFromStudy(number,subnumber): #============================================================================== -def getMedObjectFromStudy(): - mySO = batchmode_salome.myStudy.FindObject("Objet MED") - Builder = batchmode_salome.myStudy.NewBuilder() - anAttr = Builder.FindOrCreateAttribute(mySO, "AttributeIOR") - obj = batchmode_salome.orb.string_to_object(anAttr.Value()) - myObj = obj._narrow(SALOME_MED.MED) +def getMedObjectFromStudy(fileName=None): + myObj=None; Builder = batchmode_salome.myStudy.NewBuilder() + if fileName is not None: + objNameInStudy = "MED_OBJECT_FROM_FILE_"+fileName + mySO = batchmode_salome.myStudy.FindObject(objNameInStudy) + if mySO is not None: + anAttr = Builder.FindOrCreateAttribute(mySO, "AttributeIOR") + obj = batchmode_salome.orb.string_to_object(anAttr.Value()) + if obj is not None: + myObj = obj._narrow(SALOME_MED.MED) + else: + print "ERROR: ",myObj," has been found in the Study, but with the type different of SALOME_MED.MED!!!" + else: + print "ERROR: ",objNameInStudy," hasn't been found in the Study!!!" + else: + SObj_root = batchmode_salome.myStudy.FindObjectByPath("/Med/") + if SObj_root is not None: + iter = batchmode_salome.myStudy.NewChildIterator(SObj_root) + try: + iter.Init(); + while iter.More(): + Obj = iter.Value() + if Obj is not None: + Ok, anAttr = Builder.FindAttribute(Obj, "AttributeIOR") + if Ok: + if len(anAttr.Value()) > 0: + obj = batchmode_salome.orb.string_to_object(anAttr.Value()) + if obj is not None: + myObj = obj._narrow(SALOME_MED.MED) + if myObj is not None: + break + iter.Next() + except: + print "Exception!!!" + else: print "Root object Med hasn't been found in the study!!!" return myObj - + studyCurrent = batchmode_salome.myStudyName studyCurrentId = batchmode_salome.myStudyId