From 0ec11e4a5d01bf4325e908e8efe4158e88bcf024 Mon Sep 17 00:00:00 2001 From: abd Date: Fri, 9 Feb 2007 12:51:10 +0000 Subject: [PATCH] Merging with V3_2_4 --- configure.in.base | 4 +- src/GHS3DPlugin_GHS3D.cxx | 96 ++++++++++++++++++++------------------- src/GHS3DPlugin_GHS3D.hxx | 5 -- 3 files changed, 52 insertions(+), 53 deletions(-) diff --git a/configure.in.base b/configure.in.base index f9755aa..93ab52d 100644 --- a/configure.in.base +++ b/configure.in.base @@ -22,8 +22,8 @@ AC_CANONICAL_HOST PACKAGE=salome AC_SUBST(PACKAGE) -VERSION=3.2.2 -XVERSION=0x030202 +VERSION=4.0.0 +XVERSION=0x040000 AC_SUBST(VERSION) AC_SUBST(XVERSION) diff --git a/src/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin_GHS3D.cxx index cf89cf8..b779e95 100644 --- a/src/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin_GHS3D.cxx @@ -399,6 +399,53 @@ static TCollection_AsciiString getTmpDir() return aTmpDir; } +//================================================================================ +/*! + * \brief Decrease amount of memory GHS3D may use until it can allocate it + * \param nbMB - memory size to adjust + * \param aLogFileName - file for GHS3D output + * \retval bool - false if GHS3D can not run for any reason + */ +//================================================================================ + +static bool adjustMemory(int & nbMB, const TCollection_AsciiString & aLogFileName) +{ + TCollection_AsciiString cmd( "ghs3d -m " ); + cmd += nbMB; + cmd += " 1>"; + cmd += aLogFileName; + + system( cmd.ToCString() ); // run + + // analyse log file + + FILE * aLogFile = fopen( aLogFileName.ToCString(), "r" ); + if ( aLogFile ) + { + bool memoryOK = true; + char * aPtr; + char aBuffer[ GHS3DPlugin_BUFLENGTH ]; + int aLineNb = 0; + do { + GHS3DPlugin_ReadLine( aPtr, aBuffer, aLogFile, aLineNb ); + if ( aPtr ) { + TCollection_AsciiString line( aPtr ); + if ( line.Search( "UNABLE TO ALLOCATE MEMORY" ) > 0 ) + memoryOK = false; + } + } while ( aPtr && memoryOK ); + + fclose( aLogFile ); + + if ( !memoryOK ) { + nbMB *= 0.75; + return adjustMemory( nbMB, aLogFileName ); + } + return true; + } + return false; +} + //============================================================================= /*! *Here we are going to use the GHS3D mesher @@ -481,8 +528,10 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, struct sysinfo si; int err = sysinfo( &si ); if ( err == 0 ) { + int MB = 0.9 * ( si.freeram + si.freeswap ) * si.mem_unit / 1024 / 1024; + adjustMemory( MB, aLogFileName ); memory = "-m "; - memory += int ( 0.8 * ( si.freeram + si.freeswap ) * si.mem_unit / 1024 / 1024 ); + memory += MB; } #endif @@ -533,48 +582,3 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, return Ok; } - - -//============================================================================= -/*! - * - */ -//============================================================================= - -ostream & GHS3DPlugin_GHS3D::SaveTo(ostream & save) -{ - return save; -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -istream & GHS3DPlugin_GHS3D::LoadFrom(istream & load) -{ - return load; -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -ostream & operator << (ostream & save, GHS3DPlugin_GHS3D & hyp) -{ - return hyp.SaveTo( save ); -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -istream & operator >> (istream & load, GHS3DPlugin_GHS3D & hyp) -{ - return hyp.LoadFrom( load ); -} diff --git a/src/GHS3DPlugin_GHS3D.hxx b/src/GHS3DPlugin_GHS3D.hxx index a3855ab..ebe1933 100644 --- a/src/GHS3DPlugin_GHS3D.hxx +++ b/src/GHS3DPlugin_GHS3D.hxx @@ -43,11 +43,6 @@ public: virtual bool Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape); - ostream & SaveTo(ostream & save); - istream & LoadFrom(istream & load); - friend ostream & operator << (ostream & save, GHS3DPlugin_GHS3D & hyp); - friend istream & operator >> (istream & load, GHS3DPlugin_GHS3D & hyp); - }; #endif -- 2.39.2