- Timestamp:
- 2011-04-20T00:03:58+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java
r4005 r4040 36 36 private MapPainter painter; 37 37 private MapPaintSettings paintSettings; 38 private DataSet data; 39 38 39 private static int FLAG_NORMAL = 0; 40 private static int FLAG_DISABLED = 1; 41 private static int FLAG_SELECTED = 2; 42 private static int FLAG_MEMBER_OF_SELECTED = 4; 43 44 private static class StyleRecord implements Comparable<StyleRecord> { 45 final ElemStyle style; 46 final OsmPrimitive osm; 47 final int flags; 48 49 public StyleRecord(ElemStyle style, OsmPrimitive osm, int flags) { 50 this.style = style; 51 this.osm = osm; 52 this.flags = flags; 53 } 54 55 @Override 56 public int compareTo(StyleRecord other) { 57 if ((this.flags & FLAG_DISABLED) != 0 && (other.flags & FLAG_DISABLED) == 0) 58 return -1; 59 if ((this.flags & FLAG_DISABLED) == 0 && (other.flags & FLAG_DISABLED) != 0) 60 return 1; 61 float z_index1 = this.style.z_index; 62 if ((this.flags & FLAG_SELECTED) != 0) { 63 z_index1 += 700f; 64 } else if ((this.flags & FLAG_MEMBER_OF_SELECTED) != 0) { 65 z_index1 += 600f; 66 } 67 float z_index2 = other.style.z_index; 68 if ((other.flags & FLAG_SELECTED) != 0) { 69 z_index2 += 700f; 70 } else if ((other.flags & FLAG_MEMBER_OF_SELECTED) != 0) { 71 z_index2 += 600f; 72 } 73 74 int d1 = Float.compare(z_index1, z_index2); 75 if (d1 != 0) 76 return d1; 77 78 // simple node on top of icons and shapes 79 if (this.style == NodeElemStyle.SIMPLE_NODE_ELEMSTYLE && other.style != NodeElemStyle.SIMPLE_NODE_ELEMSTYLE) 80 return 1; 81 if (this.style != NodeElemStyle.SIMPLE_NODE_ELEMSTYLE && other.style == NodeElemStyle.SIMPLE_NODE_ELEMSTYLE) 82 return -1; 83 84 // newer primitives to the front 85 long id = this.osm.getUniqueId() - other.osm.getUniqueId(); 86 if (id > 0) 87 return 1; 88 if (id < 0) 89 return -1; 90 91 return Float.compare(this.style.object_z_index, other.style.object_z_index); 92 } 93 } 94 40 95 private class StyleCollector { 41 96 private final boolean drawArea; 42 97 private final boolean drawMultipolygon; 43 98 private final boolean drawRestriction; 44 private final boolean memberSelected; 45 46 private final List<Pair<ElemStyle, OsmPrimitive>> styleElems; 47 48 public StyleCollector(boolean drawArea, boolean drawMultipolygon, boolean drawRestriction, boolean memberSelected) { 99 100 private final List<StyleRecord> styleElems; 101 102 public StyleCollector(boolean drawArea, boolean drawMultipolygon, boolean drawRestriction) { 49 103 this.drawArea = drawArea; 50 104 this.drawMultipolygon = drawMultipolygon; 51 105 this.drawRestriction = drawRestriction; 52 this.memberSelected = memberSelected; 53 styleElems = new ArrayList<Pair<ElemStyle, OsmPrimitive>>(); 54 } 55 56 public void add(Node osm) { 106 styleElems = new ArrayList<StyleRecord>(); 107 } 108 109 public void add(Node osm, int flags) { 57 110 StyleList sl = styles.get(osm, circum, nc); 58 111 for (ElemStyle s : sl) { 59 styleElems.add(new Pair<ElemStyle, OsmPrimitive>(s, osm));60 } 61 } 62 63 public void add(Way osm ) {112 styleElems.add(new StyleRecord(s, osm, flags)); 113 } 114 } 115 116 public void add(Way osm, int flags) { 64 117 StyleList sl = styles.get(osm, circum, nc); 65 118 for (ElemStyle s : sl) { 66 if (! drawArea&& s instanceof AreaElemStyle) {119 if (!(drawArea && (flags & FLAG_DISABLED) == 0) && s instanceof AreaElemStyle) { 67 120 continue; 68 121 } 69 styleElems.add(new Pair<ElemStyle, OsmPrimitive>(s, osm));70 } 71 } 72 73 public void add(Relation osm ) {122 styleElems.add(new StyleRecord(s, osm, flags)); 123 } 124 } 125 126 public void add(Relation osm, int flags) { 74 127 StyleList sl = styles.get(osm, circum, nc); 75 128 for (ElemStyle s : sl) { 76 if (drawMultipolygon && drawArea && s instanceof AreaElemStyle ) {77 styleElems.add(new Pair<ElemStyle, OsmPrimitive>(s, osm));129 if (drawMultipolygon && drawArea && s instanceof AreaElemStyle && (flags & FLAG_DISABLED) == 0) { 130 styleElems.add(new StyleRecord(s, osm, flags)); 78 131 } else if (drawRestriction && s instanceof NodeElemStyle) { 79 styleElems.add(new Pair<ElemStyle, OsmPrimitive>(s, osm));132 styleElems.add(new StyleRecord(s, osm, flags)); 80 133 } 81 134 } … … 83 136 84 137 public void drawAll() { 85 Collections.sort(styleElems, STYLE_COMPARATOR); 86 for (Pair<ElemStyle, OsmPrimitive> p : styleElems) { 87 p.a.paintPrimitive(p.b, paintSettings, painter, data.isSelected(p.b), memberSelected); 88 } 89 } 90 } 91 92 private final static Comparator<Pair<ElemStyle, OsmPrimitive>> STYLE_COMPARATOR = new Comparator<Pair<ElemStyle, OsmPrimitive>>() { 93 @Override 94 public int compare(Pair<ElemStyle, OsmPrimitive> p1, Pair<ElemStyle, OsmPrimitive> p2) { 95 int d1 = Float.compare(p1.a.z_index, p2.a.z_index); 96 if (d1 != 0) 97 return d1; 98 if (p1.a == NodeElemStyle.SIMPLE_NODE_ELEMSTYLE && p2.a != NodeElemStyle.SIMPLE_NODE_ELEMSTYLE) 99 return 1; 100 if (p1.a != NodeElemStyle.SIMPLE_NODE_ELEMSTYLE && p2.a == NodeElemStyle.SIMPLE_NODE_ELEMSTYLE) 101 return -1; 102 // newer primitives to the front 103 long id = p1.b.getUniqueId() - p2.b.getUniqueId(); 104 if (id > 0) 105 return 1; 106 if (id < 0) 107 return -1; 108 return Float.compare(p1.a.object_z_index, p2.a.object_z_index); 109 } 110 }; 138 Collections.sort(styleElems); 139 for (StyleRecord r : styleElems) { 140 r.style.paintPrimitive( 141 r.osm, 142 paintSettings, 143 painter, 144 (r.flags & FLAG_SELECTED) != 0, 145 (r.flags & FLAG_MEMBER_OF_SELECTED) != 0 146 ); 147 } 148 } 149 } 111 150 112 151 public void visitAll(final DataSet data, boolean virtual, Bounds bounds) { 113 152 //long start = System.currentTimeMillis(); 114 153 BBox bbox = new BBox(bounds); 115 this.data = data;116 154 117 155 styles = MapPaintStyles.getStyles(); … … 132 170 this.painter = new MapPainter(paintSettings, g, inactive, nc, virtual, circum, leftHandTraffic); 133 171 134 StyleCollector scDisabledPrimitives = new StyleCollector(false, false, drawRestriction, false); 135 StyleCollector scSelectedPrimitives = new StyleCollector(drawArea, drawMultipolygon, drawRestriction, false); 136 StyleCollector scMemberPrimitives = new StyleCollector(drawArea, drawMultipolygon, drawRestriction, true); 137 StyleCollector scNormalPrimitives = new StyleCollector(drawArea, drawMultipolygon, drawRestriction, false); 172 StyleCollector sc = new StyleCollector(drawArea, drawMultipolygon, drawRestriction); 138 173 139 174 for (final Node n: data.searchNodes(bbox)) { 140 175 if (n.isDrawable()) { 141 176 if (n.isDisabled()) { 142 sc DisabledPrimitives.add(n);143 } else if ( n.isSelected()) {144 sc SelectedPrimitives.add(n);177 sc.add(n, FLAG_DISABLED); 178 } else if (data.isSelected(n)) { 179 sc.add(n, FLAG_SELECTED); 145 180 } else if (n.isMemberOfSelected()) { 146 sc MemberPrimitives.add(n);181 sc.add(n, FLAG_MEMBER_OF_SELECTED); 147 182 } else { 148 sc NormalPrimitives.add(n);183 sc.add(n, FLAG_NORMAL); 149 184 } 150 185 } … … 153 188 if (w.isDrawable()) { 154 189 if (w.isDisabled()) { 155 sc DisabledPrimitives.add(w);156 } else if ( w.isSelected()) {157 sc SelectedPrimitives.add(w);190 sc.add(w, FLAG_DISABLED); 191 } else if (data.isSelected(w)) { 192 sc.add(w, FLAG_SELECTED); 158 193 } else if (w.isMemberOfSelected()) { 159 sc MemberPrimitives.add(w);194 sc.add(w, FLAG_MEMBER_OF_SELECTED); 160 195 } else { 161 sc NormalPrimitives.add(w);196 sc.add(w, FLAG_NORMAL); 162 197 } 163 198 } … … 166 201 if (r.isDrawable()) { 167 202 if (r.isDisabled()) { 168 sc DisabledPrimitives.add(r);169 } else if ( r.isSelected()) {170 sc SelectedPrimitives.add(r);203 sc.add(r, FLAG_DISABLED); 204 } else if (data.isSelected(r)) { 205 sc.add(r, FLAG_SELECTED); 171 206 } else { 172 sc NormalPrimitives.add(r);207 sc.add(r, FLAG_NORMAL); 173 208 } 174 209 } … … 177 212 //long phase1 = System.currentTimeMillis(); 178 213 179 scDisabledPrimitives.drawAll(); 180 scDisabledPrimitives = null; 181 scNormalPrimitives.drawAll(); 182 scNormalPrimitives = null; 183 scMemberPrimitives.drawAll(); 184 scMemberPrimitives = null; 185 scSelectedPrimitives.drawAll(); 186 scSelectedPrimitives = null; 214 sc.drawAll(); 215 sc = null; 187 216 188 217 painter.drawVirtualNodes(data.searchWays(bbox)); -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java
r4006 r4040 33 33 } 34 34 35 /** 36 * draws a primitive 37 * @param primitive 38 * @param paintSettings 39 * @param painter 40 * @param selected true, if primitive is selected 41 * @param member true, if primitive is not selected and member of a selected relation 42 */ 35 43 public abstract void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected, boolean member); 36 44
Note:
See TracChangeset
for help on using the changeset viewer.