Revision 20095 trunk/extensions/extAnimationGUI/src/com/iver/ai2/animationgui/gui/MenuAnimation3D.java

View differences:

MenuAnimation3D.java
1 1
package com.iver.ai2.animationgui.gui;
2 2

  
3
import java.util.ArrayList;
4
import java.util.List;
3
import javax.swing.JOptionPane;
5 4

  
5
import com.iver.ai2.animationgui.gui.document.ProjectAnimationDocument;
6 6
import com.iver.ai2.animationgui.gui.toc.TocAnimationDate;
7
import com.iver.ai2.animationgui.gui.util.AnimationUtils;
7 8
import com.iver.ai2.gvsig3d.camera.ProjectCamera;
8
import com.iver.ai2.gvsig3dgui.view.View3D;
9 9
import com.iver.andami.PluginServices;
10 10
import com.iver.andami.plugins.Extension;
11 11
import com.iver.andami.plugins.IExtension;
......
13 13
import com.iver.cit.gvsig.ProjectExtension;
14 14
import com.iver.cit.gvsig.animation.AnimationContainer;
15 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 16
import com.iver.cit.gvsig.project.Project;
28
import com.iver.cit.gvsig.project.ProjectExtent;
29
import com.iver.cit.gvsig.project.ProjectFactory;
30 17
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 18
import com.iver.utiles.extensionPoints.ExtensionPoints;
34 19
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
35 20

  
36
import es.upv.ai2.osgvp.viewer.Camera;
37

  
38 21
/**
39 22
 * @author
40 23
 * @since 1.1
......
44 27

  
45 28
public class MenuAnimation3D extends Extension {
46 29

  
30
	// private variable that contains the project
47 31
	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
	private String AnimationPrefix = "Animation-";
32
	// It is the project Document create to create a fast animation.
33
	private ProjectAnimationDocument pad;
55 34

  
56 35
	public void execute(String actionCommand) {
57 36

  
58
		// TODO Auto-generated method stub
37
		AnimationContainer ac;
38
		String prefix = "Default-animation-document";
59 39
		// if the button pressed is animation control the animation panel is
60 40
		// created.
61 41
		if (actionCommand.equals("CONTROLES")) {
62
			System.out.println("pulsado boton controles !!!");
42
			// Getting the animation container.
43
			if (pad != null) {
44
				ac = pad.getAnimationContainer();
45
				AnimationPlayer ap = ac.getAnimationPlayer();
46
				ap.setAnimationContainer(ac);
47
				AnimationContol3D fp = new AnimationContol3D(ap);
48
				PluginServices.getMDIManager().addWindow((IWindow) fp);
49
			} else {
50
				if (AnimationUtils.exitsProject(prefix, project)){
51
					ac = AnimationUtils.getProjectDocument(prefix, project).getAnimationContainer();
52
					AnimationPlayer ap = ac.getAnimationPlayer();
53
					ap.setAnimationContainer(ac);
54
					AnimationContol3D fp = new AnimationContol3D(ap);
55
					PluginServices.getMDIManager().addWindow((IWindow) fp);
56
				}else{
57
					// Show a message that indicates why it is impossible to open
58
					// the player
59
					JOptionPane
60
					.showMessageDialog(null,
61
					"There is not any animation document. Please create one");
62
				}
63
			}
63 64

  
64
			// ProjectExtent[] ex = project.getExtents();
65
			// for (int i = 0; i < ex.length; i++) {
66
			// ProjectExtent projectExtent = ex[i];
67
			// System.out.println(projectExtent);
68
			// }
69
			
70
			AnimationContainer ac = (AnimationContainer) project.getAnimationContainer();
71
			AnimationPlayer ap = ac.getAnimationPlayer();
72
			ap.setAnimationContainer(ac);
73
			AnimationContol3D fp = new AnimationContol3D(ap);
74
			PluginServices.getMDIManager().addWindow((IWindow) fp);
75
			
76 65
		} else if (actionCommand.equals("ENCUADRECAP")) {// button capture
77
			// snapshot pressed.
78
			System.out.println("pulsado boton de capturar encuadres!!!");
66
			// if there is not create the default animation. we will create it.
67
			pad = AnimationUtils.createAnimationDocument(prefix, project);
68
			if (!AnimationUtils.exitsProject(prefix, project)){
69
				project.addDocument(pad);
70
			}
79 71

  
80
			String name = AnimationPrefix  + cont++;
81
			List keyFrameList = null;
82

  
83 72
			// Getting the active windows
84 73
			IWindow w = PluginServices.getMDIManager().getActiveWindow();
85
			
74

  
86 75
			// Getting the animation container.
87
			ac = this.getAnimationContainer();
76
			ac = pad.getAnimationContainer();
88 77

  
89
			// If the window instance is View, it will manage extends 2D
90
			if (w instanceof View) {
91
				
92
				// Getting the animation extension point.
93
				ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
94
				ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints.get("Animation"));
95
				
96
				// Creating new track
97
				animationTimeTrack = this.getAnimationTimeTrack(
98
						"encuadrator_track_2D", ac);
99
				// Creating the interval
100
				if (AKFinterval == null) {
101
					AKFinterval = (AnimationKeyFrameInterval) animationTimeTrack
102
							.createKeyFrameInterval();
103
					// Setting up interval properties. 
104
					AKFinterval.setInitialTime(0.0);
105
					AKFinterval.setEndTime(1.0);
106
				}
107
				
108
				// Getting the current extend and adding to project extends.
109
				BaseView view = (BaseView) w;
110
				MapControl mapa = view.getMapControl();
111
				ProjectExtent extent = ProjectFactory.createExtent();
112
				extent.setDescription(name);
113
				extent.setExtent(mapa.getViewPort().getExtent());
114
				project.addExtent(extent);
78
			// Capture the new encuadrator
79
			AnimationUtils.captureEncuadrator((BaseView) w, ac, prefix);
115 80

  
116
				// Creating the keyframe list.
117
				ProjectExtent[] extentsList = project.getExtents();
118
				keyFrameList = new ArrayList();
119
				for (int i = 0; i < extentsList.length; i++) {
120
					ProjectExtent projectExtent = extentsList[i];
121
					if (projectExtent.getDescription().contains(AnimationPrefix)){
122
						IKeyFrame kf2D = null;
123
						try {
124
							kf2D = (IKeyFrame)extPoint.create("KeyFrame2D");
125
						} catch (InstantiationException e) {
126
							//TODO stop this loop and show a advertise message.
127
							e.printStackTrace();
128
						} catch (IllegalAccessException e) {
129
							e.printStackTrace();
130
						}
131
						
132
						// Setting up the initial and end time interval.
133
						double fin = AKFinterval.getEndTime();
134
						double ini = AKFinterval.getInitialTime();
135
						double size = extentsList.length;
136
						// Calculating the insertion time.
137
						double tiempo = 0.0;
138
						if (i != 0)
139
							tiempo = i * ((fin - ini) / (size - 1.0));
140
						kf2D.setTime(tiempo);
141
						// hacer funcion de insercion o adapter
142
						kf2D.setAnimatedObject(projectExtent);
143
						kf2D.CapturesProperties();
144
						keyFrameList.add(kf2D);
145
					}
146
				}
147
			}
148

  
149
			if (w instanceof View3D) {
150
				
151
				// Getting the animation extension point.
152
				ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
153
				ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints.get("Animation"));
154
				
155
				// Creating new track
156
				animationTimeTrack = this.getAnimationTimeTrack(
157
						"encuadrator_track_3D", ac);
158
				
159
				// Creating the interval
160
				if (AKFinterval == null) {
161
					AKFinterval = (AnimationKeyFrameInterval) animationTimeTrack
162
							.createKeyFrameInterval();
163
					AKFinterval.setInitialTime(0.0);
164
					AKFinterval.setEndTime(1.0);
165
				}
166
				
167
				// Getting the current camera position and insert it into project camera list. 
168
				View3D view = (View3D) w;
169
				Camera ca = view.getCamera();
170
				ProjectCamera camera = new ProjectCamera();
171
				camera.setDescription(name);
172
				camera.setCamera(ca);
173
				project.addCamera(camera);
174
				
175
				// Creating key frame list
176
				Object[] extentsList = project.getCameras();
177
				keyFrameList = new ArrayList();
178
				for (int i = 0; i < extentsList.length; i++) {
179
					ProjectCamera projectCamera = (ProjectCamera) extentsList[i];
180
					if (projectCamera.getDescription().contains(AnimationPrefix)){
181
						IKeyFrame kf3D = null;
182
						try {
183
							kf3D = (IKeyFrame)extPoint.create("KeyFrame3DFlat");
184
						} catch (InstantiationException e) {
185
							e.printStackTrace();
186
						} catch (IllegalAccessException e) {
187
							e.printStackTrace();
188
						}
189
						
190
						// Setting up the initial and end time interval.
191
						double fin = AKFinterval.getEndTime();
192
						double ini = AKFinterval.getInitialTime();
193
						double size = extentsList.length;
194
						// Calculating the correct time for this key frame.
195
						double tiempo = 0.0;
196
						if (i != 0)
197
							tiempo = i * ((fin - ini) / (size - 1.0));
198
						// Setting the time.
199
						kf3D.setTime(tiempo);
200
						// hacer funcion de insercion o adapter
201
						kf3D.setAnimatedObject(projectCamera);
202
						kf3D.CapturesProperties();
203
						keyFrameList.add(kf3D);
204
					}
205
				}
206
			}
207
			AKFinterval.setKeyFrameList(keyFrameList);
208
			System.out.println(ac);
209 81
		} else if (actionCommand.equals("CAPACAP")) {// button capture layer
210 82
			// pressed.
211 83
			System.out.println("pulsado boton de capturar capa!!!");
212
		} else if (actionCommand.equals("BORRAR")){
213
			removeCameras(AnimationPrefix);
214
			AKFinterval = null;
215
			cont = 0;
216
			ac = this.getAnimationContainer();
217
			ac.removeAllTrack();			
84
		} else if (actionCommand.equals("BORRAR")) {
85
			// removeCameras(AnimationPrefix);
86
			// // AKFinterval = null;
87
			// cont = 0;
88
			// ac = this.getAnimationContainer();
89
			// ac.removeAllTrack();
218 90
		}
219
			
220 91

  
221 92
	}
222
	
93

  
223 94
	/**
224
	 * This method removes all the captures that there are in the encuadrator with the substring "substring"
225
	 *  
226
	 * @param substring the method removes all the captures that contain this substring.
95
	 * This method removes all the captures that there are in the encuadrator
96
	 * with the substring "substring"
227 97
	 * 
98
	 * @param substring
99
	 *            the method removes all the captures that contain this
100
	 *            substring.
101
	 * 
228 102
	 */
