]> SALOME platform Git repositories - modules/visu.git/blob - src/PIPELINE/VISU_PipeLine.cxx
Salome HOME
MPV: Merge V1_2d
[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 #include "VISU_PipeLineUtils.hxx"
31
32 #include <limits.h>
33
34 #include <vtkObjectFactory.h>
35 #include <vtkDataSetMapper.h>
36 #include <vtkUnstructuredGrid.h>
37
38 static int MYVTKDEBUG = 0;
39
40 #ifdef _DEBUG_
41 static int MYDEBUG = 0;
42 static int MYDEBUGWITHFILES = 0;
43 #else
44 static int MYDEBUG = 0;
45 static int MYDEBUGWITHFILES = 0;
46 #endif
47
48 VISU_PipeLine::VISU_PipeLine(){
49   myMapper = TMapper::New();
50   myInput = NULL;
51   SetDebug(MYVTKDEBUG);
52 }
53
54 VISU_PipeLine::~VISU_PipeLine(){
55   if(MYDEBUG) MESSAGE("~VISU_PipeLine - myInput = "<<myInput->GetReferenceCount());
56   SetInput(NULL);
57   myMapper->RemoveAllInputs();
58   myMapper->Delete();
59 }
60
61 void VISU_PipeLine::ShallowCopy(VISU_PipeLine *thePipeLine){
62   SetInput(thePipeLine->GetInput());
63   myMapper->ShallowCopy(thePipeLine->GetMapper());
64   Build();
65 }
66
67 void VISU_PipeLine::SetInput(TInput* theInput){
68   if(myInput != theInput){
69     if (myInput != NULL) myInput->UnRegister(this);
70     myInput = theInput;
71     if(myInput != NULL){
72       myInput->Register(this);
73       myInput->Update();
74     }else
75       myMapper->SetInput(NULL);
76     Modified();
77   }
78 }
79
80 VISU_PipeLine::TMapper* VISU_PipeLine::GetMapper() { 
81   if(myInput){
82     if(!myMapper->GetInput()){
83       myInput->Update();
84       Build();
85     }
86     myMapper->Update();
87   }
88   return myMapper;
89 }
90
91 void VISU_PipeLine::Update(){ 
92   myMapper->Update();
93 }
94
95
96 int VISU_PipeLine::CheckAvailableMemory(const float& theSize){
97   try{
98     if(theSize > ULONG_MAX) return 0;
99     size_t aSize = size_t(theSize);
100     char *aCheck = new char[aSize];
101     if(aCheck) delete [] aCheck;
102     if(MYDEBUG && aCheck == NULL)
103       MESSAGE("CheckAvailableMemory("<<theSize<<") - cannot alloacate such amount of memory!!!");
104     return aCheck != NULL;
105     //return theSize < 1000*1024*1024;
106   }catch(...){
107     if(MYDEBUG)
108       MESSAGE("CheckAvailableMemory("<<theSize<<") - unexpected exception was caught!!!");
109   }
110   return 0;
111 }
112
113
114 float VISU_PipeLine::GetAvailableMemory(float theSize, float theMinSize){
115   while(!CheckAvailableMemory(theSize))
116     if(theSize > theMinSize)
117       theSize /= 2;
118     else
119       return 0;
120   return theSize;
121 }