From: ouv Date: Fri, 24 Nov 2006 16:54:28 +0000 (+0000) Subject: Cache system X-Git-Tag: WP1_2_3_05-12-2006_cache_system~63 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=43e2ddd8e26fea2c8f44946be2aed0dfa3336a01;p=modules%2Fvisu.git Cache system --- diff --git a/resources/SalomeApp.xml b/resources/SalomeApp.xml index d388080a..518184ba 100644 --- a/resources/SalomeApp.xml +++ b/resources/SalomeApp.xml @@ -110,7 +110,7 @@ - +
diff --git a/src/VISUGUI/VisuGUI_CacheDlg.cxx b/src/VISUGUI/VisuGUI_CacheDlg.cxx index 0e7e434f..2ee018b5 100644 --- a/src/VISUGUI/VisuGUI_CacheDlg.cxx +++ b/src/VISUGUI/VisuGUI_CacheDlg.cxx @@ -29,6 +29,7 @@ #include "VisuGUI_Tools.h" +#include "VISU_PipeLine.hxx" #include "VISU_ColoredPrs3dCache_i.hh" #include "SUIT_Desktop.h" @@ -68,8 +69,11 @@ VisuGUI_CacheDlg::VisuGUI_CacheDlg( SalomeApp_Module* theModule, bool theIsLimit myMimimalMemoryButton = new QRadioButton( tr( "MINIMAL_MEMORY" ), aMemoryGroup ); myMimimalMemoryButton->setChecked( !theIsLimitedMemory ); - myLimitedMemory = new QSpinBox( 1, 5000, 1, aMemoryGroup ); - myLimitedMemory->setSuffix( " Mb" ); + // start from 1Gb + long aLimitedMemoryMax = ( long )( VISU_PipeLine::GetAvailableMemory( 1024 * 1024 * 1024.0 ) / 1024.0 ); + + myLimitedMemory = new QSpinBox( 1, aLimitedMemoryMax, 10, aMemoryGroup ); + myLimitedMemory->setSuffix( " kb" ); myLimitedMemory->setValue( theLimitedMemory ); myLimitedMemory->setEnabled( theIsLimitedMemory ); diff --git a/src/VISUGUI/VisuGUI_Module.cxx b/src/VISUGUI/VisuGUI_Module.cxx index 4dbc5fd7..c073f752 100644 --- a/src/VISUGUI/VisuGUI_Module.cxx +++ b/src/VISUGUI/VisuGUI_Module.cxx @@ -423,7 +423,7 @@ onCreateViewManager() VVTK_ViewWindow* aViewWindow = ( VVTK_ViewWindow* )aViewManager->createViewWindow(); if( aViewWindow ) { - new VisuGUI_Slider( aViewWindow, anApp->selectionMgr() ); + new VisuGUI_Slider( this, aViewWindow, anApp->selectionMgr() ); } return aViewer->getViewManager(); diff --git a/src/VISUGUI/VisuGUI_Slider.cxx b/src/VISUGUI/VisuGUI_Slider.cxx index 72b06314..25f61d9f 100644 --- a/src/VISUGUI/VisuGUI_Slider.cxx +++ b/src/VISUGUI/VisuGUI_Slider.cxx @@ -48,9 +48,13 @@ #include "VVTK_MainWindow.h" #include "VVTK_ViewWindow.h" +#include "VISU_Gen_i.hh" #include "VISU_ColoredPrs3d_i.hh" #include "VISU_ColoredPrs3dHolder_i.hh" +#include "VisuGUI_Module.h" +#include "VisuGUI_Tools.h" + #include #include @@ -68,9 +72,11 @@ /*! Constructor */ -VisuGUI_Slider::VisuGUI_Slider( VVTK_ViewWindow* theViewWindow, +VisuGUI_Slider::VisuGUI_Slider( VisuGUI_Module* theModule, + VVTK_ViewWindow* theViewWindow, LightApp_SelectionMgr* theSelectionMgr ) : QtxDockWindow( InDock, theViewWindow->getMainWindow1() ), + myModule( theModule ), myMainWindow( theViewWindow->getMainWindow1() ), mySelectionMgr( theSelectionMgr ) { @@ -210,13 +216,15 @@ void VisuGUI_Slider::enableControls( bool on ) myTimeStampStrings->clear(); myTimeStampIndices->clear(); - if( myPrsList.size() == 0 ) + if( myHolderList.size() == 0 ) return; - VISU::ColoredPrs3d_i* aPrs = myPrsList[0]; + VISU::ColoredPrs3dHolder_var aHolder = myHolderList[0]; + VISU::ColoredPrs3d_var aPrs = aHolder->GetDevice(); CORBA::Long aTimeStampNumber = aPrs->GetTimeStampNumber(); VISU::ColoredPrs3d::TimeStampsRange_var aTimeStampsRange = aPrs->GetTimeStampsRange(); + CORBA::Long aLength = aTimeStampsRange->length(); mySlider->setMinValue( 0 ); @@ -258,7 +266,8 @@ void VisuGUI_Slider::enableControls( bool on ) void VisuGUI_Slider::onSelectionChanged() { - myPrsList.resize(0); + //cout << "VisuGUI_Slider::onSelectionChanged()" << endl; + myHolderList.resize(0); _PTR(SObject) aSObject; @@ -279,27 +288,21 @@ void VisuGUI_Slider::onSelectionChanged() if (aSObject) { CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject); if (!CORBA::is_nil(anObject)) { - VISU::ColoredPrs3dHolder_i* aHolder = - dynamic_cast(VISU::GetServant(anObject).in()); + VISU::ColoredPrs3dHolder_var aHolder = VISU::ColoredPrs3dHolder::_narrow(anObject); - if( aHolder ) + if(!CORBA::is_nil(aHolder)) { - VISU::ColoredPrs3d_i* aPrs = - dynamic_cast( VISU::GetServant(aHolder->GetDevice()).in() ); - - if( aPrs && !aPrs->IsTimeStampFixed() ) { - //cout << "ColoredPrs3d" << endl; - myPrsList.resize(k+1); - myPrsList[k] = aPrs; - k++; - } + //cout << "ColoredPrs3dHolder" << endl; + myHolderList.resize(k+1); + myHolderList[k] = aHolder; + k++; } } } } } - enableControls( myPrsList.size() != 0 ); + enableControls( myHolderList.size() != 0 ); } void VisuGUI_Slider::onTimeStampActivated( int value ) @@ -356,22 +359,40 @@ void VisuGUI_Slider::onLast() void VisuGUI_Slider::onValueChanged( int value ) { - if( myPrsList.size() == 0 ) + if( myHolderList.size() == 0 ) return; - VISU::ColoredPrs3d_i* aPrs = myPrsList[0]; + VISU::ColoredPrs3dHolder_var aHolder = myHolderList[0]; + VISU::ColoredPrs3d_var aPrs = aHolder->GetDevice(); + VISU::ColoredPrs3d::TimeStampsRange_var aTimeStampsRange = aPrs->GetTimeStampsRange(); + CORBA::Long aLength = aTimeStampsRange->length(); if(value < 0 || aLength <= value) return; CORBA::Long aNumber = aTimeStampsRange[ value ].myNumber; - for( int i = 0, n = myPrsList.size(); i < n; i++ ) + HolderList::iterator it = myHolderList.begin(); + HolderList::iterator itEnd = myHolderList.end(); + for( ; it != itEnd; ++it ) { - aPrs = myPrsList[i]; - aPrs->SetTimeStampNumber( aNumber ); - aPrs->Apply(); + VISU::ColoredPrs3dHolder_var aHolder = *it; + if( CORBA::is_nil( aHolder.in() ) ) + continue; + + VISU::ColoredPrs3dHolder::BasicInput* anInput = aHolder->GetBasicInput(); + anInput->myTimeStampNumber = aNumber; + + VISU::View_var aView = VISU::GetVisuGen( myModule )->GetViewManager()->GetCurrentView(); + if( CORBA::is_nil( aView.in() ) ) + continue; + + VISU::View3D_var aView3D = VISU::View3D::_narrow( aView ); + if( CORBA::is_nil( aView3D.in() ) ) + continue; + + aHolder->Apply( aHolder->GetDevice(), *anInput, aView3D ); } myTimeStampStrings->setCurrentItem( value ); diff --git a/src/VISUGUI/VisuGUI_Slider.h b/src/VISUGUI/VisuGUI_Slider.h index 6075ecc5..f4473268 100644 --- a/src/VISUGUI/VisuGUI_Slider.h +++ b/src/VISUGUI/VisuGUI_Slider.h @@ -31,12 +31,15 @@ #include "QtxDockWindow.h" #include +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(VISU_Gen) + namespace VISU { - class ColoredPrs3d_i; + class ColoredPrs3dHolder_i; } -typedef std::vector PrsList; +typedef std::vector HolderList; class QCheckBox; class QComboBox; @@ -50,12 +53,15 @@ class VVTK_ViewWindow; class VVTK_MainWindow; class LightApp_SelectionMgr; +class VisuGUI_Module; + class VisuGUI_Slider : public QtxDockWindow { Q_OBJECT public: - VisuGUI_Slider( VVTK_ViewWindow* theViewWindow, + VisuGUI_Slider( VisuGUI_Module* theModule, + VVTK_ViewWindow* theViewWindow, LightApp_SelectionMgr* theSelectionMgr ); virtual ~VisuGUI_Slider(); @@ -82,6 +88,7 @@ public slots: virtual void onTimeout(); private: + VisuGUI_Module* myModule; VVTK_MainWindow* myMainWindow; LightApp_SelectionMgr* mySelectionMgr; @@ -105,7 +112,8 @@ private: QTimer* myTimer; - PrsList myPrsList; + //PrsList myPrsList; + HolderList myHolderList; }; #endif diff --git a/src/VISU_I/VISU_ColoredPrs3dCache_i.cc b/src/VISU_I/VISU_ColoredPrs3dCache_i.cc index a6ef3c79..93af6996 100644 --- a/src/VISU_I/VISU_ColoredPrs3dCache_i.cc +++ b/src/VISU_I/VISU_ColoredPrs3dCache_i.cc @@ -31,6 +31,9 @@ #include "VISU_View_i.hh" #include "VISU_ViewManager_i.hh" +#include "VISU_Convertor.hxx" +#include "VISU_PipeLine.hxx" + #include "VVTK_ViewWindow.h" #include "SUIT_ResourceMgr.h" @@ -40,6 +43,10 @@ static int MYDEBUG = 0; static int MYDEBUG = 0; #endif +static int INCMEMORY = 4; + +static int MEMORY_UNIT = 1000; + //---------------------------------------------------------------------------- VISU::ColoredPrs3dCache_i ::ColoredPrs3dCache_i(SALOMEDS::Study_ptr theStudy): @@ -56,12 +63,11 @@ VISU::ColoredPrs3dCache_i SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr(); - bool anIsLimitedMemory = aResourceMgr->booleanValue( "VISU", "cache_is_limited_memory", true ); + bool anIsLimitedMemory = aResourceMgr->booleanValue( "VISU", "cache_is_limited_memory", false ); SetMemoryMode( anIsLimitedMemory ? VISU::ColoredPrs3dCache::LIMITED : VISU::ColoredPrs3dCache::MINIMAL ); - int aLimitedMemory = aResourceMgr->integerValue( "VISU", "cache_limited_memory", 10 ); + int aLimitedMemory = aResourceMgr->integerValue( "VISU", "cache_limited_memory", 1000 ); SetLimitedMemory( aLimitedMemory ); - } @@ -99,37 +105,90 @@ CheckIsPossible(const VISU::ColoredPrs3dHolder::BasicInput& theInput) return TColoredPrs3d::IsPossible(aResult,aMeshName,anEntity,aFieldName,aTimeStampNumber); } + //---------------------------------------------------------------------------- int VISU::ColoredPrs3dCache_i ::IsPossible(VISU::VISUType theType, - const VISU::ColoredPrs3dHolder::BasicInput& theInput) + const VISU::ColoredPrs3dHolder::BasicInput& theInput, + bool theMemoryCheck) { //cout << "VISU::ColoredPrs3dCache_i::IsPossible " << endl; + bool anIsPossible = false; switch(theType){ case TSCALARMAP: - return CheckIsPossible(theInput); + anIsPossible = CheckIsPossible(theInput); case TGAUSSPOINTS: - return CheckIsPossible(theInput); + anIsPossible = CheckIsPossible(theInput); case TDEFORMEDSHAPE: - return CheckIsPossible(theInput); + anIsPossible = CheckIsPossible(theInput); case TSCALARMAPONDEFORMEDSHAPE: - return CheckIsPossible(theInput); + anIsPossible = CheckIsPossible(theInput); case TISOSURFACE: - return CheckIsPossible(theInput); + anIsPossible = CheckIsPossible(theInput); case TSTREAMLINES: - return CheckIsPossible(theInput); + anIsPossible = CheckIsPossible(theInput); case TPLOT3D: - return CheckIsPossible(theInput); + anIsPossible = CheckIsPossible(theInput); case TCUTPLANES: - return CheckIsPossible(theInput); + anIsPossible = CheckIsPossible(theInput); case TCUTLINES: - return CheckIsPossible(theInput); + anIsPossible = CheckIsPossible(theInput); case TVECTORS: - return CheckIsPossible(theInput); + anIsPossible = CheckIsPossible(theInput); } - return 0; + if( anIsPossible && theMemoryCheck ) + { + //cout << "Memory checking..." << endl; + if( GetMemoryMode() == VISU::ColoredPrs3dCache::LIMITED ) + { + long aMemoryUsed = 0; + + VISU::ColoredPrs3d_i* aPrs3d; + TColoredPrs3dHolderMap::iterator aMapIterator = myHolderMap.begin(); + TColoredPrs3dHolderMap::iterator aMapIteratorEnd = myHolderMap.end(); + for(; aMapIterator != aMapIteratorEnd; ++aMapIterator) + { + TLastVisitedPrsList aList = aMapIterator->second; + + TLastVisitedPrsList::iterator it = aList.begin(); + TLastVisitedPrsList::iterator itEnd = aList.end(); + for(; it != itEnd; ++it) + { + aPrs3d = *it; + if( aPrs3d ) + aMemoryUsed += aPrs3d->GetMemorySize(); + } + } + + long aMemoryLimit = GetLimitedMemory() * MEMORY_UNIT; + + //cout << "Cache memory : " << aMemoryLimit << endl; + //cout << "Memory used : " << aMemoryUsed << endl; + + VISU::Result_i* aResult = dynamic_cast( VISU::GetServant(theInput.myResult).in() ); + std::string aMeshName = theInput.myMeshName.in(); + VISU::Entity anEntity = theInput.myEntity; + std::string aFieldName = theInput.myFieldName.in(); + long aTimeStampNumber = theInput.myTimeStampNumber; + + VISU::Result_i::TInput* anInput = aResult->GetInput(); + float aMemoryNeeded = anInput->GetTimeStampSize(aMeshName, + (VISU::TEntity)anEntity, + aFieldName, + aTimeStampNumber); + aMemoryNeeded *= INCMEMORY; + //cout << "Memory needed : " << aMemoryNeeded << endl; + + if( aMemoryUsed + aMemoryNeeded > aMemoryLimit ) + anIsPossible = false; + } + else + anIsPossible = false; + } + + return anIsPossible; } @@ -260,6 +319,9 @@ CreateHolder2GetDeviceByEnum(VISU::VISUType theType, VISU::ColoredPrs3dCache_var aCache = ColoredPrs3dCache_i::GetInstance(aStudy); VISU::ColoredPrs3dHolder_var aHolder = aCache->CreateHolder(theType, anInput); + if( CORBA::is_nil(aHolder) ) + return NULL; + VISU::ColoredPrs3d_var aPrs3d = aHolder->GetDevice(); aColoredPrs3d = dynamic_cast(GetServant(aPrs3d).in()); } @@ -325,7 +387,7 @@ VISU::ColoredPrs3dCache_i { TLastVisitedPrsList aList = GetLastVisitedPrsList(theHolder); if( !aList.empty() ) - return aList.front(); + return aList.back(); return NULL; } @@ -378,7 +440,7 @@ VISU::ColoredPrs3dCache_i { aLastVisitedPrsList.pop_front(); } - else if(IsPossible(theHolder->GetPrsType(), theInput)) + else if(IsPossible(theHolder->GetPrsType(), theInput, true)) { aPrs3d = CreatePrs(theHolder->GetPrsType(), theInput, theHolder); //cout << "Created " << aPrs3d->GetName() << endl; @@ -391,7 +453,7 @@ VISU::ColoredPrs3dCache_i } aLastVisitedPrsList.push_back(aPrs3d); - //aPrs3d->SameAs(thePrs); + aPrs3d->SameAs(thePrs); if(aPrs3d && !CORBA::is_nil(theView3D)) { diff --git a/src/VISU_I/VISU_ColoredPrs3dCache_i.hh b/src/VISU_I/VISU_ColoredPrs3dCache_i.hh index 4eb1f3cb..ad847d82 100644 --- a/src/VISU_I/VISU_ColoredPrs3dCache_i.hh +++ b/src/VISU_I/VISU_ColoredPrs3dCache_i.hh @@ -158,7 +158,8 @@ namespace VISU //---------------------------------------------------------------------------- virtual int IsPossible(VISU::VISUType theType, - const VISU::ColoredPrs3dHolder::BasicInput& theInput); + const VISU::ColoredPrs3dHolder::BasicInput& theInput, + bool theMemoryCheck = false); VISU::ColoredPrs3d_i* FindPrsByInput(TLastVisitedPrsList& theLastVisitedPrsList, diff --git a/src/VISU_I/VISU_ColoredPrs3d_i.cc b/src/VISU_I/VISU_ColoredPrs3d_i.cc index 9fa199d3..f6e71de9 100644 --- a/src/VISU_I/VISU_ColoredPrs3d_i.cc +++ b/src/VISU_I/VISU_ColoredPrs3d_i.cc @@ -43,6 +43,8 @@ static int MYDEBUG = 0; static int MYDEBUG = 0; #endif +static int INCMEMORY = 4; + //============================================================================ VISU::ColoredPrs3d_i:: @@ -342,6 +344,26 @@ VISU::ColoredPrs3d_i return aTimeStampsRange._retn(); } +CORBA::Long +VISU::ColoredPrs3d_i +::GetMemorySize() +{ + VISU::Result_i* aResult = dynamic_cast( VISU::GetServant(GetResultObject()).in() ); + std::string aMeshName = GetCMeshName(); + VISU::Entity anEntity = GetEntity(); + std::string aFieldName = GetCFieldName(); + long aTimeStampNumber = GetTimeStampNumber(); + + VISU::Result_i::TInput* anInput = aResult->GetInput(); + float aSize = anInput->GetTimeStampSize(aMeshName, + (VISU::TEntity)anEntity, + aFieldName, + aTimeStampNumber); + aSize *= INCMEMORY; + + return (CORBA::Long)aSize; +} + VISU::ColoredPrs3dHolder::BasicInput* VISU::ColoredPrs3d_i ::GetBasicInput() diff --git a/src/VISU_I/VISU_ColoredPrs3d_i.hh b/src/VISU_I/VISU_ColoredPrs3d_i.hh index 19ad5515..ab830a34 100644 --- a/src/VISU_I/VISU_ColoredPrs3d_i.hh +++ b/src/VISU_I/VISU_ColoredPrs3d_i.hh @@ -217,7 +217,7 @@ namespace VISU virtual CORBA::Long - GetMemorySize() { return 0; } + GetMemorySize(); //! Returns presentation input VISU::ColoredPrs3dHolder::BasicInput*