sartrackextensiontool.java

来自「world wind java sdk 源码」· Java 代码 · 共 521 行 · 第 1/2 页

JAVA
521
字号
    //**************************************************************//    //********************  Position Events  ***********************//    //**************************************************************//    public void moved(PositionEvent e)    {        if (e == null)        {            return;        }        if (!this.armed || this.wwd == null)        {            return;        }        if (this.waitingForNextPosition)        {            Position nextPosition = null;            PickedObject po = this.getTopPickedObject();            if (po != null)            {                Object id = po.getValue(AVKey.PICKED_OBJECT_ID);                if (id == SegmentPlane.PLANE_BACKGROUND ||                    (this.segmentPlane.isSnapToGrid() && id == SegmentPlane.PLANE_GRID))                {                    nextPosition = po.getPosition();                }            }            this.setPotentialNextPosition(nextPosition);        }    }    //**************************************************************//    //********************  Property Change Events  ****************//    //**************************************************************//    @SuppressWarnings({"StringEquality"})    public void propertyChange(PropertyChangeEvent e)    {        String propertyName = e.getPropertyName();        if (propertyName == SegmentPlane.SEGMENT_BEGIN || propertyName == SegmentPlane.SEGMENT_END)        {            if (propertyName == SegmentPlane.SEGMENT_BEGIN)            {                if (this.track.size() >= 3 && this.canInsertTrailingPoint)                {                    insertTrailingPoint();                    this.canInsertTrailingPoint = false;                }            }            snapTrackPointToPlanePoint(propertyName);        }        else if (propertyName == TrackController.TRACK_MODIFY || propertyName == TrackController.TRACK_OFFSET)        {            if (!this.ignoreTrackChangeEvents)            {                if (propertyName == TrackController.TRACK_MODIFY)                {                    this.snapPlaneToLastTrackPoint();                    this.canInsertTrailingPoint = true;                }                else                {                    this.snapPlaneToLastTrackSegment();                }            }        }    }    //**************************************************************//    //********************  Track/Plane Synchronization  ***********//    //**************************************************************//    @SuppressWarnings({"StringEquality"})    protected void snapTrackPointToPlanePoint(String planePoint)    {        if (this.track == null)            return;        if (this.track.size() == 0)            return;        if (this.waitingForNextPosition && planePoint == SegmentPlane.SEGMENT_END)            return;        Position[] segmentPositions = this.segmentPlane.getSegmentPositions();        this.ignoreTrackChangeEvents = true;        try        {            if (planePoint == SegmentPlane.SEGMENT_BEGIN)            {                int lastIndex = this.track.size() - 1;                SARPosition trackPosition = this.positionToTrackPosition(segmentPositions[0]);                this.track.set(lastIndex - 1, trackPosition);            }            else if (planePoint == SegmentPlane.SEGMENT_END)            {                int lastIndex = this.track.size() - 1;                SARPosition trackPosition = this.positionToTrackPosition(segmentPositions[1]);                this.track.set(lastIndex, trackPosition);            }        }        finally        {            this.ignoreTrackChangeEvents = false;        }    }    protected void snapPlaneToLastTrackPoint()    {        if (this.track == null)            return;        if (this.track.size() == 0)            return;        int lastIndex = this.track.size() - 1;        SARPosition lastTrackPosition = this.track.get(lastIndex);        SARPosition nextTrackPosition = this.computeNextTrackPosition();        if (nextTrackPosition == null)            nextTrackPosition = lastTrackPosition;        Position position1 = this.trackPositionToPosition(lastTrackPosition);        Position position2 = this.trackPositionToPosition(nextTrackPosition);        double[] altitudes = this.segmentPlane.computeAltitudesToFitPositions(Arrays.asList(position1, position2));        LatLon[] locations = this.segmentPlane.computeLocationsToFitPositions(position1, position2);                this.segmentPlane.setPlaneAltitudes(altitudes[0], altitudes[1]);        this.segmentPlane.setPlaneLocations(locations[0], locations[1]);        this.segmentPlane.setSegmentPositions(position1, position2);        this.showSegmentEndPoint(false);        this.wwd.redraw();    }    protected void snapPlaneToLastTrackSegment()    {        if (this.track == null)            return;        if (this.track.size() < 2)            return;        int lastIndex = this.track.size() - 1;        SARPosition lastTrackPosition = this.track.get(lastIndex - 1);        SARPosition nextTrackPosition = this.track.get(lastIndex);        Position position1 = this.trackPositionToPosition(lastTrackPosition);        Position position2 = this.trackPositionToPosition(nextTrackPosition);        double[] altitudes = this.segmentPlane.computeAltitudesToFitPositions(Arrays.asList(position1, position2));        LatLon[] locations = this.segmentPlane.computeLocationsToFitPositions(position1, position2);        this.segmentPlane.setPlaneAltitudes(altitudes[0], altitudes[1]);        this.segmentPlane.setPlaneLocations(locations[0], locations[1]);        this.segmentPlane.setSegmentPositions(position1, position2);        this.showSegmentEndPoint(true);        this.wwd.redraw();    }    protected void insertTrailingPoint()    {        if (this.track.size() < 3)            return;        int lastIndex = this.track.size() - 1;        SARPosition pos = this.track.get(lastIndex - 1);        this.track.add(lastIndex - 1, pos);    }        protected void showSegmentEndPoint(boolean show)    {        this.segmentPlane.setObjectVisible(SegmentPlane.SEGMENT_END, show, show);        this.segmentPlane.setObjectVisible(SegmentPlane.ALTIMETER, show, false);    }    //**************************************************************//    //********************  Utility Methods  ***********************//    //**************************************************************//    protected SARPosition computeNextTrackPosition(Point mousePoint)    {        View view = this.wwd.getView();        Line ray = view.computeRayFromScreenPoint(mousePoint.getX(), mousePoint.getY());        Position position = this.segmentPlane.getIntersectionPosition(ray);        return this.positionToTrackPosition(position);    }    protected SARPosition computeNextTrackPosition()    {        if (this.track.size() < 2)        {            return null;        }                Globe globe = this.wwd.getModel().getGlobe();        double[] gridDimensions = this.segmentPlane.getGridCellDimensions();        int lastIndex = this.track.size() - 1;        SARPosition lastPosition = this.track.get(lastIndex);        Vec4 point = globe.computePointFromPosition(lastPosition);        double size = this.segmentPlane.getObjectSize(SegmentPlane.SEGMENT_BEGIN, point);        double distance = Math.ceil(2 * size / gridDimensions[0]);        if (distance < 1)            distance = 1;        distance = distance * gridDimensions[0];        Angle heading = LatLon.rhumbAzimuth(this.track.get(lastIndex - 1), lastPosition);        Angle angularDistance = Angle.fromRadians(distance / globe.getRadius());        LatLon nextLocation = LatLon.rhumbEndPosition(lastPosition.getLatLon(), heading, angularDistance);        return new SARPosition(nextLocation.getLatitude(), nextLocation.getLongitude(), lastPosition.getElevation());    }    protected SARPosition positionToTrackPosition(Position position)    {        double trackOffset = this.track.getOffset();        return new SARPosition(position.getLatitude(), position.getLongitude(), position.getElevation() - trackOffset);    }    protected Position trackPositionToPosition(Position position)    {        double trackOffset = this.track.getOffset();        return new Position(position.getLatitude(), position.getLongitude(), position.getElevation() + trackOffset);    }    //**************************************************************//    //********************  Mouse Events  **************************//    //**************************************************************//    protected SegmentPlaneAttributes.GeometryAttributes createPotentialNextPositionGeomAttributes()    {        SegmentPlaneAttributes.GeometryAttributes geometryAttributes = new SegmentPlaneAttributes.GeometryAttributes(            Material.BLUE, 1.0);        geometryAttributes.setSize(8);        geometryAttributes.setPickSize(0);        return geometryAttributes;    }    protected SegmentPlaneAttributes.LabelAttributes createPotentialNextPositionLabelAttributes()    {        SARSegmentPlane.MessageLabelAttributes labelAttributes = new SARSegmentPlane.MessageLabelAttributes(            Color.WHITE, Font.decode("Arial-18"), AVKey.LEFT, AVKey.CENTER, "Click to add");        labelAttributes.setOffset(new Vec4(15, 0, 0));        return labelAttributes;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?