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