root / trunk / extensions / extAnimationGUI / src / com / iver / ai2 / animationgui / gui / MenuAnimation3D.java @ 18665
History | View | Annotate | Download (13 KB)
1 |
package com.iver.ai2.animationgui.gui; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.List; |
5 |
|
6 |
import com.iver.ai2.animationgui.gui.toc.TocAnimationDate; |
7 |
import com.iver.ai2.gvsig3d.camera.ProjectCamera; |
8 |
import com.iver.ai2.gvsig3dgui.view.View3D; |
9 |
import com.iver.andami.PluginServices; |
10 |
import com.iver.andami.plugins.Extension; |
11 |
import com.iver.andami.plugins.IExtension; |
12 |
import com.iver.andami.ui.mdiManager.IWindow; |
13 |
import com.iver.cit.gvsig.ProjectExtension; |
14 |
import com.iver.cit.gvsig.animation.AnimationContainer; |
15 |
import com.iver.cit.gvsig.animation.AnimationPlayer; |
16 |
import com.iver.cit.gvsig.animation.IAnimationType; |
17 |
import com.iver.cit.gvsig.animation.animatedObject.AnimatedObjectBase; |
18 |
import com.iver.cit.gvsig.animation.interval.AnimationKeyFrameInterval; |
19 |
import com.iver.cit.gvsig.animation.keyframe.IKeyFrame; |
20 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.FuntionFactory; |
21 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolator; |
22 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolatorTimeFuntion; |
23 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.InterpolatorFactory; |
24 |
import com.iver.cit.gvsig.animation.traks.AnimationTimeTrack; |
25 |
import com.iver.cit.gvsig.animation.traks.IAnimationTrack; |
26 |
import com.iver.cit.gvsig.fmap.MapControl; |
27 |
import com.iver.cit.gvsig.project.Project; |
28 |
import com.iver.cit.gvsig.project.ProjectExtent; |
29 |
import com.iver.cit.gvsig.project.ProjectFactory; |
30 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
31 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
32 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
33 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
34 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
35 |
|
36 |
import es.upv.ai2.osgvp.viewer.Camera; |
37 |
|
38 |
/**
|
39 |
* @author
|
40 |
* @since 1.1
|
41 |
*
|
42 |
* Menu of animation toolbar's options.
|
43 |
*/
|
44 |
|
45 |
public class MenuAnimation3D extends Extension { |
46 |
|
47 |
private Project project;
|
48 |
private int cont = 0; |
49 |
private AnimationContainer ac;
|
50 |
private AnimationTimeTrack animationTimeTrack = null; |
51 |
private AnimationKeyFrameInterval AKFinterval;
|
52 |
private AnimatedObjectBase object3D = new AnimatedObjectBase(); |
53 |
private AnimatedObjectBase object2D = new AnimatedObjectBase(); |
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 = (AnimationContainer) project.getAnimationContainer(); |
70 |
AnimationPlayer ap = ac.getAnimationPlayer(); |
71 |
ap.setAnimationContainer(ac); |
72 |
AnimationContol3D fp = new AnimationContol3D(ap);
|
73 |
PluginServices.getMDIManager().addWindow((IWindow) fp); |
74 |
|
75 |
} else if (actionCommand.equals("ENCUADRECAP")) {// button capture |
76 |
// snapshot pressed.
|
77 |
System.out.println("pulsado boton de capturar encuadres!!!"); |
78 |
|
79 |
String name = "Animation-" + cont++; |
80 |
List keyFrameList = null; |
81 |
|
82 |
// Getting the active windows
|
83 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
84 |
|
85 |
// Getting the animation container.
|
86 |
ac = this.getAnimationContainer();
|
87 |
|
88 |
// If the window instance is View, it will manage extends 2D
|
89 |
if (w instanceof View) { |
90 |
|
91 |
// Getting the animation extension point.
|
92 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
93 |
ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints.get("Animation"));
|
94 |
|
95 |
// Creating new track
|
96 |
animationTimeTrack = this.getAnimationTimeTrack(
|
97 |
"encuadrator_track_2D", ac);
|
98 |
// Creating the interval
|
99 |
if (AKFinterval == null) { |
100 |
AKFinterval = (AnimationKeyFrameInterval) animationTimeTrack |
101 |
.createKeyFrameInterval(); |
102 |
// Setting up interval properties.
|
103 |
AKFinterval.setInitialTime(0.0);
|
104 |
AKFinterval.setEndTime(1.0);
|
105 |
} |
106 |
|
107 |
// Getting the current extend and adding to project extends.
|
108 |
BaseView view = (BaseView) w; |
109 |
MapControl mapa = view.getMapControl(); |
110 |
ProjectExtent extent = ProjectFactory.createExtent(); |
111 |
extent.setDescription(name); |
112 |
extent.setExtent(mapa.getViewPort().getExtent()); |
113 |
project.addExtent(extent); |
114 |
|
115 |
// Creating the keyframe list.
|
116 |
ProjectExtent[] extentsList = project.getExtents();
|
117 |
keyFrameList = new ArrayList(); |
118 |
for (int i = 0; i < extentsList.length; i++) { |
119 |
ProjectExtent projectExtent = extentsList[i]; |
120 |
|
121 |
IKeyFrame kf2D = null;
|
122 |
try {
|
123 |
kf2D = (IKeyFrame)extPoint.create("KeyFrame2D");
|
124 |
} catch (InstantiationException e) { |
125 |
//TODO stop this loop and show a advertise message.
|
126 |
e.printStackTrace(); |
127 |
} catch (IllegalAccessException e) { |
128 |
e.printStackTrace(); |
129 |
} |
130 |
|
131 |
// Setting up the initial and end time interval.
|
132 |
double fin = AKFinterval.getEndTime();
|
133 |
double ini = AKFinterval.getInitialTime();
|
134 |
double size = extentsList.length;
|
135 |
// Calculating the insertion time.
|
136 |
double tiempo = 0.0; |
137 |
if (i != 0) |
138 |
tiempo = i * ((fin - ini) / (size - 1.0));
|
139 |
kf2D.setTime(tiempo); |
140 |
// hacer funcion de insercion o adapter
|
141 |
kf2D.setAnimatedObject(projectExtent); |
142 |
kf2D.CapturesProperties(); |
143 |
keyFrameList.add(kf2D); |
144 |
|
145 |
} |
146 |
} |
147 |
|
148 |
if (w instanceof View3D) { |
149 |
|
150 |
// Getting the animation extension point.
|
151 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
152 |
ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints.get("Animation"));
|
153 |
|
154 |
// Creating new track
|
155 |
animationTimeTrack = this.getAnimationTimeTrack(
|
156 |
"encuadrator_track_3D", ac);
|
157 |
|
158 |
// Creating the interval
|
159 |
if (AKFinterval == null) { |
160 |
AKFinterval = (AnimationKeyFrameInterval) animationTimeTrack |
161 |
.createKeyFrameInterval(); |
162 |
AKFinterval.setInitialTime(0.0);
|
163 |
AKFinterval.setEndTime(1.0);
|
164 |
} |
165 |
|
166 |
// Getting the current camera position and insert it into project camera list.
|
167 |
View3D view = (View3D) w; |
168 |
Camera ca = view.getCamera(); |
169 |
ProjectCamera camera = new ProjectCamera();
|
170 |
camera.setDescription(name); |
171 |
camera.setCamera(ca); |
172 |
project.addCamera(camera); |
173 |
|
174 |
// Creating key frame list
|
175 |
Object[] extentsList = project.getCameras(); |
176 |
keyFrameList = new ArrayList(); |
177 |
for (int i = 0; i < extentsList.length; i++) { |
178 |
ProjectCamera projectCamera = (ProjectCamera) extentsList[i]; |
179 |
IKeyFrame kf3D = null;
|
180 |
try {
|
181 |
kf3D = (IKeyFrame)extPoint.create("KeyFrame3DFlat");
|
182 |
} catch (InstantiationException e) { |
183 |
e.printStackTrace(); |
184 |
} catch (IllegalAccessException e) { |
185 |
e.printStackTrace(); |
186 |
} |
187 |
|
188 |
// Setting up the initial and end time interval.
|
189 |
double fin = AKFinterval.getEndTime();
|
190 |
double ini = AKFinterval.getInitialTime();
|
191 |
double size = extentsList.length;
|
192 |
// Calculating the correct time for this key frame.
|
193 |
double tiempo = 0.0; |
194 |
if (i != 0) |
195 |
tiempo = i * ((fin - ini) / (size - 1.0));
|
196 |
// Setting the time.
|
197 |
kf3D.setTime(tiempo); |
198 |
// hacer funcion de insercion o adapter
|
199 |
kf3D.setAnimatedObject(projectCamera); |
200 |
kf3D.CapturesProperties(); |
201 |
keyFrameList.add(kf3D); |
202 |
|
203 |
} |
204 |
} |
205 |
AKFinterval.setKeyFrameList(keyFrameList); |
206 |
System.out.println(ac);
|
207 |
} else if (actionCommand.equals("CAPACAP")) {// button capture layer |
208 |
// pressed.
|
209 |
System.out.println("pulsado boton de capturar capa!!!"); |
210 |
} else if (actionCommand.equals("BORRAR")){ |
211 |
ac = this.getAnimationContainer();
|
212 |
ac.removeAllTrack(); |
213 |
} |
214 |
|
215 |
|
216 |
} |
217 |
|
218 |
|
219 |
private AnimationTimeTrack getAnimationTimeTrack(String name, |
220 |
AnimationContainer ac) { |
221 |
|
222 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices |
223 |
.getMDIManager().getActiveWindow(); |
224 |
|
225 |
AnimationTimeTrack at = this.animationTimeTrack;
|
226 |
IAnimationTrack aa = ac.findTrack(name); |
227 |
if (aa == null) { |
228 |
|
229 |
// Getting the extension point.
|
230 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton |
231 |
.getInstance(); |
232 |
ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints |
233 |
.get("Animation"));
|
234 |
|
235 |
// If f is a 2D windows, it will create with 2D specific animation type.
|
236 |
if (f instanceof View) { |
237 |
|
238 |
// Finding if there are an 3D animation track.
|
239 |
IAnimationTrack trackAux = ac.findTrack("encuadrator_track_3D");
|
240 |
if (trackAux != null) { |
241 |
// if there are one, it will disable.
|
242 |
trackAux.setEnabale(false);
|
243 |
} |
244 |
IAnimationType animationLayer2D = null;
|
245 |
try {
|
246 |
animationLayer2D = (IAnimationType) extPoint |
247 |
.create("AnimationLayer2D");
|
248 |
} catch (InstantiationException e) { |
249 |
// TODO Auto-generated catch block
|
250 |
e.printStackTrace(); |
251 |
} catch (IllegalAccessException e) { |
252 |
// TODO Auto-generated catch block
|
253 |
e.printStackTrace(); |
254 |
} |
255 |
// Setting up the track properties
|
256 |
at = (AnimationTimeTrack) ac.CreateTimeTrack(animationLayer2D); |
257 |
at.setName(name); |
258 |
at.setEnabale(true);
|
259 |
// Setting up the animated object
|
260 |
View view = (View) f; |
261 |
at.setAnimatedObject(object2D); |
262 |
|
263 |
// Getting the interpolator
|
264 |
IInterpolator inter2D = InterpolatorFactory.createObject("Interpolator2D");
|
265 |
object2D.addAnimatedObject("view", view);
|
266 |
// Getting the interpolator funcion
|
267 |
IInterpolatorTimeFuntion funtion = FuntionFactory.createObject("com.iver.cit.gvsig.animation.keyframe.interpolator.LinearFuntion");
|
268 |
inter2D.setFuntion(funtion); |
269 |
|
270 |
animationLayer2D.setInterpolator(inter2D); |
271 |
at.setAnimationType(animationLayer2D); |
272 |
animationLayer2D.setAnimatedObject(object2D); |
273 |
} |
274 |
if (f instanceof View3D) { |
275 |
// Finding if there are an 2D animation track.
|
276 |
IAnimationTrack trackAux = ac.findTrack("encuadrator_track_2D");
|
277 |
if (trackAux != null) { |
278 |
// if there are one, it will disable.
|
279 |
trackAux.setEnabale(false);
|
280 |
} |
281 |
IAnimationType animationLayer3DFlat = null;
|
282 |
try {
|
283 |
animationLayer3DFlat = (IAnimationType) extPoint |
284 |
.create("AnimationLayer3DFlat");
|
285 |
} catch (InstantiationException e) { |
286 |
// TODO Auto-generated catch block
|
287 |
e.printStackTrace(); |
288 |
} catch (IllegalAccessException e) { |
289 |
e.printStackTrace(); |
290 |
} |
291 |
at = (AnimationTimeTrack) ac |
292 |
.CreateTimeTrack(animationLayer3DFlat); |
293 |
|
294 |
at.setName(name); |
295 |
at.setEnabale(true);
|
296 |
|
297 |
BaseView view = (BaseView) f; |
298 |
object3D.addAnimatedObject("view", view);
|
299 |
at.setAnimatedObject(object3D); |
300 |
|
301 |
IInterpolator inter3DFlat = InterpolatorFactory.createObject("Interpolator3DFlat");
|
302 |
IInterpolatorTimeFuntion funtion = FuntionFactory.createObject("com.iver.cit.gvsig.animation.keyframe.interpolator.LinearFuntion");
|
303 |
inter3DFlat.setFuntion(funtion); |
304 |
animationLayer3DFlat.setInterpolator(inter3DFlat); |
305 |
at.setAnimationType(animationLayer3DFlat); |
306 |
animationLayer3DFlat.setAnimatedObject(object3D); |
307 |
} |
308 |
} |
309 |
|
310 |
if (f instanceof View3D) { |
311 |
IAnimationTrack trackAux = ac.findTrack("encuadrator_track_2D");
|
312 |
if (trackAux != null) { |
313 |
trackAux.setEnabale(false);
|
314 |
} |
315 |
} |
316 |
|
317 |
if (f instanceof View) { |
318 |
IAnimationTrack trackAux = ac.findTrack("encuadrator_track_3D");
|
319 |
if (trackAux != null) { |
320 |
trackAux.setEnabale(false);
|
321 |
} |
322 |
} |
323 |
return at;
|
324 |
|
325 |
} |
326 |
|
327 |
private AnimationContainer getAnimationContainer() {
|
328 |
|
329 |
return (AnimationContainer) project.getAnimationContainer();
|
330 |
} |
331 |
|
332 |
|
333 |
public void postInitialize(){ |
334 |
|
335 |
IExtension extension = PluginServices |
336 |
.getExtension(com.iver.cit.gvsig.ProjectExtension.class); |
337 |
ProjectExtension pe = (ProjectExtension) extension; |
338 |
project = pe.getProject(); |
339 |
|
340 |
|
341 |
ac = (AnimationContainer) project.getAnimationContainer(); |
342 |
ac = this.getAnimationContainer();
|
343 |
if (ac == null){ |
344 |
ac = new AnimationContainer();
|
345 |
project.setAnimationContainer(ac); |
346 |
} |
347 |
|
348 |
PluginServices.getIconTheme().registerDefault( |
349 |
"camera-link-icon",
|
350 |
this.getClass().getClassLoader().getResource(
|
351 |
"images/camera_link.png"));
|
352 |
PluginServices.getIconTheme().registerDefault( |
353 |
"camera-add-icon",
|
354 |
this.getClass().getClassLoader().getResource(
|
355 |
"images/camera_add.png"));
|
356 |
PluginServices.getIconTheme().registerDefault( |
357 |
"camera-edit-icon",
|
358 |
this.getClass().getClassLoader().getResource(
|
359 |
"images/camera_edit.png"));
|
360 |
|
361 |
} |
362 |
|
363 |
|
364 |
public void initialize() { |
365 |
|
366 |
// Registering TOC actions
|
367 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
368 |
extensionPoints.add("View_TocActions","Generar animacion temporal",new TocAnimationDate()); |
369 |
} |
370 |
|
371 |
public boolean isEnabled() { |
372 |
// TODO Auto-generated method stub
|
373 |
return true; |
374 |
} |
375 |
|
376 |
public boolean isVisible() { |
377 |
|
378 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices |
379 |
.getMDIManager().getActiveWindow(); |
380 |
|
381 |
if (f == null) { |
382 |
return false; |
383 |
} |
384 |
|
385 |
// Only isVisible = true, where the view3D have layers
|
386 |
if (f instanceof BaseView) { |
387 |
return true; |
388 |
} |
389 |
return false; |
390 |
} |
391 |
|
392 |
} |