Salome HOME
d4354e35bed350edc3bc6a5d6071abc8c3b456b7
[modules/visu.git] / src / PIPELINE / VISU_PipeLine.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 // File:    VISU_PipeLine.cxx
25 // Author:  Alexey PETROV
26 // Module : VISU
27
28
29 #include "VISU_PipeLine.hxx"
30
31 #include <vtkObjectFactory.h>
32 #include <vtkDataSetMapper.h>
33 #include <vtkUnstructuredGrid.h>
34
35 #ifdef _DEBUG_
36 static int MYDEBUG = 0;
37 static int MYDEBUGWITHFILES = 0;
38 #else
39 static int MYDEBUG = 0;
40 static int MYDEBUGWITHFILES = 0;
41 #endif
42
43 VISU_PipeLine::VISU_PipeLine(){
44   myMapper = TMapper::New();
45   myInput = NULL;
46 }
47
48 VISU_PipeLine::~VISU_PipeLine(){
49   myMapper->Delete();
50   SetInput(NULL);
51 }
52
53 void VISU_PipeLine::ShallowCopy(VISU_PipeLine *thePipeLine){
54   SetInput(thePipeLine->GetInput());
55   myMapper->ShallowCopy(thePipeLine->GetMapper());
56   Build();
57 }
58
59 void VISU_PipeLine::SetInput(TInput* theInput){
60   if (myInput != theInput){
61     if (myInput != NULL) myInput->UnRegister(this);
62     myInput = theInput;
63     if (myInput != NULL) {
64       myInput->Register(this);
65       myInput->Update();
66     }
67     Modified();
68   }
69 }
70
71 VISU_PipeLine::TMapper* VISU_PipeLine::GetMapper() { 
72   if(myInput){
73     if(!myMapper->GetInput()){
74       myInput->Update();
75       Build();
76     }
77     myMapper->Update();
78   }
79   return myMapper;
80 }
81
82 void VISU_PipeLine::Update(){ 
83   myMapper->Update();
84 }
85
86
87 size_t VISU_PipeLine::CheckAvailableMemory(const size_t& theSize){
88   try{
89     char *aCheck = new char[theSize];
90     if(aCheck) delete [] aCheck;
91     if(MYDEBUG && aCheck == NULL)
92       cout<<"VISU_PipeLine::CheckAvailableMemory("<<theSize<<") - cannot alloacate such amount of memory!!!\n";
93     return aCheck != NULL;
94     //return theSize < 1000*1024*1024;
95   }catch(...){
96     if(MYDEBUG)
97       cout<<"VISU_PipeLine::CheckAvailableMemory("<<theSize<<") - unexpected exception was caught!!!\n";
98   }
99   return 0;
100 }
101
102
103 size_t VISU_PipeLine::GetAvailableMemory(size_t theSize, size_t theMinSize){
104   while(!CheckAvailableMemory(theSize))
105     if(theSize > theMinSize)
106       theSize /= 2;
107     else
108       return 0;
109   return theSize;
110 }