* Gets a %ColoredPrs3dCache, to which the holder belongs
*/
ColoredPrs3dCache GetCache();
+
+ /*!
+ * Gets memory size actually used by the holder (Mb).
+ */
+ float GetMemorySize();
};
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);
/*! 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);
};
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!"
msgstr "Limited"
msgid "VISU_MEMORY_LIMIT"
-msgstr "Memory limit"
+msgstr "Memory limit (Mb)"
#: VisuGUI.cxx
#include "VisuGUI_Tools.h"
#include "VisuGUI_ViewTools.h"
#include "VISU_ColoredPrs3dFactory.hh"
+#include "VISU_PipeLine.hxx"
#include <vtkRenderer.h>
theFieldName,
theTimeId);
else
- aPrs3d = VISU::CreateHolder2GetDeviceByType<TPrs3d_i>(aResult,
- theMeshName,
- theEntity,
- theFieldName,
- theTimeId);
+ {
+ float aRequiredMemory = 0.0;
+ VISU::ColoredPrs3dCache::EnlargeType anEnlargeType =
+ VISU::GetRequiredCacheMemory<TPrs3d_i>(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<TPrs3d_i>(aResult,
+ theMeshName,
+ theEntity,
+ theFieldName,
+ theTimeId,
+ anEnlargeType,
+ aRequiredMemory);
+ }
+ }
QApplication::restoreOverrideCursor();
if(aPrs3d)
#include "VISU_View_i.hh"
#include "VISU_Actor.h"
+#include "VISU_PipeLine.hxx"
+
#include "VTKViewer_Algorithm.h"
#include "SVTK_Functor.h"
}
+//----------------------------------------------------------------------------
+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
theInput,
theType,
aRawEstimatedMemorySize);
+
if( aMemoryUsed + aMemoryNeeded < aMemoryLimit )
return true;
- theRequiredMemory = aMemoryNeeded;
+ theRequiredMemory = aMemoryNeeded - ( aMemoryLimit - aMemoryUsed );
TColoredPrs3dHolderMap aColoredPrs3dHolderMap;
return SelectPrs3dToBeDeleted(theRequiredMemory,
theHolderEntry,
}
+//----------------------------------------------------------------------------
+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
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;
}
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;
}
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
CORBA::Float
GetMemorySize();
+ virtual
+ CORBA::Float
+ GetDeviceMemorySize();
+
//----------------------------------------------------------------------------
virtual
VISU::VISUType
}
+ //----------------------------------------------------------------------------
+ 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<Result_i*>(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,
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<Result_i*>(GetServant(theResult).in())){
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) )
}
+ //----------------------------------------------------------------------------
+ //! 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<class TColoredPrs3d_i>
+ 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<TColoredPrs3d_i>::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*
const std::string& theMeshName,
VISU::Entity theEntity,
const std::string& theFieldName,
- CORBA::Long theTimeStampNumber);
+ CORBA::Long theTimeStampNumber,
+ VISU::ColoredPrs3dCache::EnlargeType theEnlargeType,
+ CORBA::Float theRequiredMemory);
//----------------------------------------------------------------------------
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<TColoredPrs3d_i>::TResult TEnum;
VISU::VISUType aColoredPrs3dType = VISU::VISUType(TEnum::value);
theMeshName,
theEntity,
theFieldName,
- theTimeStampNumber);
+ theTimeStampNumber,
+ theEnlargeType,
+ theRequiredMemory);
return dynamic_cast<TColoredPrs3d_i*>(aColoredPrs3d);
}
}
+//----------------------------------------------------------------------------
+CORBA::Float
+VISU::ColoredPrs3dHolder_i
+::GetMemorySize()
+{
+ // tmp
+ return GetDevice()->GetMemorySize();
+}
+
+
//----------------------------------------------------------------------------
VISU::VISUType
VISU::ColoredPrs3dHolder_i
VISU::ColoredPrs3d::TimeStampsRange*
GetTimeStampsRange();
+ //----------------------------------------------------------------------------
//! Gets input parameters of the last visited presentation.
VISU::ColoredPrs3dHolder::BasicInput*
GetBasicInput();
VISU::ColoredPrs3dCache_ptr
GetCache();
+ //----------------------------------------------------------------------------
+ //! Gets memory size actually used by the holder (Mb).
+ virtual
+ CORBA::Float
+ GetMemorySize();
+
//----------------------------------------------------------------------------
virtual
VISU::VISUType