Changeset 8064 in josm for trunk/src/org


Ignore:
Timestamp:
2015-02-14T18:34:24+01:00 (10 years ago)
Author:
Don-vip
Message:

fix #11105 - DataIntegrityProblemException when undo drawing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r7668 r8064  
    177177        // update selection to reflect which way being modified
    178178        DataSet currentDataSet = getCurrentDataSet();
    179         if (currentBaseNode != null && currentDataSet != null && !currentDataSet.getSelected().isEmpty()) {
    180             Way continueFrom = getWayForNode(currentBaseNode);
    181             if (alt && continueFrom != null && (!currentBaseNode.isSelected() || continueFrom.isSelected())) {
    182                 addRemoveSelection(currentDataSet, currentBaseNode, continueFrom);
     179        if (getCurrentBaseNode() != null && currentDataSet != null && !currentDataSet.getSelected().isEmpty()) {
     180            Way continueFrom = getWayForNode(getCurrentBaseNode());
     181            if (alt && continueFrom != null && (!getCurrentBaseNode().isSelected() || continueFrom.isSelected())) {
     182                addRemoveSelection(currentDataSet, getCurrentBaseNode(), continueFrom);
    183183                needsRepaint = true;
    184184            } else if (!alt && continueFrom != null && !continueFrom.isSelected()) {
     
    211211        // isn't, set wayIsFinished to true to avoid superfluous repaints.
    212212        determineCurrentBaseNodeAndPreviousNode(getCurrentDataSet().getSelected());
    213         wayIsFinished = currentBaseNode == null;
     213        wayIsFinished = getCurrentBaseNode() == null;
    214214
    215215        toleranceMultiplier = 0.01 * NavigatableComponent.PROP_SNAP_DISTANCE.get();
     
    808808        }
    809809
    810         if (currentBaseNode == null || currentBaseNode == currentMouseNode)
     810        if (getCurrentBaseNode() == null || getCurrentBaseNode() == currentMouseNode)
    811811            return; // Don't create zero length way segments.
    812812
    813813
    814         double curHdg = Math.toDegrees(currentBaseNode.getEastNorth()
     814        double curHdg = Math.toDegrees(getCurrentBaseNode().getEastNorth()
    815815                .heading(currentMouseEastNorth));
    816816        double baseHdg=-1;
    817817        if (previousNode != null) {
    818818            baseHdg =  Math.toDegrees(previousNode.getEastNorth()
    819                     .heading(currentBaseNode.getEastNorth()));
     819                    .heading(getCurrentBaseNode().getEastNorth()));
    820820        }
    821821
     
    938938    }
    939939
     940    /**
     941     * Replies the current base node, after having checked it is still usable (see #11105).
     942     * @return the current base node (can be null). If not-null, it's guaranteed the node is usable
     943     */
    940944    public Node getCurrentBaseNode() {
     945        if (currentBaseNode != null && (currentBaseNode.getDataSet() == null || !currentBaseNode.isUsable())) {
     946            currentBaseNode = null;
     947        }
    941948        return currentBaseNode;
    942949    }
     
    10351042        EastNorth p1=ws.getFirstNode().getEastNorth();
    10361043        EastNorth p2=ws.getSecondNode().getEastNorth();
    1037         if (snapHelper.dir2!=null && currentBaseNode!=null) {
    1038             EastNorth xPoint = Geometry.getSegmentSegmentIntersection(p1, p2, snapHelper.dir2, currentBaseNode.getEastNorth());
     1044        if (snapHelper.dir2 != null && getCurrentBaseNode() != null) {
     1045            EastNorth xPoint = Geometry.getSegmentSegmentIntersection(p1, p2, snapHelper.dir2,
     1046                    getCurrentBaseNode().getEastNorth());
    10391047            if (xPoint!=null) {
    10401048                n.setEastNorth(xPoint);
     
    11021110        if (Main.map.mapView == null || mousePos == null
    11031111                // don't draw line if we don't know where from or where to
    1104                 || currentBaseNode == null || currentMouseEastNorth == null
     1112                || getCurrentBaseNode() == null || currentMouseEastNorth == null
    11051113                // don't draw line if mouse is outside window
    11061114                || !Main.map.mapView.getBounds().contains(mousePos))
     
    11181126            return;
    11191127        GeneralPath b = new GeneralPath();
    1120         Point p1=mv.getPoint(currentBaseNode);
     1128        Point p1=mv.getPoint(getCurrentBaseNode());
    11211129        Point p2=mv.getPoint(currentMouseEastNorth);
    11221130
     
    11751183         * Check whether a connection will be made
    11761184         */
    1177         if (currentBaseNode != null && !wayIsFinished) {
     1185        if (getCurrentBaseNode() != null && !wayIsFinished) {
    11781186            if (alt) {
    11791187                rv.append(" ").append(tr("Start new way from last node."));
     
    12251233        DataSet ds = getCurrentDataSet();
    12261234        if (ds == null) return null;
    1227         if (currentBaseNode != null && !ds.getSelected().isEmpty()) {
    1228             Way continueFrom = getWayForNode(currentBaseNode);
     1235        if (getCurrentBaseNode() != null && !ds.getSelected().isEmpty()) {
     1236            Way continueFrom = getWayForNode(getCurrentBaseNode());
    12291237            if (continueFrom != null)
    12301238                return Collections.<OsmPrimitive>singleton(continueFrom);
     
    13641372            if (!snapOn || !active)
    13651373                return;
    1366             Point p1=mv.getPoint(currentBaseNode);
     1374            Point p1=mv.getPoint(getCurrentBaseNode());
    13671375            Point p2=mv.getPoint(dir2);
    13681376            Point p3=mv.getPoint(projected);
     
    14231431         */
    14241432        public void checkAngleSnapping(EastNorth currentEN, double baseHeading, double curHeading) {
    1425             EastNorth p0 = currentBaseNode.getEastNorth();
     1433            EastNorth p0 = getCurrentBaseNode().getEastNorth();
    14261434            EastNorth snapPoint = currentEN;
    14271435            double angle = -1;
     
    14731481            // find out the distance, in metres, between the base point and projected point
    14741482            LatLon mouseLatLon = Main.map.mapView.getProjection().eastNorth2latlon(snapPoint);
    1475             double distance = currentBaseNode.getCoor().greatCircleDistance(mouseLatLon);
     1483            double distance = getCurrentBaseNode().getCoor().greatCircleDistance(mouseLatLon);
    14761484            double hdg = Math.toDegrees(p0.heading(snapPoint));
    14771485            // heading of segment from current to calculated point, not to mouse position
Note: See TracChangeset for help on using the changeset viewer.