]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Added possibility to enlarge cache
authorouv <ouv@opencascade.com>
Wed, 27 Dec 2006 13:19:58 +0000 (13:19 +0000)
committerouv <ouv@opencascade.com>
Wed, 27 Dec 2006 13:19:58 +0000 (13:19 +0000)
idl/VISU_Gen.idl
src/VISUGUI/VISU_msg_en.po
src/VISUGUI/VisuGUI_Prs3dTools.h
src/VISU_I/VISU_ColoredPrs3dCache_i.cc
src/VISU_I/VISU_ColoredPrs3dCache_i.hh
src/VISU_I/VISU_ColoredPrs3dFactory.cc
src/VISU_I/VISU_ColoredPrs3dFactory.hh
src/VISU_I/VISU_ColoredPrs3dHolder_i.cc
src/VISU_I/VISU_ColoredPrs3dHolder_i.hh

index 90bf25923f85b36789617d7cf3ad107c84ab8ca9..334eb42c6f2f58c7a17e88184223de50db0086de 100644 (file)
@@ -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);
   };
 
 
index 8e7dc6965432e8e581999b6ac1ab24190f93d67a..d64470647dcaf80f636ce3d54d5af559321e1e9c 100644 (file)
@@ -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
 
index abcdac8425e343d900a98ea7c5f6cec9d4a46cd8..0761326e0371c4973e59dd19d78601821fcd750f 100644 (file)
@@ -32,6 +32,7 @@
 #include "VisuGUI_Tools.h"
 #include "VisuGUI_ViewTools.h"
 #include "VISU_ColoredPrs3dFactory.hh"
+#include "VISU_PipeLine.hxx"
 
 #include <vtkRenderer.h>
 
@@ -128,11 +129,51 @@ namespace VISU
                                             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)
index 3947b4b65440480aa818f3397a15598bf5e50e5a..07fbb5bff2dd71128e02fc069424dafb32740ee3 100644 (file)
@@ -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;
 }
 
 
index 2ba3cda71652cf8be3552074b3b908a7a13b3dc2..56ab4a22005ef6fe193a3c27c0d56dc2f2bc0ce1 100644 (file)
@@ -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 
index e1129b818ceea5049f377a0128112a03a6279095..5634f0141000030357d9e0d8d8efabb873ef409f 100644 (file)
@@ -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<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,
@@ -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<Result_i*>(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) )
index 9bc14a389f8b3d6a85cdc9ba3f55c38209006edc..0deb370a2286042ddf1c7622b9ffb34ce9eb7e80 100644 (file)
@@ -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<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*
@@ -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<TColoredPrs3d_i>::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<TColoredPrs3d_i*>(aColoredPrs3d);
   }
 
index afb4a99ad5be61dd8879009c53d0e4500cfb20b5..32b2bc394d8670bf4c1b1150ad54799c88db913a 100644 (file)
@@ -155,6 +155,16 @@ VISU::ColoredPrs3dHolder_i
 }
 
 
+//----------------------------------------------------------------------------
+CORBA::Float
+VISU::ColoredPrs3dHolder_i
+::GetMemorySize()
+{
+  // tmp
+  return GetDevice()->GetMemorySize();
+}
+
+
 //----------------------------------------------------------------------------
 VISU::VISUType
 VISU::ColoredPrs3dHolder_i
index f2bb397eb41738d2d130d92018b1d6fc2cb6669b..2b6a9c9dea4f7b5ca6f693f285b800d939e67cb9 100644 (file)
@@ -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