svn-gvsig-desktop / import / ext3D / branches / ext3D_v1.1 / extAnimationGUI / src / com / iver / ai2 / animationgui / gui / MenuAnimation3D.java @ 15422
History | View | Annotate | Download (8.92 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.gvsig3d.camera.ProjectCamera; |
8 |
import com.iver.ai2.gvsig3d.gui.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.AnimationLayer2D; |
16 |
import com.iver.cit.gvsig.animation.AnimationLayer3DFlat; |
17 |
import com.iver.cit.gvsig.animation.AnimationPlayer; |
18 |
import com.iver.cit.gvsig.animation.AnimationTypeFactoryLayer2D; |
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.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.libjosg.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 |
|
53 |
public void execute(String actionCommand) { |
54 |
|
55 |
// TODO Auto-generated method stub
|
56 |
// if the button pressed is animation control the animation panel is
|
57 |
// created.
|
58 |
if (actionCommand.equals("CONTROLES")) { |
59 |
System.out.println("pulsado boton controles !!!"); |
60 |
|
61 |
// ProjectExtent[] ex = project.getExtents();
|
62 |
// for (int i = 0; i < ex.length; i++) {
|
63 |
// ProjectExtent projectExtent = ex[i];
|
64 |
// System.out.println(projectExtent);
|
65 |
// }
|
66 |
|
67 |
AnimationContainer ac = project.getAnimationContainer(); |
68 |
AnimationPlayer ap = ac.getAnimationPlayer(); |
69 |
ap.setAnimationContainer(ac); |
70 |
AnimationContol3D fp = new AnimationContol3D(ap);
|
71 |
PluginServices.getMDIManager().addWindow((IWindow) fp); |
72 |
} else if (actionCommand.equals("ENCUADRECAP")) {// button capture |
73 |
// snapshot pressed.
|
74 |
System.out.println("pulsado boton de capturar encuadres!!!"); |
75 |
|
76 |
String name = "Animation-" + cont++; |
77 |
List keyFrameList = null; |
78 |
|
79 |
// Getting the active windows
|
80 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
81 |
|
82 |
// crear track sino existe
|
83 |
ac = this.getAnimationContainer();
|
84 |
animationTimeTrack = this.getAnimationTimeTrack(
|
85 |
"encuadrator_track", ac);
|
86 |
// generar el intervalo
|
87 |
if (AKFinterval == null) { |
88 |
AKFinterval = (AnimationKeyFrameInterval) animationTimeTrack |
89 |
.createKeyFrameInterval(); |
90 |
AKFinterval.setInitialTime(0.0);
|
91 |
AKFinterval.setEndTime(1.0);
|
92 |
} |
93 |
|
94 |
// If the w is instance of View
|
95 |
if (w instanceof View) { |
96 |
|
97 |
BaseView view = (BaseView) w; |
98 |
MapControl mapa = view.getMapControl(); |
99 |
ProjectExtent extent = ProjectFactory.createExtent(); |
100 |
extent.setDescription(name); |
101 |
extent.setExtent(mapa.getViewPort().getExtent()); |
102 |
project.addExtent(extent); |
103 |
|
104 |
// generar lista de keyframes
|
105 |
|
106 |
ProjectExtent[] extentsList = project.getExtents();
|
107 |
keyFrameList = new ArrayList(); |
108 |
for (int i = 0; i < extentsList.length; i++) { |
109 |
ProjectExtent projectExtent = extentsList[i]; |
110 |
KeyFrame2D kf2D = new KeyFrame2D();
|
111 |
double fin = AKFinterval.getEndTime();
|
112 |
double ini = AKFinterval.getInitialTime();
|
113 |
double size = extentsList.length;
|
114 |
// Calcular el tiempo de insercion
|
115 |
double tiempo = 0.0; |
116 |
if (i != 0) |
117 |
tiempo = i * ((fin - ini) / (size - 1.0));
|
118 |
// (AKFinterval.getEndTime() - AKFinterval
|
119 |
// .getInitialTime()) / extentsList.length);
|
120 |
kf2D.setTime(tiempo); |
121 |
// hacer funcion de insercion o adapter
|
122 |
// kf2D.CapturesProperties(projectExtent);
|
123 |
kf2D.setAnimatedObject(projectExtent); |
124 |
keyFrameList.add(kf2D); |
125 |
|
126 |
} |
127 |
} |
128 |
|
129 |
if (w instanceof View3D) { |
130 |
|
131 |
View3D view = (View3D) w; |
132 |
Camera ca = view.getCamera(); |
133 |
|
134 |
ProjectCamera camera = new ProjectCamera();
|
135 |
camera.setDescription(name); |
136 |
camera.setCamera(ca); |
137 |
|
138 |
Object[] l = project.getCameras(); |
139 |
|
140 |
|
141 |
project.addCamera(camera); |
142 |
|
143 |
|
144 |
// generar lista de keyframes
|
145 |
|
146 |
Object[] extentsList = project.getCameras(); |
147 |
keyFrameList = new ArrayList(); |
148 |
for (int i = 0; i < extentsList.length; i++) { |
149 |
ProjectCamera projectCamera = (ProjectCamera) extentsList[i]; |
150 |
KeyFrame3DFlat kf2D = new KeyFrame3DFlat();
|
151 |
double fin = AKFinterval.getEndTime();
|
152 |
double ini = AKFinterval.getInitialTime();
|
153 |
double size = extentsList.length;
|
154 |
// Calcular el tiempo de insercion
|
155 |
double tiempo = 0.0; |
156 |
if (i != 0) |
157 |
tiempo = i * ((fin - ini) / (size - 1.0));
|
158 |
// (AKFinterval.getEndTime() - AKFinterval
|
159 |
// .getInitialTime()) / extentsList.length);
|
160 |
kf2D.setTime(tiempo); |
161 |
// hacer funcion de insercion o adapter
|
162 |
// kf2D.CapturesProperties(projectExtent);
|
163 |
kf2D.setAnimatedObject(projectCamera); |
164 |
keyFrameList.add(kf2D); |
165 |
|
166 |
} |
167 |
} |
168 |
|
169 |
|
170 |
AKFinterval.setKeyFrameList(keyFrameList); |
171 |
|
172 |
System.out.println(ac);
|
173 |
|
174 |
} else if (actionCommand.equals("CAPACAP")) {// button capture layer |
175 |
// pressed.
|
176 |
System.out.println("pulsado boton de capturar capa!!!"); |
177 |
} |
178 |
|
179 |
} |
180 |
|
181 |
private AnimationTimeTrack getAnimationTimeTrack(String name, |
182 |
AnimationContainer ac) { |
183 |
AnimationTimeTrack at = this.animationTimeTrack;
|
184 |
IAnimationTrack aa = ac.findTrack(name); |
185 |
if (aa == null) { |
186 |
|
187 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton |
188 |
.getInstance(); |
189 |
ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints |
190 |
.get("Animation"));
|
191 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices |
192 |
.getMDIManager().getActiveWindow(); |
193 |
if (f instanceof View) { |
194 |
AnimationLayer2D animationLayer2D = null;
|
195 |
try {
|
196 |
animationLayer2D = (AnimationLayer2D) extPoint |
197 |
.create("AnimationLayer2D");
|
198 |
} catch (InstantiationException e) { |
199 |
// TODO Auto-generated catch block
|
200 |
e.printStackTrace(); |
201 |
} catch (IllegalAccessException e) { |
202 |
// TODO Auto-generated catch block
|
203 |
e.printStackTrace(); |
204 |
} |
205 |
at = (AnimationTimeTrack) ac.CreateTimeTrack(animationLayer2D); |
206 |
at.setName(name); |
207 |
View view = (View) f; |
208 |
at.setAnimatedObject(view); |
209 |
Interpolator2D inter2D = new Interpolator2D();
|
210 |
inter2D.setAnimatedObject(view); |
211 |
animationLayer2D.setInterpolator(inter2D); |
212 |
at.setAnimationType(animationLayer2D); |
213 |
animationLayer2D.setAnimatedObject(view); |
214 |
} |
215 |
if (f instanceof View3D) { |
216 |
AnimationLayer3DFlat animationLayer3DFlat = null;
|
217 |
try {
|
218 |
animationLayer3DFlat = (AnimationLayer3DFlat) extPoint |
219 |
.create("AnimationLayer3DFlat");
|
220 |
} catch (InstantiationException e) { |
221 |
// TODO Auto-generated catch block
|
222 |
e.printStackTrace(); |
223 |
} catch (IllegalAccessException e) { |
224 |
e.printStackTrace(); |
225 |
} |
226 |
at = (AnimationTimeTrack) ac.CreateTimeTrack(animationLayer3DFlat); |
227 |
at.setName(name); |
228 |
BaseView view = (BaseView) f; |
229 |
at.setAnimatedObject(view); |
230 |
Interpolator3DFlat inter3DFlat = new Interpolator3DFlat();
|
231 |
inter3DFlat.setAnimatedObject(view); |
232 |
animationLayer3DFlat.setInterpolator(inter3DFlat); |
233 |
at.setAnimationType(animationLayer3DFlat); |
234 |
animationLayer3DFlat.setAnimatedObject(view); |
235 |
} |
236 |
} |
237 |
return at;
|
238 |
|
239 |
} |
240 |
|
241 |
private AnimationContainer getAnimationContainer() {
|
242 |
|
243 |
return project.getAnimationContainer();
|
244 |
} |
245 |
|
246 |
public void initialize() { |
247 |
|
248 |
// Getting the project using pluggin services
|
249 |
IExtension extension = PluginServices |
250 |
.getExtension(com.iver.cit.gvsig.ProjectExtension.class); |
251 |
ProjectExtension pe = (ProjectExtension) extension; |
252 |
project = pe.getProject(); |
253 |
|
254 |
// Register types
|
255 |
AnimationTypeFactoryLayer2D.register(); |
256 |
// AnimationTypeFactoryLayer3DFlat.register();
|
257 |
} |
258 |
|
259 |
public boolean isEnabled() { |
260 |
// TODO Auto-generated method stub
|
261 |
return true; |
262 |
} |
263 |
|
264 |
public boolean isVisible() { |
265 |
|
266 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices |
267 |
.getMDIManager().getActiveWindow(); |
268 |
|
269 |
if (f == null) { |
270 |
return false; |
271 |
} |
272 |
|
273 |
// Only isVisible = true, where the view3D have layers
|
274 |
if (f instanceof BaseView) { |
275 |
return true; |
276 |
} |
277 |
return false; |
278 |
} |
279 |
|
280 |
} |