Salome HOME
DCQ : Merge with Ecole Ete a6.
[modules/visu.git] / src / PIPELINE / VISU_PipeLine.cxx
index d4354e35bed350edc3bc6a5d6071abc8c3b456b7..a99eba600854ef89c7862149f1f4326069aadd86 100644 (file)
 
 
 #include "VISU_PipeLine.hxx"
+#include "VISU_PipeLineUtils.hxx"
+
+#include <limits.h>
 
 #include <vtkObjectFactory.h>
 #include <vtkDataSetMapper.h>
 #include <vtkUnstructuredGrid.h>
 
+static int MYVTKDEBUG = 0;
+
 #ifdef _DEBUG_
 static int MYDEBUG = 0;
 static int MYDEBUGWITHFILES = 0;
@@ -43,11 +48,14 @@ static int MYDEBUGWITHFILES = 0;
 VISU_PipeLine::VISU_PipeLine(){
   myMapper = TMapper::New();
   myInput = NULL;
+  SetDebug(MYVTKDEBUG);
 }
 
 VISU_PipeLine::~VISU_PipeLine(){
-  myMapper->Delete();
+  if(MYDEBUG) MESSAGE("~VISU_PipeLine - myInput = "<<myInput->GetReferenceCount());
   SetInput(NULL);
+  myMapper->RemoveAllInputs();
+  myMapper->Delete();
 }
 
 void VISU_PipeLine::ShallowCopy(VISU_PipeLine *thePipeLine){
@@ -57,13 +65,14 @@ void VISU_PipeLine::ShallowCopy(VISU_PipeLine *thePipeLine){
 }
 
 void VISU_PipeLine::SetInput(TInput* theInput){
-  if (myInput != theInput){
+  if(myInput != theInput){
     if (myInput != NULL) myInput->UnRegister(this);
     myInput = theInput;
-    if (myInput != NULL) {
+    if(myInput != NULL){
       myInput->Register(this);
       myInput->Update();
-    }
+    }else
+      myMapper->SetInput(NULL);
     Modified();
   }
 }
@@ -83,24 +92,28 @@ void VISU_PipeLine::Update(){
   myMapper->Update();
 }
 
-
-size_t VISU_PipeLine::CheckAvailableMemory(const size_t& theSize){
+int VISU_PipeLine::CheckAvailableMemory(const float& theSize){
   try{
-    char *aCheck = new char[theSize];
+    if(theSize > ULONG_MAX) return 0;
+    size_t aSize = size_t(theSize);
+    char *aCheck = new char[aSize];
     if(aCheck) delete [] aCheck;
     if(MYDEBUG && aCheck == NULL)
-      cout<<"VISU_PipeLine::CheckAvailableMemory("<<theSize<<") - cannot alloacate such amount of memory!!!\n";
+      MESSAGE("CheckAvailableMemory("<<theSize<<") - cannot alloacate such amount of memory!!!");
     return aCheck != NULL;
     //return theSize < 1000*1024*1024;
-  }catch(...){
-    if(MYDEBUG)
-      cout<<"VISU_PipeLine::CheckAvailableMemory("<<theSize<<") - unexpected exception was caught!!!\n";
+  }catch(std::bad_alloc& exc){
+    if(MYDEBUG) 
+      MESSAGE("CheckAvailableMemory("<<theSize<<") " << exc.what());
+  } catch(...) {
+    if(MYDEBUG) 
+      MESSAGE("CheckAvailableMemory("<<theSize<<") - unexpected exception was caught!!!");
   }
   return 0;
 }
 
 
-size_t VISU_PipeLine::GetAvailableMemory(size_t theSize, size_t theMinSize){
+float VISU_PipeLine::GetAvailableMemory(float theSize, float theMinSize){
   while(!CheckAvailableMemory(theSize))
     if(theSize > theMinSize)
       theSize /= 2;