PageRenderTime 14ms CodeModel.GetById 6ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/src/worldwind/kml/model/KML3DModel.java

http://wwj-kml.googlecode.com/
Java | 121 lines | 59 code | 17 blank | 45 comment | 8 complexity | 9f35a67cb1511b98b922231be7b6df9a MD5 | raw file
  1/**
  2 * 
  3 */
  4package worldwind.kml.model;
  5
  6import gov.nasa.worldwind.geom.Position;
  7import gov.nasa.worldwind.geom.Sector;
  8import gov.nasa.worldwind.render.Renderable;
  9
 10import java.lang.reflect.InvocationTargetException;
 11import java.lang.reflect.Method;
 12import java.security.InvalidParameterException;
 13
 14/**
 15 * This class define external 3D model who may be included in a KML file.
 16 */
 17public class KML3DModel extends KMLGraphic {
 18
 19	/**
 20	 * Specifies how altitude components in the <coordinates> element are
 21	 * interpreted.<br/>
 22	 * Default value is {@link AltitudeMode#RelativeToGround}
 23	 */
 24	private AltitudeMode altitudeMode = AltitudeMode.RelativeToGround;
 25
 26	/**
 27	 * The mesh definition loaded as a WWJ renderable.
 28	 */
 29	private Renderable mesh;
 30
 31	/**
 32	 * This mesh location.
 33	 */
 34	private KMLCoord location;
 35
 36	/**
 37	 * Current sector for this model.
 38	 */
 39	private Sector sector;
 40
 41	/**
 42	 * The mesh definition loaded as a WWJ renderable.
 43	 */
 44	public Renderable getMesh() {
 45		return this.mesh;
 46	}
 47
 48	/**
 49	 * The mesh definition loaded as a WWJ renderable.
 50	 */
 51	public void setMesh(Renderable mesh) {
 52		this.mesh = mesh;
 53		if (this.mesh != null && this.location != null) {
 54			try {
 55				Method m = mesh.getClass().getMethod("moveTo", Position.class);
 56				m.invoke(this.mesh, this.location.toPosition());
 57			} catch (SecurityException e) {
 58				// no accessible
 59			} catch (NoSuchMethodException e) {
 60				// doesn't exists
 61			} catch (IllegalArgumentException e) {
 62				e.printStackTrace();
 63			} catch (IllegalAccessException e) {
 64				e.printStackTrace();
 65			} catch (InvocationTargetException e) {
 66				e.printStackTrace();
 67			}
 68		}
 69	}
 70
 71	/**
 72	 * Specifies how altitude components in the <coordinates> element are
 73	 * interpreted.<br/>
 74	 * Default value is {@link AltitudeMode#RelativeToGround}
 75	 */
 76	public AltitudeMode getAltitudeMode() {
 77		return altitudeMode;
 78	}
 79
 80	/**
 81	 * Specifies how altitude components in the <coordinates> element are
 82	 * interpreted.<br/>
 83	 * Default value is {@link AltitudeMode#RelativeToGround}
 84	 */
 85	public void setAltitudeMode(AltitudeMode mode) {
 86		if (mode == null)
 87			throw new InvalidParameterException("Altitude mode cannot be null");
 88		this.altitudeMode = mode;
 89	}
 90
 91	/**
 92	 * This mesh location.
 93	 */
 94	public KMLCoord getLocation() {
 95		return this.location;
 96	}
 97
 98	/**
 99	 * This mesh location.
100	 */
101	public void setLocation(KMLCoord coord) {
102		this.location = coord;
103	}
104
105	@Override
106	public Sector getSector() {
107		if (sector == null) {
108			// debug size
109			double size = 10.0;
110
111			double minLon = location.lon - size;
112			double minLat = location.lat - size;
113			double maxLon = location.lon + size;
114			double maxLat = location.lat + size;
115
116			sector = Sector.fromDegrees(minLat, maxLat, minLon, maxLon);
117		}
118		return sector;
119	}
120
121}