Changeset 4040 in josm for trunk/src


Ignore:
Timestamp:
2011-04-20T00:03:58+02:00 (13 years ago)
Author:
bastiK
Message:

fixed #6210 - Selected a way rendered on top of unselected nodes

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  
    3636    private MapPainter painter;
    3737    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   
    4095    private class StyleCollector {
    4196        private final boolean drawArea;
    4297        private final boolean drawMultipolygon;
    4398        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) {
    49103            this.drawArea = drawArea;
    50104            this.drawMultipolygon = drawMultipolygon;
    51105            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) {
    57110            StyleList sl = styles.get(osm, circum, nc);
    58111            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) {
    64117            StyleList sl = styles.get(osm, circum, nc);
    65118            for (ElemStyle s : sl) {
    66                 if (!drawArea && s instanceof AreaElemStyle) {
     119                if (!(drawArea && (flags & FLAG_DISABLED) == 0) && s instanceof AreaElemStyle) {
    67120                    continue;
    68121                }
    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) {
    74127            StyleList sl = styles.get(osm, circum, nc);
    75128            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));
    78131                } else if (drawRestriction && s instanceof NodeElemStyle) {
    79                     styleElems.add(new Pair<ElemStyle, OsmPrimitive>(s, osm));
     132                    styleElems.add(new StyleRecord(s, osm, flags));
    80133                }
    81134            }
     
    83136
    84137        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    }
    111150
    112151    public void visitAll(final DataSet data, boolean virtual, Bounds bounds) {
    113152        //long start = System.currentTimeMillis();
    114153        BBox bbox = new BBox(bounds);
    115         this.data = data;
    116154
    117155        styles = MapPaintStyles.getStyles();
     
    132170        this.painter = new MapPainter(paintSettings, g, inactive, nc, virtual, circum, leftHandTraffic);
    133171
    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);
    138173
    139174        for (final Node n: data.searchNodes(bbox)) {
    140175            if (n.isDrawable()) {
    141176                if (n.isDisabled()) {
    142                     scDisabledPrimitives.add(n);
    143                 } else if (n.isSelected()) {
    144                     scSelectedPrimitives.add(n);
     177                    sc.add(n, FLAG_DISABLED);
     178                } else if (data.isSelected(n)) {
     179                    sc.add(n, FLAG_SELECTED);
    145180                } else if (n.isMemberOfSelected()) {
    146                     scMemberPrimitives.add(n);
     181                    sc.add(n, FLAG_MEMBER_OF_SELECTED);
    147182                } else {
    148                     scNormalPrimitives.add(n);
     183                    sc.add(n, FLAG_NORMAL);
    149184                }
    150185            }
     
    153188            if (w.isDrawable()) {
    154189                if (w.isDisabled()) {
    155                     scDisabledPrimitives.add(w);
    156                 } else if (w.isSelected()) {
    157                     scSelectedPrimitives.add(w);
     190                    sc.add(w, FLAG_DISABLED);
     191                } else if (data.isSelected(w)) {
     192                    sc.add(w, FLAG_SELECTED);
    158193                } else if (w.isMemberOfSelected()) {
    159                     scMemberPrimitives.add(w);
     194                    sc.add(w, FLAG_MEMBER_OF_SELECTED);
    160195                } else {
    161                     scNormalPrimitives.add(w);
     196                    sc.add(w, FLAG_NORMAL);
    162197                }
    163198            }
     
    166201            if (r.isDrawable()) {
    167202                if (r.isDisabled()) {
    168                     scDisabledPrimitives.add(r);
    169                 } else if (r.isSelected()) {
    170                     scSelectedPrimitives.add(r);
     203                    sc.add(r, FLAG_DISABLED);
     204                } else if (data.isSelected(r)) {
     205                    sc.add(r, FLAG_SELECTED);
    171206                } else {
    172                     scNormalPrimitives.add(r);
     207                    sc.add(r, FLAG_NORMAL);
    173208                }
    174209            }
     
    177212        //long phase1 = System.currentTimeMillis();
    178213
    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;
    187216
    188217        painter.drawVirtualNodes(data.searchWays(bbox));
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java

    r4006 r4040  
    3333    }
    3434
     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     */
    3543    public abstract void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected, boolean member);
    3644
Note: See TracChangeset for help on using the changeset viewer.