svn-gvsig-desktop / import / ext3D / branches / ext3D_v1.1 / extAnimationGUI / src / com / iver / ai2 / animationgui / gui / MenuAnimation3D.java @ 15462
History | View | Annotate | Download (10.6 KB)
1 |
package com.iver.ai2.animationgui.gui; |
---|---|
2 |
|
3 |
//import com.iver.ai2.gvsig3d.gui.AnimationContol3D;
|
4 |
import java.util.ArrayList; |
5 |
import java.util.List; |
6 |
|
7 |
import com.iver.ai2.animationgui.gui.toc.TocAnimationDate; |
8 |
import com.iver.ai2.gvsig3d.camera.ProjectCamera; |
9 |
import com.iver.ai2.gvsig3d.gui.View3D; |
10 |
import com.iver.andami.PluginServices; |
11 |
import com.iver.andami.plugins.Extension; |
12 |
import com.iver.andami.plugins.IExtension; |
13 |
import com.iver.andami.ui.mdiManager.IWindow; |
14 |
import com.iver.cit.gvsig.ProjectExtension; |
15 |
import com.iver.cit.gvsig.animation.AnimationContainer; |
16 |
import com.iver.cit.gvsig.animation.AnimationLayer2D; |
17 |
import com.iver.cit.gvsig.animation.AnimationLayer3DFlat; |
18 |
import com.iver.cit.gvsig.animation.AnimationPlayer; |
19 |
import com.iver.cit.gvsig.animation.Interpolator2D; |
20 |
import com.iver.cit.gvsig.animation.Interpolator3DFlat; |
21 |
import com.iver.cit.gvsig.animation.KeyFrame2D; |
22 |
import com.iver.cit.gvsig.animation.KeyFrame3DFlat; |
23 |
import com.iver.cit.gvsig.animation.interval.AnimationKeyFrameInterval; |
24 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.FuntionFactory; |
25 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolatorFuntion; |
26 |
import com.iver.cit.gvsig.animation.traks.AnimationTimeTrack; |
27 |
import com.iver.cit.gvsig.animation.traks.IAnimationTrack; |
28 |
import com.iver.cit.gvsig.fmap.MapControl; |
29 |
import com.iver.cit.gvsig.project.Project; |
30 |
import com.iver.cit.gvsig.project.ProjectExtent; |
31 |
import com.iver.cit.gvsig.project.ProjectFactory; |
32 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
33 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
34 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
35 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
36 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
37 |
|
38 |
import es.upv.ai2.libjosg.viewer.Camera; |
39 |
|
40 |
/**
|
41 |
* @author
|
42 |
* @since 1.1
|
43 |
*
|
44 |
* Menu of animation toolbar's options.
|
45 |
*/
|
46 |
|
47 |
public class MenuAnimation3D extends Extension { |
48 |
|
49 |
private Project project;
|
50 |
private int cont = 0; |
51 |
private AnimationContainer ac;
|
52 |
private AnimationTimeTrack animationTimeTrack = null; |
53 |
private AnimationKeyFrameInterval AKFinterval;
|
54 |
|
55 |
public void execute(String actionCommand) { |
56 |
|
57 |
// TODO Auto-generated method stub
|
58 |
// if the button pressed is animation control the animation panel is
|
59 |
// created.
|
60 |
if (actionCommand.equals("CONTROLES")) { |
61 |
System.out.println("pulsado boton controles !!!"); |
62 |
|
63 |
// ProjectExtent[] ex = project.getExtents();
|
64 |
// for (int i = 0; i < ex.length; i++) {
|
65 |
// ProjectExtent projectExtent = ex[i];
|
66 |
// System.out.println(projectExtent);
|
67 |
// }
|
68 |
|
69 |
AnimationContainer ac = project.getAnimationContainer(); |
70 |
AnimationPlayer ap = ac.getAnimationPlayer(); |
71 |
ap.setAnimationContainer(ac); |
72 |
AnimationContol3D fp = new AnimationContol3D(ap);
|
73 |
PluginServices.getMDIManager().addWindow((IWindow) fp); |
74 |
} else if (actionCommand.equals("ENCUADRECAP")) {// button capture |
75 |
// snapshot pressed.
|
76 |
System.out.println("pulsado boton de capturar encuadres!!!"); |
77 |
|
78 |
String name = "Animation-" + cont++; |
79 |
List keyFrameList = null; |
80 |
|
81 |
// Getting the active windows
|
82 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
83 |
|
84 |
// crear track sino existe
|
85 |
ac = this.getAnimationContainer();
|
86 |
|
87 |
// If the w is instance of View
|
88 |
if (w instanceof View) { |
89 |
|
90 |
animationTimeTrack = this.getAnimationTimeTrack(
|
91 |
"encuadrator_track_2D", ac);
|
92 |
// generar el intervalo
|
93 |
if (AKFinterval == null) { |
94 |
AKFinterval = (AnimationKeyFrameInterval) animationTimeTrack |
95 |
.createKeyFrameInterval(); |
96 |
AKFinterval.setInitialTime(0.0);
|
97 |
AKFinterval.setEndTime(1.0);
|
98 |
} |
99 |
|
100 |
BaseView view = (BaseView) w; |
101 |
MapControl mapa = view.getMapControl(); |
102 |
ProjectExtent extent = ProjectFactory.createExtent(); |
103 |
extent.setDescription(name); |
104 |
extent.setExtent(mapa.getViewPort().getExtent()); |
105 |
project.addExtent(extent); |
106 |
|
107 |
// generar lista de keyframes
|
108 |
|
109 |
ProjectExtent[] extentsList = project.getExtents();
|
110 |
keyFrameList = new ArrayList(); |
111 |
for (int i = 0; i < extentsList.length; i++) { |
112 |
ProjectExtent projectExtent = extentsList[i]; |
113 |
KeyFrame2D kf2D = new KeyFrame2D();
|
114 |
double fin = AKFinterval.getEndTime();
|
115 |
double ini = AKFinterval.getInitialTime();
|
116 |
double size = extentsList.length;
|
117 |
// Calcular el tiempo de insercion
|
118 |
double tiempo = 0.0; |
119 |
if (i != 0) |
120 |
tiempo = i * ((fin - ini) / (size - 1.0));
|
121 |
kf2D.setTime(tiempo); |
122 |
// hacer funcion de insercion o adapter
|
123 |
// kf2D.CapturesProperties(projectExtent);
|
124 |
kf2D.setAnimatedObject(projectExtent); |
125 |
keyFrameList.add(kf2D); |
126 |
|
127 |
} |
128 |
} |
129 |
|
130 |
if (w instanceof View3D) { |
131 |
|
132 |
animationTimeTrack = this.getAnimationTimeTrack(
|
133 |
"encuadrator_track_3D", ac);
|
134 |
// generar el intervalo
|
135 |
if (AKFinterval == null) { |
136 |
AKFinterval = (AnimationKeyFrameInterval) animationTimeTrack |
137 |
.createKeyFrameInterval(); |
138 |
AKFinterval.setInitialTime(0.0);
|
139 |
AKFinterval.setEndTime(1.0);
|
140 |
} |
141 |
|
142 |
View3D view = (View3D) w; |
143 |
Camera ca = view.getCamera(); |
144 |
|
145 |
ProjectCamera camera = new ProjectCamera();
|
146 |
camera.setDescription(name); |
147 |
camera.setCamera(ca); |
148 |
|
149 |
project.addCamera(camera); |
150 |
// generar lista de keyframes
|
151 |
Object[] extentsList = project.getCameras(); |
152 |
keyFrameList = new ArrayList(); |
153 |
for (int i = 0; i < extentsList.length; i++) { |
154 |
ProjectCamera projectCamera = (ProjectCamera) extentsList[i]; |
155 |
KeyFrame3DFlat kf2D = new KeyFrame3DFlat();
|
156 |
double fin = AKFinterval.getEndTime();
|
157 |
double ini = AKFinterval.getInitialTime();
|
158 |
double size = extentsList.length;
|
159 |
// Calcular el tiempo de insercion
|
160 |
double tiempo = 0.0; |
161 |
if (i != 0) |
162 |
tiempo = i * ((fin - ini) / (size - 1.0));
|
163 |
// (AKFinterval.getEndTime() - AKFinterval
|
164 |
// .getInitialTime()) / extentsList.length);
|
165 |
kf2D.setTime(tiempo); |
166 |
// hacer funcion de insercion o adapter
|
167 |
// kf2D.CapturesProperties(projectExtent);
|
168 |
kf2D.setAnimatedObject(projectCamera); |
169 |
keyFrameList.add(kf2D); |
170 |
|
171 |
} |
172 |
} |
173 |
AKFinterval.setKeyFrameList(keyFrameList); |
174 |
System.out.println(ac);
|
175 |
} else if (actionCommand.equals("CAPACAP")) {// button capture layer |
176 |
// pressed.
|
177 |
System.out.println("pulsado boton de capturar capa!!!"); |
178 |
} else if (actionCommand.equals("BORRAR")){ |
179 |
ac = this.getAnimationContainer();
|
180 |
ac.removeAllTrack(); |
181 |
} |
182 |
|
183 |
|
184 |
} |
185 |
|
186 |
private AnimationTimeTrack getAnimationTimeTrack(String name, |
187 |
AnimationContainer ac) { |
188 |
|
189 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices |
190 |
.getMDIManager().getActiveWindow(); |
191 |
|
192 |
AnimationTimeTrack at = this.animationTimeTrack;
|
193 |
IAnimationTrack aa = ac.findTrack(name); |
194 |
if (aa == null) { |
195 |
|
196 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton |
197 |
.getInstance(); |
198 |
ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints |
199 |
.get("Animation"));
|
200 |
|
201 |
if (f instanceof View) { |
202 |
IAnimationTrack trackAux = ac.findTrack("encuadrator_track_3D");
|
203 |
if (trackAux != null) { |
204 |
trackAux.setEnabale(false);
|
205 |
} |
206 |
AnimationLayer2D animationLayer2D = null;
|
207 |
try {
|
208 |
animationLayer2D = (AnimationLayer2D) extPoint |
209 |
.create("AnimationLayer2D");
|
210 |
} catch (InstantiationException e) { |
211 |
// TODO Auto-generated catch block
|
212 |
e.printStackTrace(); |
213 |
} catch (IllegalAccessException e) { |
214 |
// TODO Auto-generated catch block
|
215 |
e.printStackTrace(); |
216 |
} |
217 |
at = (AnimationTimeTrack) ac.CreateTimeTrack(animationLayer2D); |
218 |
at.setName(name); |
219 |
at.setEnabale(true);
|
220 |
View view = (View) f; |
221 |
at.setAnimatedObject(view); |
222 |
// Create the interpolator
|
223 |
Interpolator2D inter2D = new Interpolator2D();
|
224 |
inter2D.setAnimatedObject(view); |
225 |
IInterpolatorFuntion funtion = FuntionFactory.createObject("com.iver.cit.gvsig.animation.keyframe.interpolator.LinearFuntion");
|
226 |
inter2D.setFuntion(funtion); |
227 |
|
228 |
animationLayer2D.setInterpolator(inter2D); |
229 |
at.setAnimationType(animationLayer2D); |
230 |
animationLayer2D.setAnimatedObject(view); |
231 |
} |
232 |
if (f instanceof View3D) { |
233 |
IAnimationTrack trackAux = ac.findTrack("encuadrator_track_2D");
|
234 |
if (trackAux != null) { |
235 |
trackAux.setEnabale(false);
|
236 |
} |
237 |
AnimationLayer3DFlat animationLayer3DFlat = null;
|
238 |
try {
|
239 |
animationLayer3DFlat = (AnimationLayer3DFlat) extPoint |
240 |
.create("AnimationLayer3DFlat");
|
241 |
} catch (InstantiationException e) { |
242 |
// TODO Auto-generated catch block
|
243 |
e.printStackTrace(); |
244 |
} catch (IllegalAccessException e) { |
245 |
e.printStackTrace(); |
246 |
} |
247 |
at = (AnimationTimeTrack) ac |
248 |
.CreateTimeTrack(animationLayer3DFlat); |
249 |
at.setName(name); |
250 |
at.setEnabale(true);
|
251 |
BaseView view = (BaseView) f; |
252 |
at.setAnimatedObject(view); |
253 |
Interpolator3DFlat inter3DFlat = new Interpolator3DFlat();
|
254 |
inter3DFlat.setAnimatedObject(view); |
255 |
IInterpolatorFuntion funtion = FuntionFactory.createObject("com.iver.cit.gvsig.animation.keyframe.interpolator.LinearFuntion");
|
256 |
inter3DFlat.setFuntion(funtion); |
257 |
animationLayer3DFlat.setInterpolator(inter3DFlat); |
258 |
at.setAnimationType(animationLayer3DFlat); |
259 |
animationLayer3DFlat.setAnimatedObject(view); |
260 |
} |
261 |
} |
262 |
|
263 |
if (f instanceof View3D) { |
264 |
IAnimationTrack trackAux = ac.findTrack("encuadrator_track_2D");
|
265 |
if (trackAux != null) { |
266 |
trackAux.setEnabale(false);
|
267 |
} |
268 |
} |
269 |
|
270 |
if (f instanceof View) { |
271 |
IAnimationTrack trackAux = ac.findTrack("encuadrator_track_3D");
|
272 |
if (trackAux != null) { |
273 |
trackAux.setEnabale(false);
|
274 |
} |
275 |
} |
276 |
return at;
|
277 |
|
278 |
} |
279 |
|
280 |
private AnimationContainer getAnimationContainer() {
|
281 |
|
282 |
return project.getAnimationContainer();
|
283 |
} |
284 |
|
285 |
public void initialize() { |
286 |
|
287 |
// Getting the project using pluggin services
|
288 |
IExtension extension = PluginServices |
289 |
.getExtension(com.iver.cit.gvsig.ProjectExtension.class); |
290 |
ProjectExtension pe = (ProjectExtension) extension; |
291 |
project = pe.getProject(); |
292 |
|
293 |
// Register types
|
294 |
// AnimationTypeFactoryLayer2D.register();
|
295 |
// AnimationTypeFactoryLayer3DFlat.register();
|
296 |
|
297 |
// Registering TOC actions
|
298 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
299 |
extensionPoints.add("View_TocActions","Generar animacion temporal",new TocAnimationDate()); |
300 |
} |
301 |
|
302 |
public boolean isEnabled() { |
303 |
// TODO Auto-generated method stub
|
304 |
return true; |
305 |
} |
306 |
|
307 |
public boolean isVisible() { |
308 |
|
309 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices |
310 |
.getMDIManager().getActiveWindow(); |
311 |
|
312 |
if (f == null) { |
313 |
return false; |
314 |
} |
315 |
|
316 |
// Only isVisible = true, where the view3D have layers
|
317 |
if (f instanceof BaseView) { |
318 |
return true; |
319 |
} |
320 |
return false; |
321 |
} |
322 |
|
323 |
} |