Skip to content

Commit 23580f7

Browse files
committed
Repaired exceptions during shape editing when the World Window's vertical exaggeration changes.
1 parent a3a5611 commit 23580f7

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

src/gov/nasa/worldwind/cache/ShapeDataCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static class ShapeDataCacheEntry extends AVListImpl
5656
public ShapeDataCacheEntry(DrawContext dc, long minExpiryTime, long maxExpiryTime)
5757
{
5858
this.timer = new TimedExpirySupport(Math.max(minExpiryTime, 0), Math.max(maxExpiryTime, 0));
59-
this.globeStateKey = dc != null ? dc.getGlobe().getGlobeStateKey(dc) : null;
59+
this.globeStateKey = dc != null ? dc.getGlobe().getGlobeStateKey() : null;
6060
this.verticalExaggeration = dc != null ? dc.getVerticalExaggeration() : 1d;
6161
}
6262

src/gov/nasa/worldwind/util/ShapeEditor.java

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.awt.*;
2323
import java.awt.event.*;
24+
import java.beans.*;
2425
import java.util.*;
2526
import java.util.List;
2627

@@ -40,7 +41,7 @@
4041
* @author tag
4142
* @version $Id: ShapeEditor.java 3423 2015-09-23 20:59:03Z tgaskins $
4243
*/
43-
public class ShapeEditor implements SelectListener
44+
public class ShapeEditor implements SelectListener, PropertyChangeListener
4445
{
4546
// Control point purposes
4647
/**
@@ -680,6 +681,7 @@ protected void enable()
680681
this.updateControlPoints();
681682

682683
this.getWwd().addSelectListener(this);
684+
this.getWwd().getSceneController().addPropertyChangeListener(this);
683685
}
684686

685687
/**
@@ -695,6 +697,7 @@ protected void disable()
695697
layers.remove(this.getShadowLayer());
696698

697699
getWwd().removeSelectListener(this);
700+
getWwd().getSceneController().removePropertyChangeListener(this);
698701

699702
((Component) this.getWwd()).setCursor(null);
700703
}
@@ -846,6 +849,28 @@ else if (dragEvent.getTopPickedObject().getParentLayer() == this.getControlPoint
846849
}
847850
}
848851

852+
/**
853+
* The property change listener, the method called when a property of the Scene Controller changes
854+
* (vertical exaggeration, etc.). Does not necessarily indicate a property associated with this editor.
855+
*
856+
* @param event the property change event indicating the property name and its associated value.
857+
*/
858+
public void propertyChange(PropertyChangeEvent event)
859+
{
860+
if (event == null)
861+
{
862+
String msg = Logging.getMessage("nullValue.EventIsNull");
863+
Logging.logger().log(java.util.logging.Level.FINE, msg);
864+
throw new IllegalArgumentException(msg);
865+
}
866+
867+
if (event.getPropertyName().equals(AVKey.VERTICAL_EXAGGERATION))
868+
{
869+
// The orientation line altitudes depend on the vertical exaggeration.
870+
this.updateControlPoints();
871+
}
872+
}
873+
849874
/**
850875
* Creates the shape that will remain at the same location and is the same size as the shape to be edited.
851876
*/
@@ -1230,11 +1255,17 @@ protected void updateOrientationLine(Position centerPosition, Position controlPo
12301255
rotationLine.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND);
12311256
rotationLine.setFollowTerrain(true);
12321257

1233-
// Add a little altitude so that the line isn't lost during depth buffering.
1234-
cAltitude = 100 + centerPosition.getAltitude() - this.getWwd().getModel().getGlobe().getElevation(
1258+
// Set the line's altitude relative to the ground.
1259+
cAltitude = centerPosition.getAltitude() - this.getWwd().getModel().getGlobe().getElevation(
12351260
centerPosition.getLatitude(), centerPosition.getLongitude());
1236-
rAltitude = 100 + controlPoint.getAltitude() - this.getWwd().getModel().getGlobe().getElevation(
1261+
rAltitude = controlPoint.getAltitude() - this.getWwd().getModel().getGlobe().getElevation(
12371262
controlPoint.getLatitude(), controlPoint.getLongitude());
1263+
// Path does not incorporate vertical exaggeration, but airspace shapes do. Compensate for that difference here.
1264+
cAltitude *= this.getWwd().getSceneController().getVerticalExaggeration();
1265+
rAltitude *= this.getWwd().getSceneController().getVerticalExaggeration();
1266+
// Add a little altitude so that the line isn't lost during depth buffering.
1267+
cAltitude += 100;
1268+
rAltitude += 100;
12381269
}
12391270
else if (this.getShapeAltitudeMode() == WorldWind.CLAMP_TO_GROUND)
12401271
{

src/gov/nasa/worldwindx/examples/ShapeEditing.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
package gov.nasa.worldwindx.examples;
88

9-
import gov.nasa.worldwind.WorldWind;
9+
import gov.nasa.worldwind.*;
1010
import gov.nasa.worldwind.avlist.AVKey;
1111
import gov.nasa.worldwind.event.*;
1212
import gov.nasa.worldwind.geom.*;
@@ -123,7 +123,7 @@ public AppFrame()
123123
sphere.setAttributes(attrs);
124124
sphere.setHighlightAttributes(highlightAttrs);
125125
sphere.setAltitudeDatum(AVKey.ABOVE_GROUND_LEVEL, AVKey.ABOVE_GROUND_LEVEL);
126-
sphere.setAltitudes(1e4, 2e4);
126+
sphere.setAltitude(1.5e4);
127127
layer.addRenderable(sphere);
128128

129129
PartialCappedCylinder partialCylinder = new PartialCappedCylinder(LatLon.fromDegrees(40.5, -105), 5e4);
@@ -234,7 +234,7 @@ public void selected(SelectEvent event)
234234

235235
if (event.getEventAction().equals(SelectEvent.LEFT_CLICK))
236236
{
237-
if (topObject != null && topObject.getObject() instanceof Renderable)
237+
if (topObject != null && this.isEditableShape(topObject.getObject()))
238238
{
239239
if (this.editor == null)
240240
{
@@ -268,6 +268,11 @@ else if ((event.getMouseEvent().getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) =
268268
}
269269
}
270270

271+
protected boolean isEditableShape(Object object)
272+
{
273+
return object instanceof Airspace || object instanceof SurfaceShape;
274+
}
275+
271276
protected void keepShapeHighlighted(boolean tf)
272277
{
273278
if (tf)

0 commit comments

Comments
 (0)