229
	void removeCameras(String substring){
103
	void removeCameras(String substring) {
230 104
		// Remove all animation keyframe from the encuadrator.
231 105
		Object[] pcList = project.getCameras();
232 106
		int i = 0;
233 107
		while (i < pcList.length) {
234 108
			ProjectCamera projectCamera = (ProjectCamera) pcList[i];
235
			if(projectCamera.getDescription().contains(substring)){
109
			if (projectCamera.getDescription().contains(substring)) {
236 110
				project.removeCamera(i);
237 111
				pcList = project.getCameras();
238 112
			} else {
......
241 115
		}
242 116
	}
243 117

  
118
	public void postInitialize() {
244 119

  
245
	private AnimationTimeTrack getAnimationTimeTrack(String name,
246
			AnimationContainer ac) {
247

  
248
		com.iver.andami.ui.mdiManager.IWindow f = PluginServices
249
				.getMDIManager().getActiveWindow();
250

  
251
		AnimationTimeTrack at = this.animationTimeTrack;
252
		IAnimationTrack aa = ac.findTrack(name);
253
		if (aa == null) {
254

  
255
			// Getting the extension point.
256
			ExtensionPoints extensionPoints = ExtensionPointsSingleton
257
					.getInstance();
258
			ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints
259
					.get("Animation"));
260

  
261
			// If f is a 2D windows, it will create with 2D specific animation type.
262
			if (f instanceof View) {
263
				
264
				// Finding if there are an 3D animation track.
265
				IAnimationTrack trackAux = ac.findTrack("encuadrator_track_3D");
266
				if (trackAux != null) {
267
					// if there are one, it will disable.
268
					trackAux.setEnabale(false);
269
				}
270
				IAnimationType animationLayer2D = null;
271
				try {
272
					animationLayer2D = (IAnimationType) extPoint
273
							.create("AnimationLayer2D");
274
				} catch (InstantiationException e) {
275
					// TODO Auto-generated catch block
276
					e.printStackTrace();
277
				} catch (IllegalAccessException e) {
278
					// TODO Auto-generated catch block
279
					e.printStackTrace();
280
				}
281
				// Setting up the track properties
282
				at = (AnimationTimeTrack) ac.CreateTimeTrack(animationLayer2D);
283
				at.setName(name);
284
				at.setEnabale(true);
285
				// Setting up the animated object
286
				View view = (View) f;
287
				at.setAnimatedObject(object2D);
288

  
289
				// Getting the interpolator
290
				IInterpolator inter2D = InterpolatorFactory.createObject("Interpolator2D");
291
				object2D.addAnimatedObject("view2D", view);
292
				// Getting the interpolator funcion
293
				IInterpolatorTimeFuntion funtion = FuntionFactory.createObject("com.iver.cit.gvsig.animation.keyframe.interpolator.LinearFuntion");
294
				inter2D.setFuntion(funtion);
295
				
296
				animationLayer2D.setInterpolator(inter2D);
297
				at.setAnimationType(animationLayer2D);
298
				animationLayer2D.setAnimatedObject(object2D);
299
			}
300
			if (f instanceof View3D) {
301
				// Finding if there are an 2D animation track.
302
				IAnimationTrack trackAux = ac.findTrack("encuadrator_track_2D");
303
				if (trackAux != null) {
304
					// if there are one, it will disable.
305
					trackAux.setEnabale(false);
306
				}
307
				IAnimationType animationLayer3DFlat = null;
308
				try {
309
					animationLayer3DFlat = (IAnimationType) extPoint
310
							.create("AnimationLayer3DFlat");
311
				} catch (InstantiationException e) {
312
					// TODO Auto-generated catch block
313
					e.printStackTrace();
314
				} catch (IllegalAccessException e) {
315
					e.printStackTrace();
316
				}
317
				at = (AnimationTimeTrack) ac
318
						.CreateTimeTrack(animationLayer3DFlat);
319
				
320
				at.setName(name);
321
				at.setEnabale(true);
322
				
323
				BaseView view = (BaseView) f;
324
				object3D.addAnimatedObject("view", view);
325
				at.setAnimatedObject(object3D);
326
				
327
				IInterpolator inter3DFlat = InterpolatorFactory.createObject("Interpolator3DFlat");
328
				IInterpolatorTimeFuntion funtion = FuntionFactory.createObject("com.iver.cit.gvsig.animation.keyframe.interpolator.LinearFuntion");
329
				inter3DFlat.setFuntion(funtion);				
330
				animationLayer3DFlat.setInterpolator(inter3DFlat);
331
				at.setAnimationType(animationLayer3DFlat);
332
				animationLayer3DFlat.setAnimatedObject(object3D);
333
			}
334
		}
335

  
336
		if (f instanceof View3D) {
337
			IAnimationTrack trackAux = ac.findTrack("encuadrator_track_2D");
338
			if (trackAux != null) {
339
				trackAux.setEnabale(false);
340
			}
341
		}
342

  
343
		if (f instanceof View) {
344
			IAnimationTrack trackAux = ac.findTrack("encuadrator_track_3D");
345
			if (trackAux != null) {
346
				trackAux.setEnabale(false);
347
			}
348
		}
349
		return at;
350

  
351
	}
352

  
353
	private AnimationContainer getAnimationContainer() {
354

  
355
		return (AnimationContainer) project.getAnimationContainer();
356
	}
357
	
358
	
359
	public void postInitialize(){
360
		
361 120
		IExtension extension = PluginServices
362
		.getExtension(com.iver.cit.gvsig.ProjectExtension.class);
121
				.getExtension(com.iver.cit.gvsig.ProjectExtension.class);
363 122
		ProjectExtension pe = (ProjectExtension) extension;
364 123
		project = pe.getProject();
365
		
366
		
367
		ac = (AnimationContainer) project.getAnimationContainer();
368
		ac = this.getAnimationContainer();
369
		if (ac == null){
370
			ac = new AnimationContainer();
371
			project.setAnimationContainer(ac);
372
		}
373
		
124

  
374 125
		PluginServices.getIconTheme().registerDefault(
375 126
				"camera-link-icon",
376 127
				this.getClass().getClassLoader().getResource(
377
				"images/camera_link.png"));
128
						"images/camera_link.png"));
378 129
		PluginServices.getIconTheme().registerDefault(
379 130
				"camera-add-icon",
380 131
				this.getClass().getClassLoader().getResource(
381
				"images/camera_add.png"));
132
						"images/camera_add.png"));
382 133
		PluginServices.getIconTheme().registerDefault(
383 134
				"camera-edit-icon",
384 135
				this.getClass().getClassLoader().getResource(
385
				"images/camera_edit.png"));
386
		
136
						"images/camera_edit.png"));
137

  
387 138
	}
388
	
389 139

  
390 140
	public void initialize() {
391
		
141

  
392 142
		// Registering TOC actions
393
		ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
394
	    extensionPoints.add("View_TocActions","Generar animacion temporal",new TocAnimationDate());
143
		ExtensionPoints extensionPoints = ExtensionPointsSingleton
144
				.getInstance();
145
		extensionPoints.add("View_TocActions", "Generar animacion temporal",
146
				new TocAnimationDate());
395 147
	}
396 148

  
397 149
	public boolean isEnabled() {
398
		// TODO Auto-generated method stub
399 150
		return true;
400 151
	}
401 152

  

Also available in: Unified diff