Ticket #20680: 20680-2.patch

File 20680-2.patch, 4.6 KB (added by GerdP, 5 years ago)

when validating a selection check also the parent ways of modified nodes

  • actions/upload/ValidateUploadHook.java

     
    5454        if (tests.isEmpty())
    5555            return true;
    5656
    57         AggregatePrimitivesVisitor v = new AggregatePrimitivesVisitor();
     57        AggregatePrimitivesVisitor v = new AggregatePrimitivesVisitor(true);
    5858        v.visit(apiDataSet.getPrimitivesToAdd());
    5959        Collection<OsmPrimitive> selection = v.visit(apiDataSet.getPrimitivesToUpdate());
    6060
  • actions/ValidateAction.java

     
    7070                selection = getLayerManager().getActiveDataSet().allNonDeletedPrimitives();
    7171                lastSelection = null;
    7272            } else {
    73                 AggregatePrimitivesVisitor v = new AggregatePrimitivesVisitor();
     73                AggregatePrimitivesVisitor v = new AggregatePrimitivesVisitor(true);
    7474                selection = v.visit(selection);
    7575                lastSelection = selection;
    7676            }
  • data/validation/tests/CrossingWays.java

     
    1515import java.util.stream.Collectors;
    1616
    1717import org.openstreetmap.josm.data.coor.EastNorth;
     18import org.openstreetmap.josm.data.osm.DataSet;
     19import org.openstreetmap.josm.data.osm.OsmDataManager;
    1820import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1921import org.openstreetmap.josm.data.osm.OsmUtils;
    2022import org.openstreetmap.josm.data.osm.Relation;
     
    8082    private final Map<Point2D, List<WaySegment>> cellSegments = new HashMap<>(1000);
    8183    /** The already detected ways in error */
    8284    private final Map<List<Way>, List<WaySegment>> seenWays = new HashMap<>(50);
     85    protected boolean isSurroundingTest;
    8386
    8487    protected final int code;
    8588
     
    298301    @Override
    299302    public void startTest(ProgressMonitor monitor) {
    300303        super.startTest(monitor);
     304        isSurroundingTest = false;
    301305        cellSegments.clear();
    302306        seenWays.clear();
    303307    }
     
    304308
    305309    @Override
    306310    public void endTest() {
     311        // see #20680: if only a selection was tested, test it also against the other suitable ways
     312        if (partialSelection && !cellSegments.isEmpty() && !(this instanceof SelfCrossing)) {
     313            isSurroundingTest = true; // don't add more ways to the spatial index
     314            DataSet ds = OsmDataManager.getInstance().getActiveDataSet();
     315            for (Way w : ds.getWays()) {
     316                if (isPrimitiveUsable(w))
     317                    visit(w);
     318            }
     319        }
    307320        super.endTest();
    308321        cellSegments.clear();
    309322        seenWays.clear();
     
    390403                        highlight.add(es2);
    391404                    }
    392405                }
    393                 segments.add(es1);
     406                if (!isSurroundingTest)
     407                    segments.add(es1);
    394408            }
    395409        }
    396410    }
  • data/validation/util/AggregatePrimitivesVisitor.java

     
    2121public class AggregatePrimitivesVisitor implements OsmPrimitiveVisitor {
    2222    /** Aggregated data */
    2323    private final Collection<OsmPrimitive> aggregatedData = new HashSet<>();
     24    private final boolean collectParentWays;
    2425
    2526    /**
     27     * create new AggregatePrimitivesVisitor.
     28     */
     29    public AggregatePrimitivesVisitor() {
     30        this(false);
     31    }
     32
     33    /**
     34     * create new AggregatePrimitivesVisitor.
     35     * @param collectParentWays if true, parent ways of modified nodes are also collected
     36     */
     37    public AggregatePrimitivesVisitor(boolean collectParentWays) {
     38        this.collectParentWays = collectParentWays;
     39    }
     40
     41    /**
    2642     * Visits a collection of primitives
    2743     * @param data The collection of primitives
    2844     * @return The aggregated primitives
     
    4056        if (!aggregatedData.contains(n)) {
    4157            aggregatedData.add(n);
    4258        }
     59        if (collectParentWays && n.isModified()) {
     60            n.referrers(Way.class).filter(Way::isUsable).forEach(this::visit);
     61        }
    4362    }
    4463
    4564    @Override