Salome HOME
44dbbc6f74f30a34bd9c11714d81a18ff1b373b2
[modules/visu.git] / src / OBJECT / VISU_ActorBase.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  VISU OBJECT : interactive object for VISU entities implementation
23 //  File   : 
24 //  Author : 
25 //  Module : VISU
26 //  $Header$
27 //
28 #include "VISU_ActorBase.h"
29 #include "VISU_ActorFactory.h"
30 #include "VTKViewer_ShrinkFilter.h"
31
32 #include <vtkObjectFactory.h>
33 #include <vtkProperty.h>
34 #include <vtkPassThroughFilter.h>
35 #include <vtkShrinkFilter.h>
36 #include <vtkDataSet.h>
37 #include <vtkShrinkPolyData.h>
38 #include <vtkUnstructuredGrid.h>
39
40 #include "utilities.h"
41
42 #include <boost/bind.hpp>
43
44 VISU_ActorBase
45 ::VISU_ActorBase() :
46   myActorFactory(NULL),
47   myShrinkFilter(VTKViewer_ShrinkFilter::New()),
48   myIsShrinkable(true),
49   myIsShrunk(false)
50 {
51   myShrinkFilter->Delete();
52   
53   myStoreMapping = true;
54   
55   myShrinkFilter->SetStoreMapping(true);
56 }
57
58 VISU_ActorBase
59 ::~VISU_ActorBase()
60 {
61   myUpdateActorsConnection.disconnect();
62   myRemoveFromRendererConnection.disconnect();
63 }
64
65 //----------------------------------------------------------------------------
66 VISU::TActorFactory* 
67 VISU_ActorBase
68 ::GetFactory()
69
70   return myActorFactory;
71 }
72
73 void
74 VISU_ActorBase
75 ::SetFactory(VISU::TActorFactory* theActorFactory)
76
77   using namespace VISU;
78
79   if(myActorFactory == theActorFactory)
80     return;
81   
82   if(theActorFactory)
83      myDestroySignal.connect(boost::bind(&TActorFactory::RemoveActor,
84                                          theActorFactory,
85                                          _1));
86
87   myActorFactory = theActorFactory;
88 }
89
90 void
91 VISU_ActorBase
92 ::UpdateFromFactory()
93 {
94   if(myUpdateFromFactoryTime.GetMTime() < myActorFactory->GetMTime()){
95     myUpdateFromFactoryTime.Modified();
96     myActorFactory->UpdateActor(this);
97     Update();
98   }
99 }
100
101 //--------------------------------------------------------------------------
102
103 void
104 VISU_ActorBase
105 ::SetLineWidth(vtkFloatingPointType theLineWidth)
106 {
107   GetProperty()->SetLineWidth(theLineWidth);
108 }
109
110 vtkFloatingPointType
111 VISU_ActorBase
112 ::GetLineWidth()
113 {
114   return GetProperty()->GetLineWidth();
115 }
116
117 //--------------------------------------------------------------------------
118 void
119 VISU_ActorBase
120 ::SetRepresentation(int theMode) 
121
122   Superclass::SetRepresentation(theMode);
123   if(myRepresentation == VTK_POINTS)
124     UnShrink();
125 }
126
127 //----------------------------------------------------------------------------
128 void VISU_ActorBase::SetShrink()
129 {
130   if(!myIsShrinkable) 
131     return;
132   if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
133     myShrinkFilter->SetInput(aDataSet);
134     myPassFilter[1]->SetInput(myShrinkFilter->GetOutput());
135     myIsShrunk = true;
136   }
137 }
138
139 void VISU_ActorBase::UnShrink()
140 {
141   if(!myIsShrunk) 
142     return;
143   if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
144     myPassFilter[1]->SetInput(aDataSet);
145     myPassFilter[1]->Modified();
146     myIsShrunk = false;
147     Modified();
148   }
149 }
150
151 bool VISU_ActorBase::IsShrunk()
152 {
153   return myIsShrunk;
154 }
155
156 void VISU_ActorBase::SetShrinkable(bool theIsShrinkable)
157 {
158   myIsShrinkable = theIsShrinkable;
159 }
160
161 bool VISU_ActorBase::IsShrunkable() 
162
163   return myIsShrinkable;
164 }
165
166 //--------------------------------------------------------------------------------------
167
168 void VISU_ActorBase::RemoveFromRender(vtkRenderer* theRenderer)
169 {
170   Superclass::RemoveFromRender(theRenderer);
171 }
172
173 void VISU_ActorBase::RemoveFromRender()
174 {
175   RemoveFromRender(GetRenderer());
176 }
177
178 void VISU_ActorBase::ConnectToFactory(boost::signal0<void>& theUpdateActorSignal, boost::signal0<void>& theRemoveFromRendererSignal)
179 {
180   myUpdateActorsConnection = theUpdateActorSignal.connect(boost::bind(&VISU_ActorBase::UpdateFromFactory,this));
181   myRemoveFromRendererConnection = theRemoveFromRendererSignal.connect(boost::bind(&VISU_ActorBase::RemoveFromRender,this));
182 }