| 1 | // License: GPL. See LICENSE file for details.
|
|---|
| 2 | package org.openstreetmap.josm.data.validation.tests;
|
|---|
| 3 |
|
|---|
| 4 | import static org.openstreetmap.josm.tools.I18n.marktr;
|
|---|
| 5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 6 |
|
|---|
| 7 | import java.text.MessageFormat;
|
|---|
| 8 | import java.util.ArrayList;
|
|---|
| 9 | import java.util.List;
|
|---|
| 10 |
|
|---|
| 11 | import org.openstreetmap.josm.data.osm.Node;
|
|---|
| 12 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
|---|
| 13 | import org.openstreetmap.josm.data.osm.OsmUtils;
|
|---|
| 14 | import org.openstreetmap.josm.data.osm.Relation;
|
|---|
| 15 | import org.openstreetmap.josm.data.osm.Way;
|
|---|
| 16 | import org.openstreetmap.josm.data.validation.Severity;
|
|---|
| 17 | import org.openstreetmap.josm.data.validation.Test;
|
|---|
| 18 | import org.openstreetmap.josm.data.validation.TestError;
|
|---|
| 19 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
|---|
| 20 |
|
|---|
| 21 | /**
|
|---|
| 22 | * Check area type ways for errors
|
|---|
| 23 | *
|
|---|
| 24 | * @author stoecker
|
|---|
| 25 | */
|
|---|
| 26 | public class UnclosedWays extends Test {
|
|---|
| 27 |
|
|---|
| 28 | /**
|
|---|
| 29 | * Constructor
|
|---|
| 30 | */
|
|---|
| 31 | public UnclosedWays() {
|
|---|
| 32 | super(tr("Unclosed Ways."), tr("This tests if ways which should be circular are closed."));
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | @Override
|
|---|
| 36 | public void startTest(ProgressMonitor monitor) {
|
|---|
| 37 | super.startTest(monitor);
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | @Override
|
|---|
| 41 | public void endTest() {
|
|---|
| 42 | super.endTest();
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | private String type;
|
|---|
| 46 | private String etype;
|
|---|
| 47 | private int mode;
|
|---|
| 48 |
|
|---|
| 49 | public void set(int m, String text, String desc) {
|
|---|
| 50 | etype = MessageFormat.format(text, desc);
|
|---|
| 51 | type = tr(text, tr(desc));
|
|---|
| 52 | mode = m;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | public void set(int m, String text) {
|
|---|
| 56 | etype = text;
|
|---|
| 57 | type = tr(text);
|
|---|
| 58 | mode = m;
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | @Override
|
|---|
| 62 | public void visit(Way w) {
|
|---|
| 63 | String test;
|
|---|
| 64 | type = etype = null;
|
|---|
| 65 | mode = 0;
|
|---|
| 66 |
|
|---|
| 67 | if (!w.isUsable())
|
|---|
| 68 | return;
|
|---|
| 69 |
|
|---|
| 70 | test = w.get("natural");
|
|---|
| 71 | if (test != null && !"coastline".equals(test) && !"cliff".equals(test)) {
|
|---|
| 72 | set(1101, marktr("natural type {0}"), test);
|
|---|
| 73 | }
|
|---|
| 74 | test = w.get("landuse");
|
|---|
| 75 | if (test != null) {
|
|---|
| 76 | set(1102, marktr("landuse type {0}"), test);
|
|---|
| 77 | }
|
|---|
| 78 | test = w.get("amenities");
|
|---|
| 79 | if (test != null) {
|
|---|
| 80 | set(1103, marktr("amenities type {0}"), test);
|
|---|
| 81 | }
|
|---|
| 82 | test = w.get("sport");
|
|---|
| 83 | if (test != null && !test.equals("water_slide")) {
|
|---|
| 84 | set(1104, marktr("sport type {0}"), test);
|
|---|
| 85 | }
|
|---|
| 86 | test = w.get("tourism");
|
|---|
| 87 | if (test != null) {
|
|---|
| 88 | set(1105, marktr("tourism type {0}"), test);
|
|---|
| 89 | }
|
|---|
| 90 | test = w.get("shop");
|
|---|
| 91 | if (test != null) {
|
|---|
| 92 | set(1106, marktr("shop type {0}"), test);
|
|---|
| 93 | }
|
|---|
| 94 | test = w.get("leisure");
|
|---|
| 95 | if (test != null) {
|
|---|
| 96 | set(1107, marktr("leisure type {0}"), test);
|
|---|
| 97 | }
|
|---|
| 98 | test = w.get("waterway");
|
|---|
| 99 | if (test != null && test.equals("riverbank")) {
|
|---|
| 100 | set(1108, marktr("waterway type {0}"), test);
|
|---|
| 101 | }
|
|---|
| 102 | Boolean btest = OsmUtils.getOsmBoolean(w.get("building"));
|
|---|
| 103 | if (btest != null && btest) {
|
|---|
| 104 | set(1120, marktr("building"));
|
|---|
| 105 | }
|
|---|
| 106 | btest = OsmUtils.getOsmBoolean(w.get("area"));
|
|---|
| 107 | if (btest != null && btest) {
|
|---|
| 108 | set(1130, marktr("area"));
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | if (type != null && !w.isClosed()) {
|
|---|
| 112 | for (OsmPrimitive parent: w.getReferrers()) {
|
|---|
| 113 | if (parent instanceof Relation && ((Relation)parent).isMultipolygon())
|
|---|
| 114 | return;
|
|---|
| 115 | }
|
|---|
| 116 | Node f = w.firstNode();
|
|---|
| 117 | Node l = w.lastNode();
|
|---|
| 118 |
|
|---|
| 119 | List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>();
|
|---|
| 120 | List<OsmPrimitive> highlight = new ArrayList<OsmPrimitive>();
|
|---|
| 121 | primitives.add(w);
|
|---|
| 122 |
|
|---|
| 123 | // The important parts of an unclosed way are the first and
|
|---|
| 124 | // the last node which should be connected, therefore we highlight them
|
|---|
| 125 | highlight.add(f);
|
|---|
| 126 | highlight.add(l);
|
|---|
| 127 |
|
|---|
| 128 | errors.add(new TestError(this, Severity.WARNING, tr("Unclosed way"),
|
|---|
| 129 | type, etype, mode, primitives, highlight));
|
|---|
| 130 | }
|
|---|
| 131 | }
|
|---|
| 132 | }
|
|---|