Changeset 3889 in josm


Ignore:
Timestamp:
Feb 11, 2011 11:00:56 PM (2 years ago)
Author:
bastiK
Message:

fixed #5673 - "oneway" arrows on ways should be painted in different style than way-direction arrows

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

Legend:

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

    r3888 r3889  
    4444import org.openstreetmap.josm.tools.ImageProvider; 
    4545import org.openstreetmap.josm.tools.LanguageInfo; 
     46import org.openstreetmap.josm.tools.Pair; 
    4647 
    4748public class MapPainter { 
     
    104105    } 
    105106 
    106     public void drawWay(Way way, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor, TextElement text, boolean showDirection, 
    107             boolean reversedDirection, boolean showHeadArrowOnly) { 
     107    /** 
     108     * draw way 
     109     * @param showOrientation show arrows that indicate the technical orientation of 
     110     *              the way (defined by order of nodes) 
     111     * @param showOneway show symbols that indicate the direction of the feature, 
     112     *              e.g. oneway street or waterway 
     113     * @param onewayReversed for oneway=-1 and similar 
     114     */ 
     115    public void drawWay(Way way, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor,  
     116            TextElement text, boolean showOrientation, boolean showHeadArrowOnly, 
     117            boolean showOneway, boolean onewayReversed) { 
    108118 
    109119        GeneralPath path = new GeneralPath(); 
    110         GeneralPath arrows = new GeneralPath(); 
     120        GeneralPath orientationArrows = showOrientation ? new GeneralPath() : null; 
     121        GeneralPath onewayArrows = showOneway ? new GeneralPath() : null; 
     122        GeneralPath onewayArrowsCasing = showOneway ? new GeneralPath() : null; 
    111123        Rectangle bounds = g.getClipBounds(); 
    112124        bounds.grow(100, 100);                  // avoid arrow heads at the border 
    113125 
     126        double wayLength = 0; 
    114127        Point lastPoint = null; 
    115128        boolean initialMoveToNeeded = true; 
     
    140153 
    141154                    /* draw arrow */ 
    142                     if (showHeadArrowOnly ? !it.hasNext() : showDirection) { 
    143                         if (reversedDirection) { 
    144                             Point tmp = p1; 
    145                             p1 = p2; 
    146                             p2 = tmp; 
    147                         } 
    148                         final double l =  10. / p1.distance(p2); 
     155                    if (showHeadArrowOnly ? !it.hasNext() : showOrientation) { 
     156                        final double l =  (10. + line.getLineWidth()) / p1.distance(p2); 
    149157 
    150158                        final double sx = l * (p1.x - p2.x); 
    151159                        final double sy = l * (p1.y - p2.y); 
    152160 
    153                         arrows.moveTo(p2.x, p2.y); 
    154                         arrows.lineTo (p2.x + (int) Math.round(cosPHI * sx - sinPHI * sy), p2.y + (int) Math.round(sinPHI * sx + cosPHI * sy)); 
    155                         arrows.moveTo (p2.x + (int) Math.round(cosPHI * sx + sinPHI * sy), p2.y + (int) Math.round(- sinPHI * sx + cosPHI * sy)); 
    156                         arrows.lineTo(p2.x, p2.y); 
     161                        orientationArrows.moveTo(p2.x, p2.y); 
     162                        orientationArrows.lineTo (p2.x + cosPHI * sx - sinPHI * sy, p2.y + sinPHI * sx + cosPHI * sy); 
     163                        orientationArrows.moveTo (p2.x + cosPHI * sx + sinPHI * sy, p2.y - sinPHI * sx + cosPHI * sy); 
     164                        orientationArrows.lineTo(p2.x, p2.y); 
     165                    } 
     166                    if (showOneway) { 
     167                        final double segmentLength = p1.distance(p2); 
     168                        final double nx = (p2.x - p1.x) / segmentLength; 
     169                        final double ny = (p2.y - p1.y) / segmentLength; 
     170 
     171                        final double interval = 60; 
     172                        // distance from p1 
     173                        double dist = interval - (wayLength % interval); 
     174 
     175                        while (dist < segmentLength) { 
     176                            for (Pair<Float, GeneralPath> sizeAndPath : Arrays.asList(new Pair[] { 
     177                                    new Pair<Float, GeneralPath>(3f, onewayArrowsCasing), 
     178                                    new Pair<Float, GeneralPath>(2f, onewayArrows)})) { 
     179 
     180                                // scale such that border is 1 px 
     181                                final double fac = - (onewayReversed ? -1 : 1) * sizeAndPath.a * (1 + sinPHI) / (sinPHI * cosPHI); 
     182                                final double sx = nx * fac; 
     183                                final double sy = ny * fac; 
     184 
     185                                // Attach the triangle at the incenter and not at the tip. 
     186                                // Makes the border even at all sides. 
     187                                final double x = p1.x + nx * (dist + (onewayReversed ? -1 : 1) * (sizeAndPath.a / sinPHI)); 
     188                                final double y = p1.y + ny * (dist + (onewayReversed ? -1 : 1) * (sizeAndPath.a / sinPHI)); 
     189 
     190                                sizeAndPath.b.moveTo(x, y); 
     191                                sizeAndPath.b.lineTo (x + cosPHI * sx - sinPHI * sy, y + sinPHI * sx + cosPHI * sy); 
     192                                sizeAndPath.b.lineTo (x + cosPHI * sx + sinPHI * sy, y - sinPHI * sx + cosPHI * sy); 
     193                                sizeAndPath.b.lineTo(x, y); 
     194                            } 
     195                            dist += interval; 
     196                        } 
     197                        wayLength += segmentLength; 
    157198                    } 
    158199                } 
     
    160201            lastPoint = p; 
    161202        } 
    162         displaySegments(path, arrows, color, line, dashes, dashedColor); 
     203        displaySegments(path, orientationArrows, onewayArrows, onewayArrowsCasing, color, line, dashes, dashedColor); 
    163204        drawTextOnPath(way, text); 
    164205    } 
    165206 
    166     private void displaySegments(GeneralPath path, GeneralPath arrows, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor) { 
     207    private void displaySegments(GeneralPath path, GeneralPath orientationArrows, GeneralPath onewayArrows, GeneralPath onewayArrowsCasing, 
     208            Color color, BasicStroke line, BasicStroke dashes, Color dashedColor) { 
    167209        g.setColor(inactive ? inactiveColor : color); 
    168210        if (useStrokes) { 
     
    170212        } 
    171213        g.draw(path); 
    172         g.draw(arrows); 
    173214 
    174215        if(!inactive && useStrokes && dashes != null) { 
     
    176217            g.setStroke(dashes); 
    177218            g.draw(path); 
    178             g.draw(arrows); 
     219        } 
     220 
     221        if (orientationArrows != null) { 
     222            g.setColor(inactive ? inactiveColor : color); 
     223            g.setStroke(new BasicStroke(line.getLineWidth(), line.getEndCap(), BasicStroke.JOIN_MITER, line.getMiterLimit())); 
     224            g.draw(orientationArrows); 
     225        } 
     226 
     227        if (onewayArrows != null) { 
     228            g.setStroke(new BasicStroke(1, line.getEndCap(), BasicStroke.JOIN_MITER, line.getMiterLimit())); 
     229            g.fill(onewayArrowsCasing); 
     230            g.setColor(inactive ? inactiveColor : backgroundColor); 
     231            g.fill(onewayArrows); 
    179232        } 
    180233 
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java

    r3888 r3889  
    193193        the way is tagged with a direction key 
    194194        (even if the tag is negated as in oneway=false) or the way is selected */ 
    195         boolean showDirection = !isModifier && (selected || ((!paintSettings.isUseRealWidth()) && (paintSettings.isShowDirectionArrow() 
    196                 && (!paintSettings.isShowRelevantDirectionsOnly() || w.hasDirectionKeys())))); 
    197         boolean reversedDirection = w.reversedDirection(); 
     195        boolean showOrientation = !isModifier && selected && !paintSettings.isUseRealWidth(); 
     196        boolean showOneway = !isModifier && !selected && 
     197                !paintSettings.isUseRealWidth() && 
     198                paintSettings.isShowDirectionArrow() && w.hasDirectionKeys(); 
     199        boolean onewayReversed = w.reversedDirection(); 
    198200        /* head only takes over control if the option is true, 
    199201        the direction should be shown at all and not only because it's selected */ 
    200         boolean showOnlyHeadArrowOnly = showDirection && !selected && paintSettings.isShowHeadArrowOnly(); 
     202        boolean showOnlyHeadArrowOnly = showOrientation && !selected && paintSettings.isShowHeadArrowOnly(); 
    201203        Node lastN; 
    202204 
    203205        Color myDashedColor = dashesBackground; 
    204206        BasicStroke myLine = line, myDashLine = dashesLine; 
    205         if (realWidth > 0 && paintSettings.isUseRealWidth() && !showDirection) { 
     207        if (realWidth > 0 && paintSettings.isUseRealWidth() && !showOrientation) { 
    206208            float myWidth = (int) (100 /  (float) (painter.getCircum() / realWidth)); 
    207209            if (myWidth < line.getLineWidth()) { 
     
    216218        } 
    217219 
    218         Color markColor = null; 
     220        Color myColor = color; 
    219221        if(w.isHighlighted()) { 
    220             markColor = paintSettings.getHighlightColor(); 
     222            myColor = paintSettings.getHighlightColor(); 
    221223        } else if (selected) { 
    222             markColor = paintSettings.getSelectedColor(color.getAlpha()); 
     224            myColor = paintSettings.getSelectedColor(color.getAlpha()); 
    223225        } else if (member) { 
    224             markColor = paintSettings.getRelationSelectedColor(color.getAlpha()); 
     226            myColor = paintSettings.getRelationSelectedColor(color.getAlpha()); 
    225227        } else if(w.isDisabled()) { 
    226             markColor = paintSettings.getInactiveColor(); 
     228            myColor = paintSettings.getInactiveColor(); 
    227229            myDashedColor = paintSettings.getInactiveColor(); 
    228230        } 
    229231 
    230         painter.drawWay(w, markColor != null ? markColor : color, myLine, myDashLine, myDashedColor, text, showDirection, 
    231                 selected ? false : reversedDirection, showOnlyHeadArrowOnly); 
     232        painter.drawWay(w, myColor, myLine, myDashLine, myDashedColor, text, showOrientation, 
     233                showOnlyHeadArrowOnly, showOneway, onewayReversed); 
    232234 
    233235        if(paintSettings.isShowOrderNumber()) { 
Note: See TracChangeset for help on using the changeset viewer.