X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FDriverMED%2FDriverMED_W_SMESHDS_Mesh.cxx;h=b0d98d2c32c3263529502975c9c892518c4910fe;hp=4581568136b65b1b39964c5c897a3ac7f484cfef;hb=HEAD;hpb=60bb6273b99dc88e3d6f360d7ae5792a77c68d06 diff --git a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx index 458156813..fda036694 100644 --- a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx +++ b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -53,6 +53,12 @@ using namespace std; using namespace MED; +//================================================================================ +/*! + * \brief Constructor + */ +//================================================================================ + DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh(): myAllSubMeshes (false), myDoGroupOfNodes (false), @@ -65,19 +71,31 @@ DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh(): myAddODOnVertices(false), myDoAllInGroups(false), myVersion(-1), - myZTolerance(-1.) + myZTolerance(-1.), + mySaveNumbers(true) {} +//================================================================================ +/*! + * \brief Set a file name and a version + * \param [in] theFileName - output file name + * \param [in] theVersion - desired MED file version == major * 10 + minor + */ +//================================================================================ + void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName, int theVersion) { myVersion = theVersion; Driver_SMESHDS_Mesh::SetFile(theFileName); } +//================================================================================ /*! * MED version is either the latest available, or with an inferior minor, * to ensure backward compatibility on writing med files. */ +//================================================================================ + string DriverMED_W_SMESHDS_Mesh::GetVersionString(int theMinor, int theNbDigits) { TInt majeur, mineur, release; @@ -148,24 +166,15 @@ void DriverMED_W_SMESHDS_Mesh::AddGroupOfBalls() myDoGroupOfBalls = true; } -//================================================================================ -/*! - * \brief Set up a flag to add all elements not belonging to any group to - * some auxiliary group. This is needed for SMESH -> SAUVE -> SMESH conversion, - * which since PAL0023285 reads only SAUVE elements belonging to any group, - * and hence can lose some elements. That auxiliary group is ignored while - * reading a MED file. - */ -//================================================================================ - -void DriverMED_W_SMESHDS_Mesh::AddAllToGroup() -{ - myDoAllInGroups = true; -} - namespace { + //--------------------------------------------- + /*! + * \brief Retrieving node coordinates utilities + */ + //--------------------------------------------- + typedef double (SMDS_MeshNode::* TGetCoord)() const; typedef const char* TName; typedef const char* TUnit; @@ -344,28 +353,37 @@ namespace } } +//================================================================================ +/*! + * \brief Write my mesh to a file + */ +//================================================================================ + Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() { MED::PWrapper myMed = CrWrapperW(myFile, myVersion); return this->PerformInternal(myMed); } +//================================================================================ +/*! + * \brief Write my mesh to a MEDCoupling DS + */ +//================================================================================ + Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh_Mem::Perform() { void *ptr(nullptr); std::size_t sz(0); Driver_Mesh::Status status = Driver_Mesh::DRS_OK; bool isClosed(false); - TMemFile *tfileInst = nullptr; {// let braces to flush (call of MED::PWrapper myMed destructor) - tfileInst = new TMemFile(&isClosed); + TMemFile *tfileInst = new TMemFile(&ptr,&sz,&isClosed);// this new will be destroyed by destructor of myMed MED::PWrapper myMed = CrWrapperW(myFile, -1, tfileInst); status = this->PerformInternal(myMed); } - if(tfileInst) - { - ptr = tfileInst->getData(); sz = tfileInst->getSize(); - } + if(!isClosed) + EXCEPTION(std::runtime_error, "TFTMemFile destructor : on destruction file has not been closed properly -> chunk of memory data may be invalid !"); _data = MEDCoupling::DataArrayByte::New(); _data->useArray(reinterpret_cast(ptr),true,MEDCoupling::DeallocType::C_DEALLOC,sz,1); if(!isClosed) @@ -574,7 +592,7 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::PerformInternal(LowLevelWriter myM #endif const EModeSwitch theMode = eFULL_INTERLACE; const ERepere theSystem = eCART; - const EBooleen theIsElemNum = eVRAI; + const EBooleen theIsElemNum = mySaveNumbers ? eVRAI : eFAUX; const EBooleen theIsElemNames = eFAUX; const EConnectivite theConnMode = eNOD; @@ -1003,9 +1021,11 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::PerformInternal(LowLevelWriter myM theIsElemNames); TInt aNbNodes = MED::GetNbNodes(aElemTypeData->_geomType); + elemIterator = myMesh->elementsIterator( aElemTypeData->_smdsType ); if ( aElemTypeData->_smdsType == SMDSAbs_0DElement && ! nodesOf0D.empty() ) elemIterator = iterVecIter; + while ( elemIterator->more() ) { const SMDS_MeshElement* anElem = elemIterator->next(); @@ -1032,6 +1052,15 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::PerformInternal(LowLevelWriter myM if ( ++iElem == aCellInfo->GetNbElem() ) break; } + // fix numbers of added SMDSAbs_0DElement + if ( aElemTypeData->_smdsType == SMDSAbs_0DElement && ! nodesOf0D.empty() ) + { + iElem = myMesh->Nb0DElements(); + TInt elem0DNum = FromSmIdType( myMesh->MaxElementID() + 1 ); + for ( size_t i = 0; i < nodesOf0D.size(); ++i ) + aCellInfo->SetElemNum( iElem++, elem0DNum++); + } + // store data in a file myMed->SetCellInfo(aCellInfo); }