gvsig-3d / org.gvsig.animation3d / trunk / org.gvsig.animation3d / org.gvsig.animation3d.swing / org.gvsig.animation3d.swing.impl / src / main / java / org / gvsig / animation3d / swing / impl / DefaultAnimation3DSwingManager.java @ 685
History | View | Annotate | Download (7.09 KB)
1 |
package org.gvsig.animation3d.swing.impl; |
---|---|
2 |
|
3 |
import gov.nasa.worldwind.View; |
4 |
import gov.nasa.worldwind.WorldWind; |
5 |
import gov.nasa.worldwind.animation.AnimationSupport; |
6 |
import gov.nasa.worldwind.avlist.AVKey; |
7 |
import gov.nasa.worldwind.awt.WorldWindowGLJPanel; |
8 |
import gov.nasa.worldwind.geom.Angle; |
9 |
import gov.nasa.worldwind.geom.LatLon; |
10 |
import gov.nasa.worldwind.geom.Position; |
11 |
import gov.nasa.worldwind.globes.Globe; |
12 |
import gov.nasa.worldwind.view.orbit.FlyToOrbitViewAnimator; |
13 |
import gov.nasa.worldwind.view.orbit.OrbitView; |
14 |
|
15 |
import java.util.ArrayList; |
16 |
import java.util.Collection; |
17 |
import java.util.List; |
18 |
import java.util.Map; |
19 |
|
20 |
import org.gvsig.animation3d.swing.api.Animation3D; |
21 |
import org.gvsig.animation3d.swing.api.Animation3DPanel; |
22 |
import org.gvsig.animation3d.swing.api.Animation3DSwingManager; |
23 |
import org.gvsig.animation3d.swing.api.Animator; |
24 |
import org.gvsig.animation3d.swing.api.Frame3D; |
25 |
import org.gvsig.animation3d.swing.api.Frame3DCreationException; |
26 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
27 |
import org.gvsig.fmap.geom.GeometryLocator; |
28 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
29 |
import org.gvsig.fmap.geom.primitive.Point; |
30 |
import org.gvsig.fmap.mapcontext.layers.ExtendedPropertiesSupport; |
31 |
import org.gvsig.tools.persistence.impl.DelegatedList; |
32 |
import org.gvsig.view3d.swing.api.MapControl3D; |
33 |
|
34 |
/**
|
35 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
36 |
*
|
37 |
*/
|
38 |
public class DefaultAnimation3DSwingManager implements Animation3DSwingManager { |
39 |
|
40 |
@SuppressWarnings("unchecked") |
41 |
@Override
|
42 |
public List<Animation3D> getAnimations(ExtendedPropertiesSupport properties) { |
43 |
Object animationsList = properties.getProperty("animations"); |
44 |
if (animationsList == null) { |
45 |
List<Animation3D> animations = new ArrayList<Animation3D>(); |
46 |
setAnimations(properties, animations); |
47 |
return animations;
|
48 |
} else {
|
49 |
if (animationsList instanceof DelegatedList) { |
50 |
List<Animation3D> animations = new ArrayList<Animation3D>(); |
51 |
animations.addAll((Collection<? extends Animation3D>) animationsList); |
52 |
setAnimations(properties, animations); |
53 |
return animations;
|
54 |
} else {
|
55 |
return (List<Animation3D>) animationsList; |
56 |
} |
57 |
} |
58 |
} |
59 |
|
60 |
@Override
|
61 |
public void setAnimations(ExtendedPropertiesSupport properties, List<Animation3D> animations) { |
62 |
properties.setProperty("animations", animations);
|
63 |
} |
64 |
|
65 |
@Override
|
66 |
public Frame3D createFrame3D(String name, MapControl3D mapControl3D) |
67 |
throws Frame3DCreationException {
|
68 |
|
69 |
OrbitView orbitView = getOrbitView(mapControl3D); |
70 |
double heading = orbitView.getHeading().getDegrees();
|
71 |
double pitch = orbitView.getPitch().getDegrees();
|
72 |
double elevation = orbitView.getCenterPosition().getElevation();
|
73 |
double zoom = orbitView.getZoom();
|
74 |
|
75 |
Point position = null; |
76 |
double x = orbitView.getCenterPosition().getLongitude().getDegrees();
|
77 |
double y = orbitView.getCenterPosition().getLatitude().getDegrees();
|
78 |
try {
|
79 |
position = GeometryLocator.getGeometryManager().createPoint(x, y, SUBTYPES.GEOM2D); |
80 |
} catch (CreateGeometryException e) {
|
81 |
String msg =
|
82 |
String.format("Can not create frame position [longitude: %1s latitude: %2s]", |
83 |
new Object[] { x, y }); |
84 |
throw new Frame3DCreationException(msg, e); |
85 |
} |
86 |
|
87 |
return createFrame3D(name, heading, pitch, elevation, position, zoom);
|
88 |
} |
89 |
|
90 |
public Frame3D createFrame3D(String name, double heading, double pitch, double elevation, |
91 |
Point position, double zoom) { |
92 |
return new DefaultFrame3D(name, heading, pitch, elevation, position, zoom); |
93 |
} |
94 |
|
95 |
@Override
|
96 |
public Animation3D createAnimation3D(String name, List<Frame3D> sphericalFrames, |
97 |
List<Frame3D> flatFrames) {
|
98 |
return new DefaultAnimation3D(name, sphericalFrames, flatFrames); |
99 |
} |
100 |
|
101 |
@Override
|
102 |
public Animation3DPanel createAnimationPanel(Map<String, ExtendedPropertiesSupport> properties) { |
103 |
return new DefaultAnimation3DPanelController(properties); |
104 |
} |
105 |
|
106 |
@Override
|
107 |
public Animator createGoToAnimator(MapControl3D mapControl3D, Frame3D frame,
|
108 |
final long minMillis, final long maxMillis) { |
109 |
|
110 |
OrbitView orbitView = getOrbitView(mapControl3D); |
111 |
Globe globe = orbitView.getGlobe(); |
112 |
double longitude = frame.getPosition().getX();
|
113 |
double latitude = frame.getPosition().getY();
|
114 |
Position endPos =
|
115 |
new Position(LatLon.fromDegrees(latitude, longitude), globe.getElevation( |
116 |
Angle.fromDegrees(latitude), Angle.fromDegrees(longitude)) |
117 |
+ frame.getElevation()); |
118 |
|
119 |
Position beginPos =
|
120 |
Position.fromDegrees(orbitView.getCenterPosition().getLatitude().getDegrees(),
|
121 |
orbitView.getCenterPosition().getLongitude().getDegrees(), orbitView |
122 |
.getCenterPosition().getElevation()); |
123 |
long timeToMove =
|
124 |
AnimationSupport.getScaledTimeMillisecs(beginPos, endPos, minMillis, maxMillis); |
125 |
|
126 |
gov.nasa.worldwind.animation.Animator animator = |
127 |
FlyToOrbitViewAnimator.createFlyToOrbitViewAnimator(orbitView, beginPos, endPos, |
128 |
orbitView.getHeading(), Angle.fromDegrees(frame.getHeading()), |
129 |
orbitView.getPitch(), Angle.fromDegrees(frame.getPitch()), orbitView.getZoom(), |
130 |
frame.getZoom(), timeToMove, WorldWind.ABSOLUTE); |
131 |
return new DefaultAnimatorWrapper(animator); |
132 |
} |
133 |
|
134 |
@Override
|
135 |
public Animator createGoToAnimator(MapControl3D mapControl3D, List<Frame3D> frames, |
136 |
long minMillis, long maxMillis) { |
137 |
OrbitView orbitView = getOrbitView(mapControl3D); |
138 |
gov.nasa.worldwind.animation.Animator animator = |
139 |
new MultipleFlyToOrbitViewAnimator(orbitView, frames, minMillis, maxMillis);
|
140 |
return new DefaultAnimatorWrapper(animator); |
141 |
} |
142 |
|
143 |
@Override
|
144 |
public void addAnimator(MapControl3D mapControl3D, Animator animator) { |
145 |
OrbitView orbitView = getOrbitView(mapControl3D); |
146 |
orbitView.addAnimator(new DefaultWWAnimationWrapper(animator));
|
147 |
orbitView.firePropertyChange(AVKey.VIEW, null, orbitView);
|
148 |
} |
149 |
|
150 |
@Override
|
151 |
public boolean isAnimating(MapControl3D mapControl3D) { |
152 |
OrbitView orbitView = getOrbitView(mapControl3D); |
153 |
return orbitView.isAnimating();
|
154 |
} |
155 |
|
156 |
@Override
|
157 |
public void stopAnimations(MapControl3D mapControl3D) { |
158 |
OrbitView orbitView = getOrbitView(mapControl3D); |
159 |
orbitView.stopAnimations(); |
160 |
} |
161 |
|
162 |
private OrbitView getOrbitView(MapControl3D mapControl3D) {
|
163 |
Object underLineComponent = mapControl3D.getUnderLineComponent();
|
164 |
if (underLineComponent instanceof WorldWindowGLJPanel) { |
165 |
WorldWindowGLJPanel wwd = (WorldWindowGLJPanel) underLineComponent; |
166 |
View view = wwd.getView();
|
167 |
if (view instanceof OrbitView) { |
168 |
return (OrbitView) view;
|
169 |
} |
170 |
} |
171 |
throw new IllegalArgumentException( |
172 |
"Can not get WorldWind view from under line MapControl3D component");
|
173 |
} |
174 |
} |