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 | 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 | test = w.get("landuse");
|
---|
79 | if (test != null)
|
---|
80 | set(1102, marktr("landuse type {0}"), test);
|
---|
81 | test = w.get("amenities");
|
---|
82 | if (test != null)
|
---|
83 | set(1103, marktr("amenities type {0}"), test);
|
---|
84 | test = w.get("sport");
|
---|
85 | if (test != null && !test.equals("water_slide"))
|
---|
86 | set(1104, marktr("sport type {0}"), test);
|
---|
87 | test = w.get("tourism");
|
---|
88 | if (test != null)
|
---|
89 | set(1105, marktr("tourism type {0}"), test);
|
---|
90 | test = w.get("shop");
|
---|
91 | if (test != null)
|
---|
92 | set(1106, marktr("shop type {0}"), test);
|
---|
93 | test = w.get("leisure");
|
---|
94 | if (test != null)
|
---|
95 | set(1107, marktr("leisure type {0}"), test);
|
---|
96 | test = w.get("waterway");
|
---|
97 | if (test != null && test.equals("riverbank"))
|
---|
98 | set(1108, marktr("waterway type {0}"), test);
|
---|
99 | Boolean btest = OsmUtils.getOsmBoolean(w.get("building"));
|
---|
100 | if (btest != null && btest)
|
---|
101 | set(1120, marktr("building"));
|
---|
102 | btest = OsmUtils.getOsmBoolean(w.get("area"));
|
---|
103 | if (btest != null && btest)
|
---|
104 | set(1130, marktr("area"));
|
---|
105 |
|
---|
106 | if (type != null && !w.isClosed()) {
|
---|
107 | for (OsmPrimitive parent: w.getReferrers()) {
|
---|
108 | if (parent instanceof Relation && "multipolygon".equals(parent.get("type")))
|
---|
109 | return;
|
---|
110 | }
|
---|
111 | Node f = w.firstNode();
|
---|
112 | Node l = w.lastNode();
|
---|
113 |
|
---|
114 | List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>();
|
---|
115 | List<OsmPrimitive> highlight = new ArrayList<OsmPrimitive>();
|
---|
116 | primitives.add(w);
|
---|
117 |
|
---|
118 | // The important parts of an unclosed way are the first and
|
---|
119 | // the last node which should be connected, therefore we highlight them
|
---|
120 | highlight.add(f);
|
---|
121 | highlight.add(l);
|
---|
122 |
|
---|
123 | errors.add(new TestError(this, Severity.WARNING, tr("Unclosed way"),
|
---|
124 | type, etype, mode, primitives, highlight));
|
---|
125 | _errorWays.add(w, w);
|
---|
126 | }
|
---|
127 | }
|
---|
128 | }
|
---|