]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Cache system
authorouv <ouv@opencascade.com>
Fri, 24 Nov 2006 16:54:28 +0000 (16:54 +0000)
committerouv <ouv@opencascade.com>
Fri, 24 Nov 2006 16:54:28 +0000 (16:54 +0000)
resources/SalomeApp.xml
src/VISUGUI/VisuGUI_CacheDlg.cxx
src/VISUGUI/VisuGUI_Module.cxx
src/VISUGUI/VisuGUI_Slider.cxx
src/VISUGUI/VisuGUI_Slider.h
src/VISU_I/VISU_ColoredPrs3dCache_i.cc
src/VISU_I/VISU_ColoredPrs3dCache_i.hh
src/VISU_I/VISU_ColoredPrs3d_i.cc
src/VISU_I/VISU_ColoredPrs3d_i.hh

index d388080a0e38a7456764b5ba5a25674202917448..518184ba31b8817ae211907c1d905ecfe3749224 100644 (file)
     <parameter name="recorder_quality"     value="100"  />
     <parameter name="recorder_progressive" value="true" />
     <parameter name="cache_is_limited_memory" value="false" />
-    <parameter name="cache_limited_memory"    value="1" />
+    <parameter name="cache_limited_memory"    value="1000" />
   </section>
   <section name="resources">
     <!-- Module resources -->
index 0e7e434f7fdc88a868cfc42e671c3e021f4a64a1..2ee018b5718b17b213cd25cb47bf5891b8246e15 100644 (file)
@@ -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 );
 
index 4dbc5fd78b26e2b48bc4c803820e54e89427212b..c073f752f2b9fb31bd1700dcab09ed7091dfe9ec 100644 (file)
@@ -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();
index 72b063145497b32b6dd095a325e275718e815459..25f61d9fbce1f7ec1c8bc14433a4402a31fd9628 100644 (file)
 #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 <vtkActorCollection.h>
 #include <vtkRenderer.h>
 
 /*!
   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::ColoredPrs3dHolder_i*>(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::ColoredPrs3d_i*>( 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 );
index 6075ecc5af0a654c277a8ea4a41eca51aed01414..f4473268c1b2c7c687e6b5dbc3bf8d10e743ddf2 100644 (file)
 #include "QtxDockWindow.h"
 #include <vector>
 
+#include "SALOMEconfig.h"
+#include CORBA_SERVER_HEADER(VISU_Gen)
+
 namespace VISU
 {
-  class ColoredPrs3d_i;
+  class ColoredPrs3dHolder_i;
 }
 
-typedef std::vector<VISU::ColoredPrs3d_i*> PrsList;
+typedef std::vector<VISU::ColoredPrs3dHolder_var> 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
index a6ef3c791740488a6e583759046bf4f57ba7b39f..93af69967eb35a270400d2e0d92256a68d3495ee 100644 (file)
@@ -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<TSCALARMAP>(theInput);
+    anIsPossible =  CheckIsPossible<TSCALARMAP>(theInput);
   case TGAUSSPOINTS:
-    return CheckIsPossible<TGAUSSPOINTS>(theInput);
+    anIsPossible =  CheckIsPossible<TGAUSSPOINTS>(theInput);
   case TDEFORMEDSHAPE:
-    return CheckIsPossible<TDEFORMEDSHAPE>(theInput);
+    anIsPossible =  CheckIsPossible<TDEFORMEDSHAPE>(theInput);
   case TSCALARMAPONDEFORMEDSHAPE:
-    return CheckIsPossible<TSCALARMAPONDEFORMEDSHAPE>(theInput);
+    anIsPossible =  CheckIsPossible<TSCALARMAPONDEFORMEDSHAPE>(theInput);
   case TISOSURFACE:
-    return CheckIsPossible<TISOSURFACE>(theInput);
+    anIsPossible =  CheckIsPossible<TISOSURFACE>(theInput);
   case TSTREAMLINES:
-    return CheckIsPossible<TSTREAMLINES>(theInput);
+    anIsPossible =  CheckIsPossible<TSTREAMLINES>(theInput);
   case TPLOT3D:
-    return CheckIsPossible<TPLOT3D>(theInput);
+    anIsPossible =  CheckIsPossible<TPLOT3D>(theInput);
   case TCUTPLANES:
-    return CheckIsPossible<TCUTPLANES>(theInput);
+    anIsPossible =  CheckIsPossible<TCUTPLANES>(theInput);
   case TCUTLINES:
-    return CheckIsPossible<TCUTLINES>(theInput);
+    anIsPossible =  CheckIsPossible<TCUTLINES>(theInput);
   case TVECTORS:
-    return CheckIsPossible<TVECTORS>(theInput);
+    anIsPossible =  CheckIsPossible<TVECTORS>(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::Result_i*>( 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<VISU::ColoredPrs3d_i*>(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))
   {
index 4eb1f3cbe044405cece63a19d1e71e14de93e0f2..ad847d82434e6c6b5cc9b92bdd3353b5e0b47cea 100644 (file)
@@ -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,
index 9fa199d3d600511017fa3df8d719a7a2e366d265..f6e71de9b7a900b57c06b70573ec5471a51c76a5 100644 (file)
@@ -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::Result_i*>( 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()
index 19ad5515f5ddc3bad1304025b4b08366e19f8165..ab830a34ef2e5e02ea54483ac48e2a1c6fd7f7d7 100644 (file)
@@ -217,7 +217,7 @@ namespace VISU
 
     virtual
     CORBA::Long
-    GetMemorySize() { return 0; }
+    GetMemorySize();
 
     //! Returns presentation input
     VISU::ColoredPrs3dHolder::BasicInput*