source: josm/trunk/src/org/openstreetmap/josm/data/osm/FilterWorker.java@ 3414

Last change on this file since 3414 was 3371, checked in by jttt, 14 years ago

Fix #5018 DataIntegrityProblemException: Primitive must be part of the dataset

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1package org.openstreetmap.josm.data.osm;
2
3import java.util.Collection;
4
5/**
6 *
7 * @author Petr_Dlouhý
8 */
9public 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
36 // First relation and ways
37 for (OsmPrimitive primitive: all) {
38 if (!(primitive instanceof Node)) {
39 if (filterMatcher.isHidden(primitive)) {
40 primitive.setDisabledState(true);
41 } else if (filterMatcher.isDisabled(primitive)) {
42 primitive.setDisabledState(false);
43 } else {
44 primitive.unsetDisabledState();
45 }
46 }
47 }
48
49 // Then nodes (because they state may depend on parent ways)
50 for (OsmPrimitive primitive: all) {
51 if (primitive instanceof Node) {
52 if (filterMatcher.isHidden(primitive)) {
53 primitive.setDisabledState(true);
54 } else if (filterMatcher.isDisabled(primitive)) {
55 primitive.setDisabledState(false);
56 } else {
57 primitive.unsetDisabledState();
58 }
59 }
60 }
61 }
62
63 public static boolean executeFilters(OsmPrimitive primitive, FilterMatcher filterMatcher) {
64 boolean hidden = primitive.isDisabledAndHidden();
65 boolean disabled = primitive.isDisabled();
66 if (filterMatcher.isHidden(primitive)) {
67 primitive.setDisabledState(true);
68 } else if (filterMatcher.isDisabled(primitive)) {
69 primitive.setDisabledState(false);
70 } else {
71 primitive.unsetDisabledState();
72 }
73 return hidden != primitive.isDisabledAndHidden() || disabled != primitive.isDisabled();
74 }
75
76 public static void clearFilterFlags(Collection<OsmPrimitive> prims) {
77 for (OsmPrimitive osm : prims) {
78 osm.unsetDisabledState();
79 }
80 }
81}
Note: See TracBrowser for help on using the repository browser.