Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / OBJECT / VISU_ActorBase.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  VISU OBJECT : interactive object for VISU entities implementation
21 //  File   : 
22 //  Author : 
23 //  Module : VISU
24 //  $Header$
25 //
26 #include "VISU_ActorBase.h"
27 #include "VISU_ActorFactory.h"
28 #include "VTKViewer_ShrinkFilter.h"
29
30 #include <vtkObjectFactory.h>
31 #include <vtkProperty.h>
32 #include <vtkPassThroughFilter.h>
33 #include <vtkShrinkFilter.h>
34 #include <vtkDataSet.h>
35 #include <vtkShrinkPolyData.h>
36 #include <vtkUnstructuredGrid.h>
37
38 #include "utilities.h"
39
40 #include <boost/bind.hpp>
41
42 VISU_ActorBase
43 ::VISU_ActorBase() :
44   myActorFactory(NULL),
45   myShrinkFilter(VTKViewer_ShrinkFilter::New()),
46   myIsShrinkable(true),
47   myIsShrunk(false)
48 {
49   myShrinkFilter->Delete();
50   
51   myStoreMapping = true;
52   
53   myShrinkFilter->SetStoreMapping(true);
54 }
55
56 VISU_ActorBase
57 ::~VISU_ActorBase()
58 {
59   myUpdateActorsConnection.disconnect();
60   myRemoveFromRendererConnection.disconnect();
61 }
62
63 //----------------------------------------------------------------------------
64 VISU::TActorFactory* 
65 VISU_ActorBase
66 ::GetFactory()
67
68   return myActorFactory;
69 }
70
71 void
72 VISU_ActorBase
73 ::SetFactory(VISU::TActorFactory* theActorFactory)
74
75   using namespace VISU;
76
77   if(myActorFactory == theActorFactory)
78     return;
79   
80   if(theActorFactory)
81      myDestroySignal.connect(boost::bind(&TActorFactory::RemoveActor,
82                                          theActorFactory,
83                                          _1));
84
85   myActorFactory = theActorFactory;
86 }
87
88 void
89 VISU_ActorBase
90 ::UpdateFromFactory()
91 {
92   if(myUpdateFromFactoryTime.GetMTime() < myActorFactory->GetMTime()){
93     myUpdateFromFactoryTime.Modified();
94     myActorFactory->UpdateActor(this);
95     Update();
96   }
97 }
98
99 //--------------------------------------------------------------------------
100
101 void
102 VISU_ActorBase
103 ::SetLineWidth(vtkFloatingPointType theLineWidth)
104 {
105   GetProperty()->SetLineWidth(theLineWidth);
106 }
107
108 vtkFloatingPointType
109 VISU_ActorBase
110 ::GetLineWidth()
111 {
112   return GetProperty()->GetLineWidth();
113 }
114
115 //--------------------------------------------------------------------------
116 void
117 VISU_ActorBase
118 ::SetRepresentation(int theMode) 
119
120   Superclass::SetRepresentation(theMode);
121   if(myRepresentation == VTK_POINTS)
122     UnShrink();
123 }
124
125 //----------------------------------------------------------------------------
126 void VISU_ActorBase::SetShrink()
127 {
128   if(!myIsShrinkable) 
129     return;
130   if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
131     myShrinkFilter->SetInput(aDataSet);
132     myPassFilter[1]->SetInput(myShrinkFilter->GetOutput());
133     myIsShrunk = true;
134   }
135 }
136
137 void VISU_ActorBase::UnShrink()
138 {
139   if(!myIsShrunk) 
140     return;
141   if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
142     myPassFilter[1]->SetInput(aDataSet);
143     myPassFilter[1]->Modified();
144     myIsShrunk = false;
145     Modified();
146   }
147 }
148
149 bool VISU_ActorBase::IsShrunk()
150 {
151   return myIsShrunk;
152 }
153
154 void VISU_ActorBase::SetShrinkable(bool theIsShrinkable)
155 {
156   myIsShrinkable = theIsShrinkable;
157 }
158
159 bool VISU_ActorBase::IsShrunkable() 
160
161   return myIsShrinkable;
162 }
163
164 //--------------------------------------------------------------------------------------
165
166 void VISU_ActorBase::RemoveFromRender(vtkRenderer* theRenderer)
167 {
168   Superclass::RemoveFromRender(theRenderer);
169 }
170
171 void VISU_ActorBase::RemoveFromRender()
172 {
173   RemoveFromRender(GetRenderer());
174 }
175
176 void VISU_ActorBase::ConnectToFactory(boost::signal0<void>& theUpdateActorSignal, boost::signal0<void>& theRemoveFromRendererSignal)
177 {
178   myUpdateActorsConnection = theUpdateActorSignal.connect(boost::bind(&VISU_ActorBase::UpdateFromFactory,this));
179   myRemoveFromRendererConnection = theRemoveFromRendererSignal.connect(boost::bind(&VISU_ActorBase::RemoveFromRender,this));
180 }