Changeset 4005 in josm


Ignore:
Timestamp:
Mar 26, 2011 6:50:33 PM (2 years ago)
Author:
bastiK
Message:

mapcss: MapPaintVisitor rework (more flexibility with z-index)

Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java

    r3964 r4005  
    2121import org.openstreetmap.josm.gui.mappaint.ElemStyle; 
    2222import org.openstreetmap.josm.gui.mappaint.ElemStyles; 
    23 import org.openstreetmap.josm.gui.mappaint.LineElemStyle; 
    2423import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 
    2524import org.openstreetmap.josm.gui.mappaint.NodeElemStyle; 
     
    4039 
    4140    private class StyleCollector { 
    42         private List<Pair<ElemStyle, OsmPrimitive>> styleElems; 
    43         protected boolean memberSelected = false; 
    44         private Class klass; 
    45  
    46         public StyleCollector(Class<?> klass) { 
     41        private final boolean drawArea; 
     42        private final boolean drawMultipolygon; 
     43        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) { 
     49            this.drawArea = drawArea; 
     50            this.drawMultipolygon = drawMultipolygon; 
     51            this.drawRestriction = drawRestriction; 
     52            this.memberSelected = memberSelected; 
    4753            styleElems = new ArrayList<Pair<ElemStyle, OsmPrimitive>>(); 
    48             this.klass = klass; 
    49         } 
    50  
    51         public void add(OsmPrimitive osm) { 
     54        } 
     55 
     56        public void add(Node osm) { 
    5257            StyleList sl = styles.get(osm, circum, nc); 
    5358            for (ElemStyle s : sl) { 
    54                 if (klass.isInstance(s)) { 
     59                styleElems.add(new Pair<ElemStyle, OsmPrimitive>(s, osm)); 
     60            } 
     61        } 
     62 
     63        public void add(Way osm) { 
     64            StyleList sl = styles.get(osm, circum, nc); 
     65            for (ElemStyle s : sl) { 
     66                if (!drawArea && s instanceof AreaElemStyle) { 
     67                    continue; 
     68                } 
     69                styleElems.add(new Pair<ElemStyle, OsmPrimitive>(s, osm)); 
     70            } 
     71        } 
     72 
     73        public void add(Relation osm) { 
     74            StyleList sl = styles.get(osm, circum, nc); 
     75            for (ElemStyle s : sl) { 
     76                if (drawMultipolygon && drawArea && s instanceof AreaElemStyle) { 
     77                    styleElems.add(new Pair<ElemStyle, OsmPrimitive>(s, osm)); 
     78                } else if (drawRestriction && s instanceof NodeElemStyle) { 
    5579                    styleElems.add(new Pair<ElemStyle, OsmPrimitive>(s, osm)); 
    5680                } 
     
    6387                p.a.paintPrimitive(p.b, paintSettings, painter, data.isSelected(p.b), memberSelected); 
    6488            } 
    65         } 
    66  
    67         public boolean isMemberSelected() { 
    68             return memberSelected; 
    69         } 
    70  
    71         public void setMemberSelected(boolean memberSelected) { 
    72             this.memberSelected = memberSelected; 
    7389        } 
    7490    } 
     
    116132        this.painter = new MapPainter(paintSettings, g, inactive, nc, virtual, circum, leftHandTraffic); 
    117133 
    118         StyleCollector scDisabledLines = new StyleCollector(LineElemStyle.class); 
    119         StyleCollector scSelectedLines = new StyleCollector(LineElemStyle.class); 
    120         StyleCollector scSelectedAreas = new StyleCollector(AreaElemStyle.class); 
    121         StyleCollector scMemberLines = new StyleCollector(LineElemStyle.class); 
    122         scMemberLines.setMemberSelected(true); 
    123         StyleCollector scNormalAreas = new StyleCollector(AreaElemStyle.class); 
    124         StyleCollector scNormalLines = new StyleCollector(LineElemStyle.class); 
     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); 
     138 
     139        for (final Node n: data.searchNodes(bbox)) { 
     140            if (n.isDrawable()) { 
     141                if (n.isDisabled()) { 
     142                    scDisabledPrimitives.add(n); 
     143                } else if (n.isSelected()) { 
     144                    scSelectedPrimitives.add(n); 
     145                } else if (n.isMemberOfSelected()) { 
     146                    scMemberPrimitives.add(n); 
     147                } else { 
     148                    scNormalPrimitives.add(n); 
     149                } 
     150            } 
     151        } 
    125152        for (final Way w : data.searchWays(bbox)) { 
    126153            if (w.isDrawable()) { 
    127154                if (w.isDisabled()) { 
    128                     scDisabledLines.add(w); 
     155                    scDisabledPrimitives.add(w); 
    129156                } else if (w.isSelected()) { 
    130                     scSelectedLines.add(w); 
    131                     if (drawArea) { 
    132                         scSelectedAreas.add(w); 
    133                     } 
     157                    scSelectedPrimitives.add(w); 
    134158                } else if (w.isMemberOfSelected()) { 
    135                     scMemberLines.add(w); 
    136                     if (drawArea) { 
    137                         scNormalAreas.add(w); 
    138                     } 
     159                    scMemberPrimitives.add(w); 
    139160                } else { 
    140                     scNormalLines.add(w); 
    141                     if (drawArea) { 
    142                         scNormalAreas.add(w); 
    143                     } 
    144                 } 
    145             } 
    146         } 
    147         scDisabledLines.drawAll(); 
    148         scDisabledLines = null; 
    149  
    150         StyleCollector scDisabledNodes = new StyleCollector(NodeElemStyle.class); 
    151         StyleCollector scSelectedNodes = new StyleCollector(NodeElemStyle.class); 
    152         StyleCollector scMemberNodes = new StyleCollector(NodeElemStyle.class); 
    153         scMemberNodes.setMemberSelected(true); 
    154         StyleCollector scNormalNodes = new StyleCollector(NodeElemStyle.class); 
    155         for (final Node n: data.searchNodes(bbox)) { 
    156             if (n.isDrawable()) { 
    157                 if (n.isDisabled()) { 
    158                     scDisabledNodes.add(n); 
    159                 } else if (n.isSelected()) { 
    160                     scSelectedNodes.add(n); 
    161                 } else if (n.isMemberOfSelected()) { 
    162                     scMemberNodes.add(n); 
    163                 } else { 
    164                     scNormalNodes.add(n); 
    165                 } 
    166             } 
    167         } 
    168         scDisabledNodes.drawAll(); 
    169         scDisabledNodes = null; 
    170  
    171         StyleCollector scDisabledRestrictions = new StyleCollector(NodeElemStyle.class); 
    172         StyleCollector scNormalRestrictions = new StyleCollector(NodeElemStyle.class); 
    173         StyleCollector scSelectedRestrictions = new StyleCollector(NodeElemStyle.class); 
     161                    scNormalPrimitives.add(w); 
     162                } 
     163            } 
     164        } 
    174165        for (Relation r: data.searchRelations(bbox)) { 
    175166            if (r.isDrawable()) { 
    176167                if (r.isDisabled()) { 
    177                     if (drawRestriction) { 
    178                         scDisabledRestrictions.add(r); 
    179                     } 
     168                    scDisabledPrimitives.add(r); 
    180169                } else if (r.isSelected()) { 
    181                     if (drawMultipolygon) { 
    182                         scSelectedAreas.add(r); 
    183                     } 
    184                     if (drawRestriction) { 
    185                         scSelectedRestrictions.add(r); 
    186                     } 
     170                    scSelectedPrimitives.add(r); 
    187171                } else { 
    188                     if (drawMultipolygon) { 
    189                         scNormalAreas.add(r); 
    190                     } 
    191                     if (drawRestriction) { 
    192                         scNormalRestrictions.add(r); 
    193                     } 
    194                 } 
    195             } 
    196         } 
    197         scDisabledRestrictions.drawAll(); 
    198         scDisabledRestrictions = null; 
    199  
    200         scNormalAreas.drawAll(); 
    201         scSelectedAreas.drawAll(); 
    202         scNormalLines.drawAll(); 
    203         scMemberLines.drawAll(); 
    204         scSelectedLines.drawAll(); 
    205         scNormalNodes.drawAll(); 
    206         scNormalRestrictions.drawAll(); 
    207         scMemberNodes.drawAll(); 
    208         scSelectedRestrictions.drawAll(); 
    209         scSelectedNodes.drawAll(); 
     172                    scNormalPrimitives.add(r); 
     173                } 
     174            } 
     175        } 
     176 
     177        //long phase1 = System.currentTimeMillis(); 
     178 
     179        scDisabledPrimitives.drawAll(); 
     180        scDisabledPrimitives = null; 
     181        scNormalPrimitives.drawAll(); 
     182        scNormalPrimitives = null; 
     183        scMemberPrimitives.drawAll(); 
     184        scMemberPrimitives = null; 
     185        scSelectedPrimitives.drawAll(); 
     186        scSelectedPrimitives = null; 
    210187 
    211188        painter.drawVirtualNodes(data.searchWays(bbox)); 
    212         //System.err.println("PAINTING TOOK "+(System.currentTimeMillis() - start)+ " (at scale "+circum+")"); 
     189         
     190        //long now = System.currentTimeMillis(); 
     191        //System.err.println(String.format("PAINTING TOOK %d [PHASE1 took %d] (at scale %s)", now - start, phase1 - start, circum)); 
    213192    } 
    214193 
  • trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java

    r3992 r4005  
    3030 
    3131    protected AreaElemStyle(Cascade c, Color color, BufferedImage fillImage, float fillImageAlpha, TextElement text) { 
    32         super(c); 
     32        super(c, -1000f); 
    3333        CheckParameterUtil.ensureParameterNotNull(color); 
    3434        this.color = color; 
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java

    r3987 r4005  
    2727    } 
    2828 
    29     protected ElemStyle(Cascade c) { 
    30         z_index = c.get("z-index", 0f, Float.class); 
     29    protected ElemStyle(Cascade c, float default_z_index) { 
     30        z_index = c.get("z-index", default_z_index, Float.class); 
    3131        object_z_index = c.get("object-z-index", 0f, Float.class); 
    3232        isModifier = c.get("modifier", false, Boolean.class); 
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java

    r3994 r4005  
    3636 
    3737    protected LineElemStyle(Cascade c, BasicStroke line, Color color, BasicStroke dashesLine, Color dashesBackground, TextElement text, float realWidth) { 
    38         super(c); 
     38        super(c, 0f); 
    3939        this.line = line; 
    4040        this.color = color; 
  • trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java

    r4003 r4005  
    141141 
    142142    protected NodeElemStyle(Cascade c, ImageIcon icon, Integer iconAlpha, Symbol symbol, NodeTextElement text) { 
    143         super(c); 
     143        super(c, 1000f); 
    144144        this.icon = icon; 
    145145        this.iconAlpha = iconAlpha == null ? 0 : iconAlpha; 
Note: See TracChangeset for help on using the changeset viewer.