1 | package org.openstreetmap.josm.data.osm;
|
---|
2 |
|
---|
3 | import java.util.Collection;
|
---|
4 |
|
---|
5 | /**
|
---|
6 | *
|
---|
7 | * @author Petr_Dlouhý
|
---|
8 | */
|
---|
9 | public class FilterWorker {
|
---|
10 | /**
|
---|
11 | * Apply the filters to the primitives of the data set.
|
---|
12 | *
|
---|
13 | * There are certain rules to ensure that a way is not displayed "naked"
|
---|
14 | * without its nodes (1) and on the other hand to avoid hiding a way but
|
---|
15 | * leaving its nodes visible as a cloud of points (2).
|
---|
16 | *
|
---|
17 | * In normal (non-inverted) mode only problem (2) is relevant.
|
---|
18 | * Untagged child nodes of filtered ways that are not used by other
|
---|
19 | * unfiltered ways are filtered as well.
|
---|
20 | *
|
---|
21 | * If a filter applies explicitly to a node, (2) is ignored and it
|
---|
22 | * is filtered in any case.
|
---|
23 | *
|
---|
24 | * In inverted mode usually only problem (1) is relevant.
|
---|
25 | * If the inverted filter applies explicitly to a node, this no longer
|
---|
26 | * means it is filtered in any case:
|
---|
27 | * E.g. the filter [searchtext="highway=footway", inverted=true] displays
|
---|
28 | * the footways only. But that does not mean, the nodes of the footway
|
---|
29 | * (which do not have the highway tag) should be filtered as well.
|
---|
30 | *
|
---|
31 | * So first the Filter is applied for ways and relations. Then to nodes
|
---|
32 | * (but hides them only if they are not used by any unfiltered way).
|
---|
33 | */
|
---|
34 | public static void executeFilters(Collection<OsmPrimitive> all, FilterMatcher filterMatcher) {
|
---|
35 | for (OsmPrimitive primitive: all) {
|
---|
36 | if (filterMatcher.isHidden(primitive)) {
|
---|
37 | primitive.setDisabledState(true);
|
---|
38 | } else if (filterMatcher.isDisabled(primitive)) {
|
---|
39 | primitive.setDisabledState(false);
|
---|
40 | } else {
|
---|
41 | primitive.unsetDisabledState();
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | for (OsmPrimitive primitive: all) {
|
---|
46 | if (primitive instanceof Way && primitive.isDisabled()) {
|
---|
47 | Way w = (Way)primitive;
|
---|
48 | for (Node n: w.getNodes()) {
|
---|
49 |
|
---|
50 | if (n.isTagged()) {
|
---|
51 | continue;
|
---|
52 | }
|
---|
53 |
|
---|
54 | boolean disabled = w.isDisabled();
|
---|
55 | boolean hidden = w.isDisabledAndHidden();
|
---|
56 | for (OsmPrimitive ref: n.getReferrers()) {
|
---|
57 | if (ref instanceof Way) {
|
---|
58 | disabled = disabled && ref.isDisabled();
|
---|
59 | hidden = hidden && ref.isDisabledAndHidden();
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | if (disabled) {
|
---|
64 | n.setDisabledState(hidden);
|
---|
65 | }
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | public static void clearFilterFlags(Collection<OsmPrimitive> prims) {
|
---|
72 | for (OsmPrimitive osm : prims) {
|
---|
73 | osm.unsetDisabledState();
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|