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