Salome HOME
Update copyright information
[modules/visu.git] / src / OBJECT / VISU_ActorBase.cxx
1 // Copyright (C) 2007-2012  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 #include "VTKViewer_Transform.h"
30
31 #include <vtkObjectFactory.h>
32 #include <vtkProperty.h>
33 #include <vtkPassThroughFilter.h>
34 #include <vtkShrinkFilter.h>
35 #include <vtkDataSet.h>
36 #include <vtkShrinkPolyData.h>
37 #include <vtkUnstructuredGrid.h>
38
39 #include "utilities.h"
40
41 #include <boost/bind.hpp>
42
43 VISU_ActorBase
44 ::VISU_ActorBase() :
45   myActorFactory(NULL),
46   myShrinkFilter(VTKViewer_ShrinkFilter::New()),
47   myIsShrinkable(true),
48   myIsShrunk(false)
49 {
50   myShrinkFilter->Delete();
51   
52   myStoreMapping = true;
53   
54   myShrinkFilter->SetStoreMapping(true);
55 }
56
57 VISU_ActorBase
58 ::~VISU_ActorBase()
59 {
60   myUpdateActorsConnection.disconnect();
61   myRemoveFromRendererConnection.disconnect();
62 }
63
64 //----------------------------------------------------------------------------
65 VISU::TActorFactory* 
66 VISU_ActorBase
67 ::GetFactory()
68
69   return myActorFactory;
70 }
71
72 void
73 VISU_ActorBase
74 ::SetFactory(VISU::TActorFactory* theActorFactory)
75
76   using namespace VISU;
77
78   if(myActorFactory == theActorFactory)
79     return;
80   
81   if(theActorFactory)
82      myDestroySignal.connect(boost::bind(&TActorFactory::RemoveActor,
83                                          theActorFactory,
84                                          _1));
85
86   myActorFactory = theActorFactory;
87 }
88
89 void
90 VISU_ActorBase
91 ::UpdateFromFactory()
92 {
93   if(myUpdateFromFactoryTime.GetMTime() < myActorFactory->GetMTime()){
94     myUpdateFromFactoryTime.Modified();
95     myActorFactory->UpdateActor(this);
96     Update();
97   }
98 }
99
100 //----------------------------------------------------------------------------
101 void
102 VISU_ActorBase
103 ::SetTransform(VTKViewer_Transform* theTransform)
104 {
105   Superclass::SetTransform( theTransform );
106
107   // Since the output of GetHighlightedDataSet() method (which is passed
108   // through transform filter) is used for calculation of bounds of the
109   // SALOME_Actor::myOutlineActor, we should remove transformation
110   // from the outline actor applied in SALOME_Actor::SetTransform().
111   // See issues IPAL22429, IPAL21936.
112   VTKViewer_Transform* aTransform = VTKViewer_Transform::New();
113   myOutlineActor->SetTransform( aTransform );
114   aTransform->Delete();
115 }
116
117 //--------------------------------------------------------------------------
118
119 void
120 VISU_ActorBase
121 ::SetLineWidth(vtkFloatingPointType theLineWidth)
122 {
123   GetProperty()->SetLineWidth(theLineWidth);
124 }
125
126 vtkFloatingPointType
127 VISU_ActorBase
128 ::GetLineWidth()
129 {
130   return GetProperty()->GetLineWidth();
131 }
132
133 //--------------------------------------------------------------------------
134 void
135 VISU_ActorBase
136 ::SetRepresentation(int theMode) 
137
138   Superclass::SetRepresentation(theMode);
139   if(myRepresentation == VTK_POINTS)
140     UnShrink();
141 }
142
143 //----------------------------------------------------------------------------
144 void VISU_ActorBase::SetShrink()
145 {
146   if(!myIsShrinkable) 
147     return;
148   if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
149     myShrinkFilter->SetInput(aDataSet);
150     myPassFilter[1]->SetInput(myShrinkFilter->GetOutput());
151     myIsShrunk = true;
152   }
153 }
154
155 void VISU_ActorBase::UnShrink()
156 {
157   if(!myIsShrunk) 
158     return;
159   if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
160     myPassFilter[1]->SetInput(aDataSet);
161     myPassFilter[1]->Modified();
162     myIsShrunk = false;
163     Modified();
164   }
165 }
166
167 bool VISU_ActorBase::IsShrunk()
168 {
169   return myIsShrunk;
170 }
171
172 void VISU_ActorBase::SetShrinkable(bool theIsShrinkable)
173 {
174   myIsShrinkable = theIsShrinkable;
175 }
176
177 bool VISU_ActorBase::IsShrunkable() 
178
179   return myIsShrinkable;
180 }
181
182 void
183 VISU_ActorBase
184 ::SetShrinkFactor(vtkFloatingPointType theValue)
185 {
186   myShrinkFilter->SetShrinkFactor(theValue);
187   Modified();
188 }
189
190 vtkFloatingPointType
191 VISU_ActorBase
192 ::GetShrinkFactor()
193 {
194   return myShrinkFilter->GetShrinkFactor();
195 }
196
197
198 //--------------------------------------------------------------------------------------
199
200 void VISU_ActorBase::RemoveFromRender(vtkRenderer* theRenderer)
201 {
202   Superclass::RemoveFromRender(theRenderer);
203 }
204
205 void VISU_ActorBase::RemoveFromRender()
206 {
207   RemoveFromRender(GetRenderer());
208 }
209
210 void VISU_ActorBase::ConnectToFactory(boost::signal0<void>& theUpdateActorSignal, boost::signal0<void>& theRemoveFromRendererSignal)
211 {
212   myUpdateActorsConnection = theUpdateActorSignal.connect(boost::bind(&VISU_ActorBase::UpdateFromFactory,this));
213   myRemoveFromRendererConnection = theRemoveFromRendererSignal.connect(boost::bind(&VISU_ActorBase::RemoveFromRender,this));
214 }
215
216 //--------------------------------------------------------------------------------------
217 vtkDataSet* VISU_ActorBase::GetHighlightedDataSet() {
218   return myPassFilter.back()->GetOutput();
219 }