From: ouv Date: Wed, 27 Dec 2006 13:19:58 +0000 (+0000) Subject: Added possibility to enlarge cache X-Git-Tag: WP1_2_3_29-12-2006_MED_to_VTK_data_passing~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8faa82552ae11492e73211d5f1d380c918b3cabc;p=modules%2Fvisu.git Added possibility to enlarge cache --- diff --git a/idl/VISU_Gen.idl b/idl/VISU_Gen.idl index 90bf2592..334eb42c 100644 --- a/idl/VISU_Gen.idl +++ b/idl/VISU_Gen.idl @@ -635,6 +635,11 @@ module VISU { * Gets a %ColoredPrs3dCache, to which the holder belongs */ ColoredPrs3dCache GetCache(); + + /*! + * Gets memory size actually used by the holder (Mb). + */ + float GetMemorySize(); }; @@ -651,6 +656,13 @@ module VISU { LIMITED /*!< Limited memory mode (fixed memory size for presentations). */ }; + /*! This enumeration defines how to enlarge the cache limited memory. */ + enum EnlargeType { + NO_ENLARGE, /*!< No need to enlarge (default behaviour). */ + ENLARGE, /*!< Enlarge limited memory. */ + IMPOSSIBLE /*!< Impossible to enlarge (not enough free memory). */ + }; + /*! Sets a memory mode.*/ void SetMemoryMode(in MemoryMode theMode); @@ -671,6 +683,11 @@ module VISU { /*! Creates %ColoredPrs3dHolder.*/ ColoredPrs3dHolder CreateHolder(in VISUType theType, in ColoredPrs3dHolder::BasicInput theInput); + + /*! Gets a memory which is required to create a holder. */ + EnlargeType GetRequiredMemory(in VISUType theType, + in ColoredPrs3dHolder::BasicInput theInput, + out float theRequiredMemory); }; diff --git a/src/VISUGUI/VISU_msg_en.po b/src/VISUGUI/VISU_msg_en.po index 8e7dc696..d6447064 100644 --- a/src/VISUGUI/VISU_msg_en.po +++ b/src/VISUGUI/VISU_msg_en.po @@ -40,6 +40,12 @@ msgstr "Current Study is locked" msgid "WRN_NO_AVAILABLE_DATA" msgstr "No Available data in selection" +msgid "WRN_EXTRA_MEMORY_REQUIRED" +msgstr "Cache need more memory to build the presentation (%1 Mb).\nDo you want to enlarge the cache?" + +msgid "ERR_NO_MEMORY_TO_BUILD" +msgstr "Please, free %1 Mb to make the cache enlarging possible\n(for example, try to delete some holders)" + msgid "ERR_CANT_FIND_VISU_COMPONENT" msgstr "Failed to activate VISU engine!" @@ -184,7 +190,7 @@ msgid "VISU_LIMITED" msgstr "Limited" msgid "VISU_MEMORY_LIMIT" -msgstr "Memory limit" +msgstr "Memory limit (Mb)" #: VisuGUI.cxx diff --git a/src/VISUGUI/VisuGUI_Prs3dTools.h b/src/VISUGUI/VisuGUI_Prs3dTools.h index abcdac84..0761326e 100644 --- a/src/VISUGUI/VisuGUI_Prs3dTools.h +++ b/src/VISUGUI/VisuGUI_Prs3dTools.h @@ -32,6 +32,7 @@ #include "VisuGUI_Tools.h" #include "VisuGUI_ViewTools.h" #include "VISU_ColoredPrs3dFactory.hh" +#include "VISU_PipeLine.hxx" #include @@ -128,11 +129,51 @@ namespace VISU theFieldName, theTimeId); else - aPrs3d = VISU::CreateHolder2GetDeviceByType(aResult, - theMeshName, - theEntity, - theFieldName, - theTimeId); + { + float aRequiredMemory = 0.0; + VISU::ColoredPrs3dCache::EnlargeType anEnlargeType = + VISU::GetRequiredCacheMemory(aResult, + theMeshName, + theEntity, + theFieldName, + theTimeId, + aRequiredMemory); + + if( anEnlargeType == VISU::ColoredPrs3dCache::IMPOSSIBLE ) + { + long aMb = 1024 * 1024; + double aFreeMemory = (double)VISU_PipeLine::GetAvailableMemory( 2048 * aMb ) / (double)aMb; + + SUIT_MessageBox::warn1(GetDesktop(theModule), + QObject::tr("WRN_VISU"), + QObject::tr("ERR_NO_MEMORY_TO_BUILD").arg(aRequiredMemory - aFreeMemory), + QObject::tr("&OK") ); + QApplication::restoreOverrideCursor(); + return NULL; + } + else + { + if( anEnlargeType == VISU::ColoredPrs3dCache::ENLARGE ) + { + if(SUIT_MessageBox::info2(GetDesktop(theModule), + QObject::tr("WRN_VISU"), + QObject::tr("WRN_EXTRA_MEMORY_REQUIRED").arg(aRequiredMemory), + QObject::tr("&OK"), QObject::tr("&Cancel"), + 0, 1, 0) == 1) + { + QApplication::restoreOverrideCursor(); + return NULL; + } + } + aPrs3d = VISU::CreateHolder2GetDeviceByType(aResult, + theMeshName, + theEntity, + theFieldName, + theTimeId, + anEnlargeType, + aRequiredMemory); + } + } QApplication::restoreOverrideCursor(); if(aPrs3d) diff --git a/src/VISU_I/VISU_ColoredPrs3dCache_i.cc b/src/VISU_I/VISU_ColoredPrs3dCache_i.cc index 3947b4b6..07fbb5bf 100644 --- a/src/VISU_I/VISU_ColoredPrs3dCache_i.cc +++ b/src/VISU_I/VISU_ColoredPrs3dCache_i.cc @@ -33,6 +33,8 @@ #include "VISU_View_i.hh" #include "VISU_Actor.h" +#include "VISU_PipeLine.hxx" + #include "VTKViewer_Algorithm.h" #include "SVTK_Functor.h" @@ -267,6 +269,23 @@ VISU::ColoredPrs3dCache_i } +//---------------------------------------------------------------------------- +CORBA::Float +VISU::ColoredPrs3dCache_i +::GetDeviceMemorySize() +{ + CORBA::Float aMemoryUsed = 0.0; + TColoredPrs3dHolderMap::const_iterator aHolderIter = myHolderMap.begin(); + TColoredPrs3dHolderMap::const_iterator aHolderIterEnd = myHolderMap.end(); + for(; aHolderIter != aHolderIterEnd; aHolderIter++){ + const TLastVisitedPrsList& aPrsList = aHolderIter->second; + if(TPrs3dPtr aPrs3d = aPrsList.front()) + aMemoryUsed += aPrs3d->GetMemorySize(); + } + return aMemoryUsed; +} + + //---------------------------------------------------------------------------- int VISU::ColoredPrs3dCache_i @@ -284,10 +303,11 @@ VISU::ColoredPrs3dCache_i theInput, theType, aRawEstimatedMemorySize); + if( aMemoryUsed + aMemoryNeeded < aMemoryLimit ) return true; - theRequiredMemory = aMemoryNeeded; + theRequiredMemory = aMemoryNeeded - ( aMemoryLimit - aMemoryUsed ); TColoredPrs3dHolderMap aColoredPrs3dHolderMap; return SelectPrs3dToBeDeleted(theRequiredMemory, theHolderEntry, @@ -299,6 +319,39 @@ VISU::ColoredPrs3dCache_i } +//---------------------------------------------------------------------------- +VISU::ColoredPrs3dCache::EnlargeType +VISU::ColoredPrs3dCache_i +::GetRequiredMemory(VISU::VISUType theType, + const VISU::ColoredPrs3dHolder::BasicInput& theInput, + CORBA::Float& theRequiredMemory) +{ + VISU::ColoredPrs3dCache::EnlargeType anEnlargeType = VISU::ColoredPrs3dCache::NO_ENLARGE; + + size_t aRawEstimatedMemorySize = VISU::CheckIsPossible(theType, theInput, true); + if(aRawEstimatedMemorySize > 0){ + if(GetMemoryMode() == VISU::ColoredPrs3dCache::LIMITED){ + CORBA::Float aMemoryUsed = GetDeviceMemorySize(); + CORBA::Float aMemoryLimit = GetLimitedMemory(); + CORBA::Float aMemoryNeeded = EstimateMemorySize(myHolderMap, + theInput, + theType, + aRawEstimatedMemorySize); + if( aMemoryUsed + aMemoryNeeded < aMemoryLimit ) + return anEnlargeType; + + theRequiredMemory = int( aMemoryUsed + aMemoryNeeded ) + 1; + + long aMb = 1024 * 1024; + double aFreeMemory = (double)VISU_PipeLine::GetAvailableMemory( 2048 * aMb ) / (double)aMb; + anEnlargeType = theRequiredMemory < aFreeMemory ? + VISU::ColoredPrs3dCache::ENLARGE : VISU::ColoredPrs3dCache::IMPOSSIBLE; + } + } + return anEnlargeType; +} + + //---------------------------------------------------------------------------- VISU::ColoredPrs3dCache_i* VISU::ColoredPrs3dCache_i @@ -378,6 +431,14 @@ void VISU::ColoredPrs3dCache_i ::SetLimitedMemory(CORBA::Float theMemorySize) { + if( fabs( myLimitedMemory - theMemorySize ) < 1 / VTK_LARGE_FLOAT ) + return; + + long aMb = 1024 * 1024; + double aFreeMemory = (double)VISU_PipeLine::GetAvailableMemory( 2048 * aMb ) / (double)aMb; + if( theMemorySize > aFreeMemory ) + return; + ClearCache(theMemorySize); myLimitedMemory = theMemorySize; } @@ -614,28 +675,31 @@ void VISU::ColoredPrs3dCache_i ::PrintCache() { - cout << "--------------CACHE-----------------" << endl; - cout << "Cache memory - " << GetMemorySize() << " Mb" << endl; - TColoredPrs3dHolderMap::const_iterator aHolderIter = myHolderMap.begin(); - TColoredPrs3dHolderMap::const_iterator aHolderIterEnd = myHolderMap.end(); - for(; aHolderIter != aHolderIterEnd; aHolderIter++){ - const TLastVisitedPrsList& aPrsList = aHolderIter->second; - TLastVisitedPrsList::const_iterator aPrsIter = aPrsList.begin(); - TLastVisitedPrsList::const_iterator aPrsIterEnd = aPrsList.end(); - - cout << "--------------------------" << endl; - cout << "Holder - " << aHolderIter->first.c_str() << endl; - cout << "Size - " << aPrsList.size() << endl; - for(; aPrsIter != aPrsIterEnd; aPrsIter++) - if(TPrs3dPtr aPrs3d = *aPrsIter) - { - cout << aPrs3d << " (" << aPrs3d->GetMemorySize() << " Mb)"; - if(aPrsIter == aPrsList.begin()) - cout << " (device)"; - cout << endl; - } + if(MYDEBUG) + { + cout << "--------------CACHE-----------------" << endl; + cout << "Cache memory - " << GetMemorySize() << " Mb" << endl; + TColoredPrs3dHolderMap::const_iterator aHolderIter = myHolderMap.begin(); + TColoredPrs3dHolderMap::const_iterator aHolderIterEnd = myHolderMap.end(); + for(; aHolderIter != aHolderIterEnd; aHolderIter++){ + const TLastVisitedPrsList& aPrsList = aHolderIter->second; + TLastVisitedPrsList::const_iterator aPrsIter = aPrsList.begin(); + TLastVisitedPrsList::const_iterator aPrsIterEnd = aPrsList.end(); + + cout << "--------------------------" << endl; + cout << "Holder - " << aHolderIter->first.c_str() << endl; + cout << "Size - " << aPrsList.size() << endl; + for(; aPrsIter != aPrsIterEnd; aPrsIter++) + if(TPrs3dPtr aPrs3d = *aPrsIter) + { + cout << aPrs3d << " (" << aPrs3d->GetMemorySize() << " Mb)"; + if(aPrsIter == aPrsList.begin()) + cout << " (device)"; + cout << endl; + } + } + cout << "------------------------------------" << endl; } - cout << "------------------------------------" << endl; } diff --git a/src/VISU_I/VISU_ColoredPrs3dCache_i.hh b/src/VISU_I/VISU_ColoredPrs3dCache_i.hh index 2ba3cda7..56ab4a22 100644 --- a/src/VISU_I/VISU_ColoredPrs3dCache_i.hh +++ b/src/VISU_I/VISU_ColoredPrs3dCache_i.hh @@ -126,6 +126,14 @@ namespace VISU CreateHolder(VISU::VISUType theType, const VISU::ColoredPrs3dHolder::BasicInput& theInput); + //---------------------------------------------------------------------------- + /*! Gets a memory which is required to create a holder. */ + virtual + VISU::ColoredPrs3dCache::EnlargeType + GetRequiredMemory(VISU::VISUType theType, + const VISU::ColoredPrs3dHolder::BasicInput& theInput, + CORBA::Float& theRequiredMemory); + //---------------------------------------------------------------------------- //! Sets a memory mode. virtual @@ -150,6 +158,10 @@ namespace VISU CORBA::Float GetMemorySize(); + virtual + CORBA::Float + GetDeviceMemorySize(); + //---------------------------------------------------------------------------- virtual VISU::VISUType diff --git a/src/VISU_I/VISU_ColoredPrs3dFactory.cc b/src/VISU_I/VISU_ColoredPrs3dFactory.cc index e1129b81..5634f014 100644 --- a/src/VISU_I/VISU_ColoredPrs3dFactory.cc +++ b/src/VISU_I/VISU_ColoredPrs3dFactory.cc @@ -132,6 +132,34 @@ namespace VISU } + //---------------------------------------------------------------------------- + VISU::ColoredPrs3dCache::EnlargeType + GetRequiredCacheMemory(VISU::VISUType theType, + VISU::Result_ptr theResult, + const std::string& theMeshName, + VISU::Entity theEntity, + const std::string& theFieldName, + CORBA::Long theIteration, + CORBA::Float& theRequiredMemory) + { + VISU::ColoredPrs3dCache::EnlargeType anEnlargeType = VISU::ColoredPrs3dCache::NO_ENLARGE; + if(Result_i* aResult = dynamic_cast(GetServant(theResult).in())){ + VISU::ColoredPrs3dHolder::BasicInput anInput; + anInput.myResult = VISU::Result::_duplicate(theResult); + anInput.myMeshName = theMeshName.c_str(); + anInput.myEntity = theEntity; + anInput.myFieldName = theFieldName.c_str(); + anInput.myTimeStampNumber = theIteration; + + SALOMEDS::Study_var aStudy = aResult->GetStudyDocument(); + VISU::ColoredPrs3dCache_var aCache = ColoredPrs3dCache_i::GetInstance(aStudy); + + anEnlargeType = aCache->GetRequiredMemory(theType, anInput, theRequiredMemory); + } + return anEnlargeType; + } + + //---------------------------------------------------------------------------- VISU::ColoredPrs3d_i* CreateHolder2GetDeviceByEnum(VISU::VISUType theType, @@ -139,7 +167,9 @@ namespace VISU const std::string& theMeshName, VISU::Entity theEntity, const std::string& theFieldName, - CORBA::Long theIteration) + CORBA::Long theIteration, + VISU::ColoredPrs3dCache::EnlargeType theEnlargeType, + CORBA::Float theRequiredMemory) { VISU::ColoredPrs3d_i* aColoredPrs3d = NULL; if(Result_i* aResult = dynamic_cast(GetServant(theResult).in())){ @@ -152,6 +182,10 @@ namespace VISU SALOMEDS::Study_var aStudy = aResult->GetStudyDocument(); VISU::ColoredPrs3dCache_var aCache = ColoredPrs3dCache_i::GetInstance(aStudy); + + if( theEnlargeType == VISU::ColoredPrs3dCache::ENLARGE ) + aCache->SetLimitedMemory( theRequiredMemory ); + VISU::ColoredPrs3dHolder_var aHolder = aCache->CreateHolder(theType, anInput); if( CORBA::is_nil(aHolder) ) diff --git a/src/VISU_I/VISU_ColoredPrs3dFactory.hh b/src/VISU_I/VISU_ColoredPrs3dFactory.hh index 9bc14a38..0deb370a 100644 --- a/src/VISU_I/VISU_ColoredPrs3dFactory.hh +++ b/src/VISU_I/VISU_ColoredPrs3dFactory.hh @@ -246,6 +246,41 @@ namespace VISU } + //---------------------------------------------------------------------------- + //! Gets the memory required for cache + VISU::ColoredPrs3dCache::EnlargeType + GetRequiredCacheMemory(VISU::VISUType theType, + VISU::Result_ptr theResult, + const std::string& theMeshName, + VISU::Entity theEntity, + const std::string& theFieldName, + CORBA::Long theTimeStampNumber, + CORBA::Float& theRequiredMemory); + + + //---------------------------------------------------------------------------- + //! Gets the memory required for cache + template + VISU::ColoredPrs3dCache::EnlargeType + GetRequiredCacheMemory(VISU::Result_ptr theResult, + const std::string& theMeshName, + VISU::Entity theEntity, + const std::string& theFieldName, + CORBA::Long theTimeStampNumber, + CORBA::Float& theRequiredMemory) + { + typedef typename TL::TColoredType2Enum::TResult TEnum; + VISU::VISUType aColoredPrs3dType = VISU::VISUType(TEnum::value); + return GetRequiredCacheMemory(aColoredPrs3dType, + theResult, + theMeshName, + theEntity, + theFieldName, + theTimeStampNumber, + theRequiredMemory); + } + + //---------------------------------------------------------------------------- //! Creates ColoredPrs3dHolder by enumeration value and gets its first device ColoredPrs3d_i* @@ -254,7 +289,9 @@ namespace VISU const std::string& theMeshName, VISU::Entity theEntity, const std::string& theFieldName, - CORBA::Long theTimeStampNumber); + CORBA::Long theTimeStampNumber, + VISU::ColoredPrs3dCache::EnlargeType theEnlargeType, + CORBA::Float theRequiredMemory); //---------------------------------------------------------------------------- @@ -265,7 +302,9 @@ namespace VISU const std::string& theMeshName, VISU::Entity theEntity, const std::string& theFieldName, - CORBA::Long theTimeStampNumber) + CORBA::Long theTimeStampNumber, + VISU::ColoredPrs3dCache::EnlargeType theEnlargeType, + CORBA::Float theRequiredMemory) { typedef typename TL::TColoredType2Enum::TResult TEnum; VISU::VISUType aColoredPrs3dType = VISU::VISUType(TEnum::value); @@ -274,7 +313,9 @@ namespace VISU theMeshName, theEntity, theFieldName, - theTimeStampNumber); + theTimeStampNumber, + theEnlargeType, + theRequiredMemory); return dynamic_cast(aColoredPrs3d); } diff --git a/src/VISU_I/VISU_ColoredPrs3dHolder_i.cc b/src/VISU_I/VISU_ColoredPrs3dHolder_i.cc index afb4a99a..32b2bc39 100644 --- a/src/VISU_I/VISU_ColoredPrs3dHolder_i.cc +++ b/src/VISU_I/VISU_ColoredPrs3dHolder_i.cc @@ -155,6 +155,16 @@ VISU::ColoredPrs3dHolder_i } +//---------------------------------------------------------------------------- +CORBA::Float +VISU::ColoredPrs3dHolder_i +::GetMemorySize() +{ + // tmp + return GetDevice()->GetMemorySize(); +} + + //---------------------------------------------------------------------------- VISU::VISUType VISU::ColoredPrs3dHolder_i diff --git a/src/VISU_I/VISU_ColoredPrs3dHolder_i.hh b/src/VISU_I/VISU_ColoredPrs3dHolder_i.hh index f2bb397e..2b6a9c9d 100644 --- a/src/VISU_I/VISU_ColoredPrs3dHolder_i.hh +++ b/src/VISU_I/VISU_ColoredPrs3dHolder_i.hh @@ -82,6 +82,7 @@ namespace VISU VISU::ColoredPrs3d::TimeStampsRange* GetTimeStampsRange(); + //---------------------------------------------------------------------------- //! Gets input parameters of the last visited presentation. VISU::ColoredPrs3dHolder::BasicInput* GetBasicInput(); @@ -91,6 +92,12 @@ namespace VISU VISU::ColoredPrs3dCache_ptr GetCache(); + //---------------------------------------------------------------------------- + //! Gets memory size actually used by the holder (Mb). + virtual + CORBA::Float + GetMemorySize(); + //---------------------------------------------------------------------------- virtual VISU::VISUType