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